@After
public void tearDown() {
- if (executor != null ) {
+ if (executor != null) {
executor.shutdownNow();
}
@Test(expected = TransactionCommitFailedException.class)
public void testRejectedCommit() throws Exception {
- commitExecutor.delegate = Mockito.mock( ExecutorService.class );
- Mockito.doThrow( new RejectedExecutionException( "mock" ) )
- .when( commitExecutor.delegate ).execute( Mockito.any( Runnable.class ) );
- Mockito.doNothing().when( commitExecutor.delegate ).shutdown();
- Mockito.doReturn( Collections.emptyList() ).when( commitExecutor.delegate ).shutdownNow();
- Mockito.doReturn( "" ).when( commitExecutor.delegate ).toString();
- Mockito.doReturn( true ).when( commitExecutor.delegate )
- .awaitTermination( Mockito.anyLong(), Mockito.any( TimeUnit.class ) );
+ commitExecutor.delegate = Mockito.mock(ExecutorService.class);
+ Mockito.doThrow(new RejectedExecutionException("mock"))
+ .when(commitExecutor.delegate).execute(Mockito.any(Runnable.class));
+ Mockito.doNothing().when(commitExecutor.delegate).shutdown();
+ Mockito.doReturn(Collections.emptyList()).when(commitExecutor.delegate).shutdownNow();
+ Mockito.doReturn("").when(commitExecutor.delegate).toString();
+ Mockito.doReturn(true).when(commitExecutor.delegate)
+ .awaitTermination(Mockito.anyLong(), Mockito.any(TimeUnit.class));
final DOMDataTreeWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
- writeTx.put( OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME) );
+ writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- writeTx.submit().checkedGet( 5, TimeUnit.SECONDS );
+ writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
}
@SuppressWarnings("checkstyle:IllegalCatch")
- AtomicReference<Throwable> submitTxAsync( final DOMDataTreeWriteTransaction writeTx ) {
+ AtomicReference<Throwable> submitTxAsync(final DOMDataTreeWriteTransaction writeTx) {
final AtomicReference<Throwable> caughtEx = new AtomicReference<>();
new Thread() {
@Override
try {
writeTx.submit();
- } catch ( final Throwable e ) {
- caughtEx.set( e );
+ } catch (final Throwable e) {
+ caughtEx.set(e);
}
}
ExecutorService delegate;
- CommitExecutorService( final ExecutorService delegate ) {
+ CommitExecutorService(final ExecutorService delegate) {
this.delegate = delegate;
}
public void testDelete() throws Exception {
DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction();
- assertNotNull( writeTx );
+ assertNotNull(writeTx);
// Write /test and commit
- writeTx.write( TestModel.TEST_PATH, ImmutableNodes.containerNode( TestModel.TEST_QNAME ) );
+ writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- assertThreePhaseCommit( writeTx.ready() );
+ assertThreePhaseCommit(writeTx.ready());
Optional<NormalizedNode<?, ?>> afterCommitRead =
- domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH ).get();
- assertEquals( "After commit read: isPresent", true, afterCommitRead.isPresent() );
+ domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
+ assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent());
// Delete /test and verify
writeTx = domStore.newWriteOnlyTransaction();
- writeTx.delete( TestModel.TEST_PATH );
+ writeTx.delete(TestModel.TEST_PATH);
- assertThreePhaseCommit( writeTx.ready() );
+ assertThreePhaseCommit(writeTx.ready());
- afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH ).get();
- assertEquals( "After commit read: isPresent", false, afterCommitRead.isPresent() );
+ afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
+ assertEquals("After commit read: isPresent", false, afterCommitRead.isPresent());
}
@Test
public void testMerge() throws Exception {
DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction();
- assertNotNull( writeTx );
+ assertNotNull(writeTx);
ContainerNode containerNode = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier( new NodeIdentifier( TestModel.TEST_QNAME ) )
- .addChild( ImmutableNodes.mapNodeBuilder( TestModel.OUTER_LIST_QNAME )
- .addChild( ImmutableNodes.mapEntry( TestModel.OUTER_LIST_QNAME,
- TestModel.ID_QNAME, 1 ) ).build() ).build();
+ .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
+ .addChild(ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
+ .addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME,
+ TestModel.ID_QNAME, 1)).build()).build();
- writeTx.merge( TestModel.TEST_PATH, containerNode );
+ writeTx.merge(TestModel.TEST_PATH, containerNode);
- assertThreePhaseCommit( writeTx.ready() );
+ assertThreePhaseCommit(writeTx.ready());
Optional<NormalizedNode<?, ?>> afterCommitRead =
- domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH ).get();
- assertEquals( "After commit read: isPresent", true, afterCommitRead.isPresent() );
- assertEquals( "After commit read: data", containerNode, afterCommitRead.get() );
+ domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
+ assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent());
+ assertEquals("After commit read: data", containerNode, afterCommitRead.get());
// Merge a new list entry node
writeTx = domStore.newWriteOnlyTransaction();
- assertNotNull( writeTx );
+ assertNotNull(writeTx);
containerNode = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier( new NodeIdentifier( TestModel.TEST_QNAME ) )
- .addChild( ImmutableNodes.mapNodeBuilder( TestModel.OUTER_LIST_QNAME )
- .addChild( ImmutableNodes.mapEntry( TestModel.OUTER_LIST_QNAME,
- TestModel.ID_QNAME, 1 ) )
- .addChild( ImmutableNodes.mapEntry( TestModel.OUTER_LIST_QNAME,
- TestModel.ID_QNAME, 2 ) ).build() ).build();
+ .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
+ .addChild(ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
+ .addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME,
+ TestModel.ID_QNAME, 1))
+ .addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME,
+ TestModel.ID_QNAME, 2)).build()).build();
- writeTx.merge( TestModel.TEST_PATH, containerNode );
+ writeTx.merge(TestModel.TEST_PATH, containerNode);
- assertThreePhaseCommit( writeTx.ready() );
+ assertThreePhaseCommit(writeTx.ready());
- afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH ).get();
- assertEquals( "After commit read: isPresent", true, afterCommitRead.isPresent() );
- assertEquals( "After commit read: data", containerNode, afterCommitRead.get() );
+ afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
+ assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent());
+ assertEquals("After commit read: data", containerNode, afterCommitRead.get());
}
public void testExistsForExistingData() throws Exception {
DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
- assertNotNull( writeTx );
+ assertNotNull(writeTx);
ContainerNode containerNode = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier( new NodeIdentifier( TestModel.TEST_QNAME ) )
- .addChild( ImmutableNodes.mapNodeBuilder( TestModel.OUTER_LIST_QNAME )
- .addChild( ImmutableNodes.mapEntry( TestModel.OUTER_LIST_QNAME,
- TestModel.ID_QNAME, 1 ) ).build() ).build();
+ .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
+ .addChild(ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
+ .addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME,
+ TestModel.ID_QNAME, 1)).build()).build();
- writeTx.merge( TestModel.TEST_PATH, containerNode );
+ writeTx.merge(TestModel.TEST_PATH, containerNode);
CheckedFuture<Boolean, ReadFailedException> exists =
writeTx.exists(TestModel.TEST_PATH);
ready.commit().get();
DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
- assertNotNull( readTx );
+ assertNotNull(readTx);
exists =
readTx.exists(TestModel.TEST_PATH);
public void testExistsForNonExistingData() throws Exception {
DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
- assertNotNull( writeTx );
+ assertNotNull(writeTx);
CheckedFuture<Boolean, ReadFailedException> exists =
writeTx.exists(TestModel.TEST_PATH);
assertEquals(false, exists.checkedGet());
DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
- assertNotNull( readTx );
+ assertNotNull(readTx);
exists =
readTx.exists(TestModel.TEST_PATH);
public void testExistsThrowsReadFailedException() throws Exception {
DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
- assertNotNull( readTx );
+ assertNotNull(readTx);
readTx.close();
public void testReadWithReadOnlyTransactionClosed() throws Throwable {
DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
- assertNotNull( readTx );
+ assertNotNull(readTx);
readTx.close();
- doReadAndThrowEx( readTx );
+ doReadAndThrowEx(readTx);
}
@SuppressWarnings("checkstyle:IllegalThrows")
@Test(expected = ReadFailedException.class)
public void testReadWithReadOnlyTransactionFailure() throws Throwable {
- DataTreeSnapshot mockSnapshot = Mockito.mock( DataTreeSnapshot.class );
- Mockito.doThrow( new RuntimeException( "mock ex" ) ).when( mockSnapshot )
- .readNode( Mockito.any( YangInstanceIdentifier.class ) );
+ DataTreeSnapshot mockSnapshot = Mockito.mock(DataTreeSnapshot.class);
+ Mockito.doThrow(new RuntimeException("mock ex")).when(mockSnapshot)
+ .readNode(Mockito.any(YangInstanceIdentifier.class));
DOMStoreReadTransaction readTx = SnapshotBackedTransactions.newReadTransaction("1", true, mockSnapshot);
- doReadAndThrowEx( readTx );
+ doReadAndThrowEx(readTx);
}
@SuppressWarnings("checkstyle:IllegalThrows")
public void testReadWithReadWriteTransactionClosed() throws Throwable {
DOMStoreReadTransaction readTx = domStore.newReadWriteTransaction();
- assertNotNull( readTx );
+ assertNotNull(readTx);
readTx.close();
- doReadAndThrowEx( readTx );
+ doReadAndThrowEx(readTx);
}
@SuppressWarnings("checkstyle:IllegalThrows")
@Test(expected = ReadFailedException.class)
public void testReadWithReadWriteTransactionFailure() throws Throwable {
- DataTreeSnapshot mockSnapshot = Mockito.mock( DataTreeSnapshot.class );
- DataTreeModification mockModification = Mockito.mock( DataTreeModification.class );
- Mockito.doThrow( new RuntimeException( "mock ex" ) ).when( mockModification )
- .readNode( Mockito.any( YangInstanceIdentifier.class ) );
- Mockito.doReturn( mockModification ).when( mockSnapshot ).newModification();
+ DataTreeSnapshot mockSnapshot = Mockito.mock(DataTreeSnapshot.class);
+ DataTreeModification mockModification = Mockito.mock(DataTreeModification.class);
+ Mockito.doThrow(new RuntimeException("mock ex")).when(mockModification)
+ .readNode(Mockito.any(YangInstanceIdentifier.class));
+ Mockito.doReturn(mockModification).when(mockSnapshot).newModification();
@SuppressWarnings("unchecked")
- TransactionReadyPrototype<String> mockReady = Mockito.mock( TransactionReadyPrototype.class );
+ TransactionReadyPrototype<String> mockReady = Mockito.mock(TransactionReadyPrototype.class);
DOMStoreReadTransaction readTx = SnapshotBackedTransactions.newReadWriteTransaction(
"1", false, mockSnapshot, mockReady);
- doReadAndThrowEx( readTx );
+ doReadAndThrowEx(readTx);
}
@SuppressWarnings("checkstyle:IllegalThrows")
- private static void doReadAndThrowEx( final DOMStoreReadTransaction readTx ) throws Throwable {
+ private static void doReadAndThrowEx(final DOMStoreReadTransaction readTx) throws Throwable {
try {
readTx.read(TestModel.TEST_PATH).get();
- } catch ( ExecutionException e ) {
+ } catch (ExecutionException e) {
throw e.getCause();
}
}
writeTx.ready();
// Should throw ex
- writeTx.write( TestModel.TEST_PATH, ImmutableNodes.containerNode( TestModel.TEST_QNAME ) );
+ writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
}
@Test(expected = IllegalStateException.class)