DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

The Latest Integration Topics

article thumbnail
Five Ways of Synchronising Multithreaded Integration Tests
A few weeks ago I wrote a blog on synchronizing multithreaded integration tests, which was republished on DZone Javalobby from where it received a comment from Robert Saulnier who quite rightly pointed out that you can also use join() to synchronize a worker thread and its unit tests. This got me thinking, just how many ways can you synchronise multi-threaded integration tests? So, I started counting... and came up with: Using a random delay. Adding a CountDownLatch Thread.join() Acquiring a Semaphore With a Future and ExecutorService Now, I’m not going to explain all the following in great detail, I’ll let the code speak for itself, except to say that all the code samples do roughly the same thing: the unit test creates a ThreadWrapper instance and then calls its doWork() method (or call() in the case of the Future). The unit test’s main thread then waits for the worker thread to complete before asserting that the test has passed. For the sample code demonstrating points 1 and 2 take a look at my original blog on Synchronizing Multithreaded Integration Tests, though I wouldn’t recommend point 1: using a random delay. Thread.join() public class ThreadWrapper { private Thread thread; /** * Start the thread running so that it does some work. */ public void doWork() { thread = new Thread() { /** * Run method adding data to a fictitious database */ @Override public void run() { System.out.println("Start of the thread"); addDataToDB(); System.out.println("End of the thread method"); } private void addDataToDB() { try { Thread.sleep(4000); } catch (InterruptedException e) { e.printStackTrace(); } } }; thread.start(); System.out.println("Off and running..."); } /** * Synchronization method. */ public void join() { try { thread.join(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } } public class ThreadWrapperTest { @Test public void testDoWork() throws InterruptedException { ThreadWrapper instance = new ThreadWrapper(); instance.doWork(); instance.join(); boolean result = getResultFromDatabase(); assertTrue(result); } /** * Dummy database method - just return true */ private boolean getResultFromDatabase() { return true; } } Acquiring a Semaphore public class ThreadWrapper { /** * Start the thread running so that it does some work. */ public void doWork() { doWork(null); } @VisibleForTesting void doWork(final Semaphore semaphore) { Thread thread = new Thread() { /** * Run method adding data to a fictitious database */ @Override public void run() { System.out.println("Start of the thread"); addDataToDB(); System.out.println("End of the thread method"); semaphore.release(); } private void addDataToDB() { try { Thread.sleep(4000); } catch (InterruptedException e) { e.printStackTrace(); } } }; aquire(semaphore); thread.start(); System.out.println("Off and running..."); } private void aquire(Semaphore semaphore) { try { semaphore.acquire(); } catch (InterruptedException e) { e.printStackTrace(); } } } public class ThreadWrapperTest { @Test public void testDoWork() throws InterruptedException { ThreadWrapper instance = new ThreadWrapper(); Semaphore semaphore = new Semaphore(1); instance.doWork(semaphore); semaphore.acquire(); boolean result = getResultFromDatabase(); assertTrue(result); } /** * Dummy database method - just return true */ private boolean getResultFromDatabase() { return true; } } With a Future public class ThreadWrapper implements Callable { @Override public Boolean call() throws Exception { System.out.println("Start of the thread"); Boolean added = addDataToDB(); System.out.println("End of the thread method"); return added; } /** * Add to the DB and return true if added okay */ private Boolean addDataToDB() { try { Thread.sleep(4000); } catch (InterruptedException e) { e.printStackTrace(); } return Boolean.valueOf(true); } } public class ThreadWrapperTest { @Test public void testCall() throws ExecutionException, InterruptedException { ThreadWrapper instance = new ThreadWrapper(); ExecutorService executorService = Executors.newFixedThreadPool(1); Future future = executorService.submit(instance); Boolean result = future.get(); assertTrue(result); } } Having listed all these methods, the next thing to consider is which one is the best? In asking that question you have to define the word “best” in terms of best for what? Best for simplicity? Maintainability? Speed or code size? After all Programming the Art of Making the Right Decision. You may have guessed that I don’t like the random delay idea and prefer the use of a CountDownLatch. Thread.join() is a bit old school; remember that the likes of Semaphore and CountDownLatch were written to improve on the original Java threading techniques. ExecutorService seems a little heavy weight for what we need here. At the end of the day the choice of technique really comes down to personal preference. Finally, I’ve listed five ways of synchronizing multi-threaded integration tests; however, if you can think of any others please let me know... The source code for this blog is available on Github.
October 11, 2022
by Roger Hughes
· 9,649 Views · 1 Like
article thumbnail
Transit Gateway With Anypoint Platform
Here we will use the Mulesoft Anypoint platform to attach VPC to the AWS transit gateway to form a single network topology.
October 10, 2022
by Gaurav Dhimate
· 5,318 Views · 2 Likes
article thumbnail
AWS Step Function for Modernization of Integration Involving High-Volume Transaction: A Case Study
The serverless offerings of AWS are getting more and more popular. But it remains a challenge to know them well enough to leverage them properly.
October 9, 2022
by Satyaki Sensarma
· 4,510 Views · 3 Likes
article thumbnail
Message Routing and Topics: A Thought Shift
This article makes some observations on the advancements in real-time, event-driven messaging with hierarchical topics from the MoM perspective.
October 9, 2022
by Giri Venkatesan
· 4,527 Views · 5 Likes
article thumbnail
Decorating Microservices
The Decorator pattern is a great fit for modifying the behaviour of a microservice. Native language support can help with applying it quickly and modularly.
October 7, 2022
by Fabrizio Montesi
· 10,599 Views · 4 Likes
article thumbnail
Upload Single and Multiple Files Using the .NET Core 6 Web API
We will discuss file uploads with the help of the IFormFile Interface and others provided by .NET and step-by-step implementation using .NET Core 6 Web API.
October 7, 2022
by Jaydeep Patil
· 12,790 Views · 2 Likes
article thumbnail
Configure Cucumber Setup in Eclipse and IntelliJ [Tutorial]
Here's how to start using Cucumber, the widely used BDD framework for Selenium automation testing. This article helps you get set up in Eclipse and IntelliJ IDEA. It also provides a step-by-step guide on setting up Maven Cucumber project in Eclipse.
October 7, 2022
by Harshit Paul
· 9,624 Views · 1 Like
article thumbnail
Databricks vs Snowflake: The Definitive Guide
Discover the key differences between Databricks and Snowflake around architecture, pricing, security, compliance, data support, data protection, performance, and more.
Updated October 6, 2022
by Luke Kline
· 15,111 Views · 12 Likes
article thumbnail
2-Tier Architecture vs 3-Tier Architecture in DBMS
This article talks about the architecture of DBMS (Database Management Systems), with their structure, advantages, features, and more.
Updated October 6, 2022
by Bikash Jain
· 10,945 Views · 3 Likes
article thumbnail
Mule Snowflake Operations With Snowflake Configuration
This tutorial covers a few operations in the Mule Snowflake Connector along with the Snowflake configuration for those operations.
October 5, 2022
by Sajal Biswas
· 6,336 Views · 1 Like
article thumbnail
AWS Cognito Overview and Step-By-Step Integration
Explore the difference between two well-known Auth building methods: AWS Cognito and JSON Web Token. Plus, take a look at the AWS Cognito application process.
October 4, 2022
by Tetiana Stoyko
· 5,011 Views · 1 Like
article thumbnail
The Art of Deploying a Service Mesh
Check out the benefits of deploying a service mesh, popular tools for deploying a Service Mesh, and more here in this article.
October 4, 2022
by Ruchita Varma
· 7,139 Views · 1 Like
article thumbnail
How To Validate Names Using Java
Gain context of three separate API solutions which can be used to validate name input fields within an application as you follow along with this demonstration.
October 3, 2022
by Brian O'Neill DZone Core CORE
· 9,162 Views · 4 Likes
article thumbnail
EDI Integration Platforms: Benefits and Limitations
Find out how companies can leverage EDI integration solutions to drive their business forward. Also, explore the potential limitations posed by EDI.
September 30, 2022
by Chandra Shekhar
· 6,995 Views · 2 Likes
article thumbnail
Asynchronous API Calls: Spring Boot, Feign, and Spring @Async
Learn how to make asynchronous API calls from Spring Boot using Spring Cloud OpenFeign and Spring @Async to reduce the response time to that of a one-page call.
Updated September 28, 2022
by Mukut Bhattacharjee
· 33,111 Views · 6 Likes
article thumbnail
Build Your Own Social Media Analytics with Apache Kafka
Stream messages between API endpoints using Kafka running on Kubernetes.
September 28, 2022
by Sylvain Kalache
· 5,353 Views · 1 Like
article thumbnail
Google Cloud - For AWS Professionals
Learning a cloud platform takes a long time. If you are familiar with AWS, this is the overview you need to get started quickly to understand Google Cloud.
September 27, 2022
by Ranga Karanam
· 5,585 Views · 1 Like
article thumbnail
Bypassing Spring Interceptors via Decoration
This article documents a simple yet very useful way of bypassing some of the configured HandlerInterceptors depending on the request's mapping.
September 27, 2022
by Horatiu Dan DZone Core CORE
· 5,372 Views · 5 Likes
article thumbnail
Starting an API-First Company
What it takes to start an API-first company, from developing product vision to securing your first round of funding.
September 26, 2022
by Derric Gilling DZone Core CORE
· 6,662 Views · 2 Likes
article thumbnail
Allow Users to Track Fitness Status in Your App
Endow your app with the ability to manage fitness status and obtain real-time fitness data.
September 26, 2022
by Jackson Jiang
· 3,377 Views · 1 Like
  • Previous
  • ...
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • ...
  • Next
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook
×