Skip to main content

JUnit 5 @RepeatedTest: Improve Test Reliability with Repeated Test Execution

In the competitive landscape of Java development, flakiness is the ultimate enemy of progress. We have all experienced the "Heisenbug" frustration: you write a test, it passes flawlessly on your local machine, but it fails intermittently once it hits the CI/CD pipeline. These non-deterministic failures erode trust in the build process and waste hours of engineering time. To combat this instability, JUnit 5 introduced a robust solution: the @RepeatedTest annotation. Whether you are hunting down elusive race conditions, validating random data generators, or stress-testing intermittent network calls, repeating a test is a proven strategy for ensuring long-term stability. Today, we’ll dive deep into how to use @RepeatedTest to transform your test suite from "mostly reliable" to "battle-hardened." What is JUnit 5 @RepeatedTest? The @RepeatedTest annotation is a specialized programming model in JUnit Jupiter that allows you to execute a single test method a specific number of times. Unlike a standard @Test annotation, which executes a method exactly once, @RepeatedTest signals the JUnit Jupiter engine to treat the method as a template. The engine then generates multiple dynamic test invocations based on that template.

8086 Assembly Program to Compute the Power of a Number

This blog post details an 8086-assembly program that computes the power of a number, specifically baseexponent. This example demonstrates fundamental assembly concepts like loops, multiplication, and register manipulation to perform iterative arithmetic. Let’s get started! data segment base dw 0003h exponent dw 0004h result dd ? data ends code segment assume cs:code, ds:data start: ; Initialize data segment mov ax, data mov ds, ax ; Initialize result to 1 (R = B^0) mov word ptr result, 0001h mov word ptr result+2, 0000h ; Load base and exponent mov cx, exponent ; CX = exponent (loop counter) mov bx, base ; BX = base cmp cx, 0000h je exit ; If exponent is 0, result is already 1. Jump to exit. power_loop: ; Multiply result by base ; The result is a 32-bit number in result[0] (lower word) and result[2] (upper word) ; Multiplication requires careful handling of the 32-bit result with a 16-bit multiplier. ; 1. Multiply the lower word of result by base mov ax, word ptr result ; AX = result[0] mul bx ; AX * BX -> DX:AX (32-bit product) push dx ; Save the higher word (DX) of the product mov word ptr result, ax ; Store the lower word (AX) of the product as the new result[0] ; 2. Multiply the upper word of result by base mov ax, word ptr result+2 ; AX = result[2] mul bx ; AX * BX -> DX:AX (32-bit product) ; 3. Add the two 16-bit 'carry' terms pop cx ; Retrieve the saved higher word (DX) from step 1 into CX add ax, cx ; AX = AX + CX (Sum of two high words) adc dx, 0000h ; DX = DX + 0 + Carry from the previous ADD (final carry from the 32-bit multiplication) ; 4. Store the final upper word mov word ptr result+2, ax ; Store AX as the new result[2] ; Handle the 32-bit overflow (DX is the final carry from the 32-bit multiplication) ; For a 32-bit result storage, this program assumes the result fits in 32-bits. ; If the power is large, overflow might occur, which is a limitation of this 32-bit storage approach. loop power_loop ; Decrement CX and jump back to power_loop if CX != 0 exit: int 3 ; Program termination code ends end start

TypeScript Arithmetic Operators: The Definitive Guide

TypeScript didn’t reinvent JavaScript’s arithmetic — it just gave you a seatbelt. Under the hood, every +, -, *, /, and ** behaves exactly like in JavaScript, including all the quirky coercion rules that have launched a thousand memes. What TypeScript adds is the ability to catch those bugs at compile time instead of 3 a.m. when a user enters “banana” in a price field. This guide covers every arithmetic operator in TypeScript with modern, real-world examples, in-depth explanations, common pitfalls, performance notes, and a cheat-sheet you’ll actually use. 1. Unary Operators Unary Plus + Purpose: Explicitly converts its operand to a number using the same algorithm as Number() but much faster. +"42"; // 42 +"3.14"; // 3.14 +""; // 0 (empty string → 0) +" 123 "; // 123 (trims whitespace!) +"0xFF"; // 255 (recognizes hex) +"abc"; // NaN +true; // 1 +false; // 0 +null; // 0 +undefined; // NaN (compile error if strictNullChecks is on)

Java HashMap vs ConcurrentHashMap: Complete Interview Guide

In Java collections framework, HashMap and ConcurrentHashMap are two of the most frequently discussed topics in technical interviews. While HashMap provides fast key-value storage for single-threaded environments, ConcurrentHashMap extends these capabilities to support concurrent access. This comprehensive guide covers essential interview questions about both data structures, their internal workings, and key differences. HashMap Fundamentals What is HashMap? HashMap is a hash table based implementation of the Map interface in Java. It stores key-value pairs and provides constant-time performance for basic operations like get() and put() assuming the hash function disperses elements properly. HashMap is part of the Java Collections Framework and resides in java.util package. How HashMap Works Internally The internal architecture of HashMap consists of an array of buckets where each bucket is a linked list (or tree in Java 8+) of entries. When you store a key-value pair, HashMap calculates the hash of the key to determine the bucket location. In Java 8+, when a bucket contains too many entries (default threshold is 8), it converts the linked list into a balanced red-black tree for faster lookups.

Spring Security Context Propagation – Complete Guide

