Skip to content

Instantly share code, notes, and snippets.

@gurbuzali
Created December 2, 2013 22:12
Show Gist options
  • Save gurbuzali/7760031 to your computer and use it in GitHub Desktop.
Save gurbuzali/7760031 to your computer and use it in GitHub Desktop.
@Test
public void testIssue1309() throws InterruptedException {
final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance();
final CountDownLatch latch = new CountDownLatch(1);
new Thread(){
public void run() {
final IQueue<Integer> q = instance1.getQueue("q");
for (int i=1; i<=100; i++){
q.offer(i);
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
latch.countDown();
}
}.start();
Thread.sleep(100);
for (int i=0; i<5; i++) {
final CountDownLatch innerLatch = new CountDownLatch(1);
new Thread() {
public void run() {
final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance();
final TransactionContext context = instance2.newTransactionContext();
context.beginTransaction();
final TransactionalQueue<Integer> q = context.getQueue("q");
final int poll1 = q.poll();
final int poll2 = q.poll();
final int poll3 = q.poll();
System.err.println("asdf p1: " + poll1 + ", p2: " + poll2 + ", p3: " + poll3);
instance2.getLifecycleService().shutdown();
innerLatch.countDown();
}
}.start();
innerLatch.await();
}
latch.await();
final IQueue<Integer> q = instance1.getQueue("q");
assertEquals(100, q.size());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment