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.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
+import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
import org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStore;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-public class DOMTransactionChainTest {
+public class DOMTransactionChainTest extends AbstractDatastoreTest {
- private SchemaContext schemaContext;
private AbstractDOMDataBroker domBroker;
@Before
- public void setupStore() throws Exception{
- 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);
-
- final ImmutableMap<LogicalDatastoreType, DOMStore> stores = ImmutableMap.<LogicalDatastoreType, DOMStore> builder() //
- .put(CONFIGURATION, configStore) //
- .put(OPERATIONAL, operStore) //
+ public void setupStore() {
+ final InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER",
+ MoreExecutors.newDirectExecutorService());
+ final InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG",
+ MoreExecutors.newDirectExecutorService());
+
+ operStore.onGlobalContextUpdated(SCHEMA_CONTEXT);
+ configStore.onGlobalContextUpdated(SCHEMA_CONTEXT);
+
+ final ImmutableMap<LogicalDatastoreType, DOMStore> stores =
+ ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
+ .put(CONFIGURATION, configStore)
+ .put(OPERATIONAL, operStore)
.build();
- final ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
+ final ListeningExecutorService executor = MoreExecutors.listeningDecorator(
+ Executors.newSingleThreadExecutor());
domBroker = new SerializedDOMDataBroker(stores, executor);
}
assertNotNull(txChain);
/**
- * We alocate new read-write transaction and write /test
- *
- *
+ * We alocate new read-write transaction and write /test.
*/
final DOMDataTreeWriteTransaction firstTx = allocateAndWrite(txChain);
/**
* First transaction is marked as ready, we are able to allocate chained
- * transactions
+ * transactions.
*/
- final ListenableFuture<Void> firstWriteTxFuture = firstTx.submit();
+ final ListenableFuture<? extends CommitInfo> firstWriteTxFuture = firstTx.commit();
/**
* We alocate chained transaction - read transaction.
assertTestContainerExists(secondReadTx);
/**
- *
* We alocate next transaction, which is still based on first one, but
* is read-write.
*
assertCommitSuccessful(firstWriteTxFuture);
/**
- *
* Allocates transaction from data store.
*
*/
assertTestContainerExists(storeReadTx);
/**
- * third transaction is sealed and commited
+ * third transaction is sealed and commited.
*/
- final ListenableFuture<Void> thirdDeleteTxFuture = thirdDeleteTx.submit();
- assertCommitSuccessful(thirdDeleteTxFuture);
+ assertCommitSuccessful(thirdDeleteTx.commit());
/**
* We close transaction chain.
listener.getSuccessFuture().get(1000, TimeUnit.MILLISECONDS);
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
@Test
public void testTransactionChainNotSealed() throws InterruptedException, ExecutionException, TimeoutException {
final BlockingTransactionChainListener listener = new BlockingTransactionChainListener();
/**
* We alocate new read-write transaction and write /test
- *
- *
*/
allocateAndWrite(txChain);
return tx;
}
- private static void assertCommitSuccessful(final ListenableFuture<Void> future)
+ private static void assertCommitSuccessful(final ListenableFuture<? extends CommitInfo> firstWriteTxFuture)
throws InterruptedException, ExecutionException {
- future.get();
+ firstWriteTxFuture.get();
}
- private static void assertTestContainerExists(final DOMDataTreeReadTransaction readTx) throws InterruptedException,
- ExecutionException {
- final ListenableFuture<Optional<NormalizedNode<?, ?>>> readFuture = readTx.read(OPERATIONAL, TestModel.TEST_PATH);
+ private static void assertTestContainerExists(final DOMDataTreeReadTransaction readTx)
+ throws InterruptedException, ExecutionException {
+ final ListenableFuture<Optional<NormalizedNode<?, ?>>> readFuture =
+ readTx.read(OPERATIONAL, TestModel.TEST_PATH);
final Optional<NormalizedNode<?, ?>> readedData = readFuture.get();
assertTrue(readedData.isPresent());
}