Skip to content

Instantly share code, notes, and snippets.

@mikeycmccarthy
Created March 9, 2012 15:44
Show Gist options
  • Save mikeycmccarthy/2007156 to your computer and use it in GitHub Desktop.
Save mikeycmccarthy/2007156 to your computer and use it in GitHub Desktop.
Uniqueness test
@Test
public void testUniquenessInMultiThreadedScenario() throws Exception {
final Long firstMember = 100L;
final List<Exception> exceptionList = new ArrayList<Exception>();
ExecutorService exec = Executors.newFixedThreadPool(16);
for (int i = 101; i < 1000; i++) {
final Long buddyId = new Long(i);
exec.execute(new Runnable() {
@Override
public void run() {
try {
memberService.refer(firstMember, buddyId);
} catch (NoSuchElementException noSuchElementException) {
exceptionList.add(noSuchElementException);
}
}
}
);
}
exec.shutdown();
exec.awaitTermination(50, TimeUnit.SECONDS);
assertTrue("Exceptions found when creating nodes", exceptionList.isEmpty());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment