TransactionProxy extends AbstractDOMStoreTransaction<TransactionIdentifier> implements DOMStoreReadWriteTransaction { @Override public FluentFuture<Boolean> exists(final YangInstanceIdentifier path) { return executeRead(shardNameFromIdentifier(path), new DataExists(path, DataStoreVersions.CURRENT_VERSION)); } @VisibleForTesting  TransactionProxy(final AbstractTransactionContextFactory<?> txContextFactory, final TransactionType type); @Override FluentFuture<Boolean> exists(final YangInstanceIdentifier path); @Override FluentFuture<Optional<NormalizedNode<?, ?>>> read(final YangInstanceIdentifier path); @Override void delete(final YangInstanceIdentifier path); @Override void merge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data); @Override void write(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data); @Override final void close(); @Override final AbstractThreePhaseCommitCohort<?> ready();  }
@Test public void testExists() throws Exception { ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY); TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY); doReturn(dataExistsReply(false)).when(mockActorContext).executeOperationAsync( eq(actorSelection(actorRef)), eqDataExists(), any(Timeout.class)); Boolean exists = transactionProxy.exists(TestModel.TEST_PATH).get(); assertEquals("Exists response", Boolean.FALSE, exists); doReturn(dataExistsReply(true)).when(mockActorContext).executeOperationAsync( eq(actorSelection(actorRef)), eqDataExists(), any(Timeout.class)); exists = transactionProxy.exists(TestModel.TEST_PATH).get(); assertEquals("Exists response", Boolean.TRUE, exists); }
@Test(expected = PrimaryNotFoundException.class) public void testExistsWhenAPrimaryNotFoundExceptionIsThrown() throws Throwable { testExceptionOnInitialCreateTransaction(new PrimaryNotFoundException("test"), proxy -> proxy.exists(TestModel.TEST_PATH)); }
@Test(expected = ReadFailedException.class) public void testExistsWithInvalidReplyMessageType() throws Throwable { ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY); doReturn(Futures.successful(new Object())).when(mockActorContext) .executeOperationAsync(eq(actorSelection(actorRef)), eqDataExists(), any(Timeout.class)); TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY); try { transactionProxy.exists(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS); } catch (ExecutionException e) { throw e.getCause(); } }
@Test(expected = TestException.class) public void testExistsWithAsyncRemoteOperatonFailure() throws Throwable { ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_ONLY); doReturn(Futures.failed(new TestException())).when(mockActorContext) .executeOperationAsync(eq(actorSelection(actorRef)), eqDataExists(), any(Timeout.class)); TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY); propagateReadFailedExceptionCause(transactionProxy.exists(TestModel.TEST_PATH)); }
@Test(expected = IllegalStateException.class) public void testExistsPreConditionCheck() { TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY); transactionProxy.exists(TestModel.TEST_PATH); }
@Test public void testExistsThrottlingWhenShardFound() { throttleOperation(transactionProxy -> { doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync( any(ActorSelection.class), eqDataExists()); transactionProxy.exists(TestModel.TEST_PATH); transactionProxy.exists(TestModel.TEST_PATH); }); }
@Test public void testExistsThrottlingWhenShardNotFound() { completeOperation(transactionProxy -> { doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync( any(ActorSelection.class), eqDataExists()); transactionProxy.exists(TestModel.TEST_PATH); transactionProxy.exists(TestModel.TEST_PATH); }, false); }
@Test public void testExistsCompletion() { completeOperation(transactionProxy -> { doReturn(dataExistsReply(true)).when(mockActorContext).executeOperationAsync( any(ActorSelection.class), eqDataExists(), any(Timeout.class)); transactionProxy.exists(TestModel.TEST_PATH); transactionProxy.exists(TestModel.TEST_PATH); }); }
@Test public void testExistsCompletionForLocalShard() { final NormalizedNode<?, ?> nodeToRead = ImmutableNodes.containerNode(TestModel.TEST_QNAME); completeOperationLocal(transactionProxy -> { transactionProxy.exists(TestModel.TEST_PATH); transactionProxy.exists(TestModel.TEST_PATH); }, createDataTree(nodeToRead)); }
@Test public void testExistsCompletionForLocalShardWhenExceptionOccurs() { completeOperationLocal(transactionProxy -> { transactionProxy.exists(TestModel.TEST_PATH); transactionProxy.exists(TestModel.TEST_PATH); }, createDataTree()); }