+ try (DistributedDataStore distributedDataStore = new DistributedDataStore(actorContext, UNKNOWN_ID)) {
+
+ distributedDataStore.newReadOnlyTransaction();
+ distributedDataStore.newReadOnlyTransaction();
+ distributedDataStore.newReadOnlyTransaction();
+
+ verify(actorContext, times(0)).acquireTxCreationPermit();
+ }
+ }
+
+ @Test
+ public void testWaitTillReadyBlocking(){
+ doReturn(datastoreContext).when(actorContext).getDatastoreContext();
+ doReturn(shardElectionTimeout).when(datastoreContext).getShardLeaderElectionTimeout();
+ doReturn(FiniteDuration.apply(50, TimeUnit.MILLISECONDS)).when(shardElectionTimeout).duration();
+ try (DistributedDataStore distributedDataStore = new DistributedDataStore(actorContext, UNKNOWN_ID)) {
+
+ long start = System.currentTimeMillis();
+
+ distributedDataStore.waitTillReady();
+
+ long end = System.currentTimeMillis();
+
+ assertTrue("Expected to be blocked for 50 millis", (end - start) >= 50);
+ }
+ }
+
+ @Test
+ public void testWaitTillReadyCountDown(){
+ try (final DistributedDataStore distributedDataStore = new DistributedDataStore(actorContext, UNKNOWN_ID)) {
+ doReturn(datastoreContext).when(actorContext).getDatastoreContext();
+ doReturn(shardElectionTimeout).when(datastoreContext).getShardLeaderElectionTimeout();
+ doReturn(FiniteDuration.apply(5000, TimeUnit.MILLISECONDS)).when(shardElectionTimeout).duration();
+
+ Executors.newSingleThreadExecutor().submit(() -> {
+ Uninterruptibles.sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
+ distributedDataStore.getWaitTillReadyCountDownLatch().countDown();
+ });
+
+ long start = System.currentTimeMillis();
+
+ distributedDataStore.waitTillReady();