import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION;
import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.ForwardingExecutorService;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.Collections;
+import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-public class DOMBrokerTest {
+public class DOMBrokerTest extends AbstractDatastoreTest {
- private SchemaContext schemaContext;
private AbstractDOMDataBroker domBroker;
private ListeningExecutorService executor;
private ExecutorService futureExecutor;
private CommitExecutorService commitExecutor;
@Before
- public void setupStore() throws Exception {
+ public void setupStore() {
final InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER",
MoreExecutors.newDirectExecutorService());
final InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG",
MoreExecutors.newDirectExecutorService());
- schemaContext = TestModel.createTestContext();
- operStore.onGlobalContextUpdated(schemaContext);
- configStore.onGlobalContextUpdated(schemaContext);
+ operStore.onGlobalContextUpdated(SCHEMA_CONTEXT);
+ configStore.onGlobalContextUpdated(SCHEMA_CONTEXT);
final ImmutableMap<LogicalDatastoreType, DOMStore> stores =
ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
.build();
commitExecutor = new CommitExecutorService(Executors.newSingleThreadExecutor());
- futureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool(1, 5, "FCB");
+ futureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool(1, 5, "FCB", DOMBrokerTest.class);
executor = new DeadlockDetectingListeningExecutorService(commitExecutor,
TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER, futureExecutor);
domBroker = new SerializedDOMDataBroker(stores, executor);
*/
writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- writeTx.submit().get();
+ writeTx.commit().get();
final Optional<NormalizedNode<?, ?>> afterCommitRead = domBroker.newReadOnlyTransaction()
.read(OPERATIONAL, TestModel.TEST_PATH).get();
}
@Test(expected = TransactionCommitFailedException.class)
- public void testRejectedCommit() throws Exception {
+ @SuppressWarnings({"checkstyle:AvoidHidingCauseException", "checkstyle:IllegalThrows"})
+ public void testRejectedCommit() throws Throwable {
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)
+ Mockito.doReturn(Boolean.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.submit().checkedGet(5, TimeUnit.SECONDS);
+ try {
+ writeTx.commit().get(5, TimeUnit.SECONDS);
+ } catch (ExecutionException e) {
+ throw e.getCause();
+ }
}
@SuppressWarnings("checkstyle:IllegalCatch")
AtomicReference<Throwable> submitTxAsync(final DOMDataTreeWriteTransaction writeTx) {
final AtomicReference<Throwable> caughtEx = new AtomicReference<>();
- new Thread() {
- @Override
- public void run() {
-
- try {
- writeTx.submit();
- } catch (final Throwable e) {
- caughtEx.set(e);
- }
+ new Thread(() -> {
+ try {
+ writeTx.commit();
+ } catch (final Throwable e) {
+ caughtEx.set(e);
}
-
- }.start();
+ }).start();
return caughtEx;
}
@Test(expected = ReadFailedException.class)
- public void basicTests() throws Exception {
+ @SuppressWarnings({"checkstyle:IllegalThrows", "checkstyle:AvoidHidingCauseException"})
+ public void basicTests() throws Throwable {
final DataContainerChild<?, ?> outerList = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
.withChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1))
.build();
assertNotNull(((SerializedDOMDataBroker) domBroker).getCommitStatsTracker());
writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- writeTx.submit().get();
+ writeTx.commit().get();
assertFalse(writeTx.cancel());
assertEquals(false, domBroker.newReadOnlyTransaction().exists(CONFIGURATION, TestModel.TEST_PATH).get());
writeTx = domBroker.newWriteOnlyTransaction();
writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
writeTx.delete(OPERATIONAL, TestModel.TEST_PATH);
- writeTx.submit().get();
+ writeTx.commit().get();
assertEquals(false, domBroker.newReadOnlyTransaction().exists(OPERATIONAL, TestModel.TEST_PATH).get());
assertTrue(domBroker.newWriteOnlyTransaction().cancel());
writeTx = domBroker.newWriteOnlyTransaction();
writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
writeTx.merge(OPERATIONAL, TestModel.TEST_PATH, testContainer);
- writeTx.submit().get();
- assertEquals(true, domBroker.newReadOnlyTransaction().exists(OPERATIONAL, TestModel.TEST_PATH).get());
- assertEquals(true, domBroker.newReadOnlyTransaction().read(OPERATIONAL, TestModel.TEST_PATH).get()
+ writeTx.commit().get();
+ assertEquals(Boolean.TRUE, domBroker.newReadOnlyTransaction().exists(OPERATIONAL, TestModel.TEST_PATH).get());
+ assertEquals(Boolean.TRUE, domBroker.newReadOnlyTransaction().read(OPERATIONAL, TestModel.TEST_PATH).get()
.get().toString().contains(testContainer.toString()));
readRx.close();
+
//Expected exception after close call
- readRx.read(OPERATIONAL, TestModel.TEST_PATH).checkedGet();
+
+ try {
+ readRx.read(OPERATIONAL, TestModel.TEST_PATH).get();
+ } catch (ExecutionException e) {
+ throw e.getCause();
+ }
}
@SuppressWarnings({"checkstyle:IllegalThrows", "checkstyle:IllegalCatch"})