Spring Security’s SecurityContext is the cornerstone of authentication and authorization in Spring applications. It stores critical user details like authentication token, granted authorities, and principal information. However, when operations span multiple threads—common in asynchronous processing or reactive programming—propagating this context becomes a significant challenge. This guide explores various strategies to ensure your security context travels correctly across thread boundaries. Understanding SecurityContext and ThreadLocal At the heart of Spring Security lies the SecurityContextHolder, which uses a ThreadLocal strategy by default. This means each thread maintains its own isolated security context, which works perfectly in standard synchronous request-response cycles but breaks down when new threads are spawned. The SecurityContextHolder supports three persistence strategies: MODE_THREADLOCAL: Default strategy where context is bound to the current thread MODE_INHERITABLETHREADLOCAL: Context is inherited by child threads created by the current thread MODE_GLOBAL: Single context shared across all threads (rarely used in production)

8086 Assembly Program to Compute Factorial of an Integer Using Recursion

This blog post will dive into a more advanced concept in 8086 assembly: computing the factorial of a number using recursion. Unlike iterative approaches using loops, recursion involves a procedure calling itself. This example highlights crucial concepts of stack management (PUSH and POP), procedure calls (CALL and RET), and conditional jumping to handle base cases. Let’s explore how the stack handles the "memory" of recursive calls! ; Program to calculate Factorial of a number using Recursion ; Input: num (e.g., 5) ; Output: result (e.g., 5! = 120 or 78h) data segment num dw 0005h ; The number to calculate factorial for (16-bit word) result dw ? ; Variable to store the final 16-bit result data ends code segment assume cs:code, ds:data start: mov ax, data mov ds, ax ; Initialize Data Segment mov cx, num ; Load the input number into CX register used as counter/argument mov ax, 0001h ; Initialize accumulator AX to 1 (needed for multiplication) call factorial ; Call the recursive procedure mov result, ax ; Store final result from AX into memory variable int 3 ; Breakpoint to halt and check registers ;--- Recursive Procedure Definition --- factorial proc near cmp cx, 1 ; BASE CASE: Check if number in CX is <= 1 jbe base_case ; If CX is 0 or 1, jump to base_case to return push cx ; RECURSIVE STEP: Save current state of CX on STACK dec cx ; Decrement CX to move towards base case (N-1) call factorial ; Recursive Call: factorial(N-1) pop cx ; UNWINDING: Restore the saved value of CX from STACK mul cx ; AX = AX * CX. (Current Result * Current N) ret ; Return to caller base_case: mov ax, 1 ; Base case returns 1 (as 0! = 1 and 1! = 1) ret ; Return to caller factorial endp ;-------------------------------------- code ends end start

Master Custom Authentication Providers in Spring Security 6

Spring Security is the de facto standard for securing Java applications, offering robust support for OAuth2, LDAP, and standard form logins. But what happens when "standard" isn't enough? You might face a scenario where user credentials live in a legacy mainframe, a proprietary API, or a multi-tenant database with complex sharding rules. In these cases, the default DaoAuthenticationProvider fails. Trying to hack standard filters to fit these requirements leads to brittle code, security vulnerabilities, and maintenance nightmares. The solution lies in Spring Security’s modular architecture. By implementing a Custom Authentication Provider, you can inject your specific business logic directly into the security lifecycle without compromising the framework's integrity. In this guide, we will build a production-ready Custom Authentication Provider using Spring Boot 3 and Spring Security 6. We will cover the architecture, implementation details, configuration, and critical edge cases you must handle. Understanding the Architecture Before writing code, it is crucial to understand where your custom logic fits. Spring Security uses a delegation model. AuthenticationFilter: Intercepts the request. AuthenticationManager: The interface defining how authentication is processed. ProviderManager: The standard implementation that iterates through a list of providers. AuthenticationProvider: The component that actually validates the user.

How to Check if a Number is a Pronic Number in Java

Whether you are preparing for a technical interview or exploring the fascinating world of number theory, encountering Pronic numbers is almost a rite of passage for Java developers. These numbers, often hidden in pattern-matching puzzles, have unique properties that make them a favorite for practicing algorithmic efficiency. In this guide, we will dive deep into what Pronic numbers are and demonstrate two distinct ways to identify them using Java—ranging from a beginner-friendly loop to a high-performance mathematical "trick." What is a Pronic Number? A Pronic number (also known as an oblong or rectangular number) is a number that is the product of two consecutive integers. Mathematically, a number P is pronic if it can be expressed as: P = n X (n + 1) For some integer n. Examples of Pronic Numbers: 0: 0 X 1 = 0 2: 1 X 2 = 2 6: 2 X 3 = 6 12: 3 X 4 = 12 20: 4 X 5 = 20

Complete Guide to Enabling HTTPS on Apache Tomcat

When your web application moves beyond hobby status, the first hardening step is wrapping every byte in TLS. Tomcat makes the process painless once you understand where the moving parts live. In this guide you will create (or import) a certificate, wire it into Tomcat’s connector, and verify that the padlock appears in every browser. Why HTTPS on Tomcat Matters Plain HTTP exposes cookies, credentials, and payloads to anyone on the wire. Search engines penalize insecure sites, browsers now flag non-TLS pages as “Not Secure”, and compliance frameworks such as PCI-DSS simply forbid clear-text traffic. Turning on HTTPS: Encrypts data in transit Proves server identity to clients Unlocks HTTP/2 and modern protocols Keeps Google and your security team happy Prerequisites and Environment Before touching configuration files ensure: Tomcat 9.x or 10.x is installed and starts cleanly on port 8080 JAVA_HOME points to JDK 8+ (keytool comes with the JDK) OpenSSL 1.1+ if you prefer generating private keys externally Server DNS name (e.g. app.ankurm.com) resolves to the VM or container