@Test @Ignore("NXP-20582: timeout waiting termination") public void testConcurrency() throws Exception { final String seqName = "mt"; int nbCalls = 5000; final UIDSequencer seq = uidGeneratorService.getSequencer(); ThreadPoolExecutor tpe = new ThreadPoolExecutor( 5, 5, 500L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(nbCalls + 1)); for (int i = 0; i < nbCalls; i++) { tpe.submit( new Runnable() { @Override public void run() { seq.getNext(seqName); } }); } tpe.shutdown(); boolean finish = tpe.awaitTermination(20, TimeUnit.SECONDS); assertTrue("timeout", finish); assertEquals(nbCalls + 1, seq.getNext(seqName)); }
@Test public void testInitSequence() { UIDSequencer seq = uidGeneratorService.getSequencer(); seq.getNext("mySequence"); seq.getNext("mySequence"); seq.initSequence("mySequence", 1); assertTrue(seq.getNext("mySequence") > 1); seq.initSequence("mySequence", 10); assertTrue(seq.getNext("mySequence") > 10); assertTrue(seq.getNextLong("mySequence") > 10); }
@Test public void testIncrement() throws Exception { UIDSequencer seq = uidGeneratorService.getSequencer(); assertNotNull(seq); assertTrue(seq.getClass().isAssignableFrom(ESUIDSequencer.class)); assertEquals(1, seq.getNext("myseq")); assertEquals(2, seq.getNext("myseq")); assertEquals(3L, seq.getNextLong("myseq")); assertEquals(1, seq.getNext("myseq2")); assertEquals(4, seq.getNext("myseq")); assertEquals(2, seq.getNext("myseq2")); }