X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-inmemory-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fstore%2Fimpl%2FDatastoreTestTask.java;h=63e1498c0efe20d697584bb40114528aab507e09;hp=26987a6fba6426169ee7df98340c8ac0f0f4be47;hb=a014c21dce3c024c1fb34ffdb419070ac26302f6;hpb=6d73d16b194435ea1ea783a37d1b51fc1f558a1f diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/DatastoreTestTask.java b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/DatastoreTestTask.java index 26987a6fba..63e1498c0e 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/DatastoreTestTask.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/DatastoreTestTask.java @@ -8,9 +8,11 @@ package org.opendaylight.controller.md.sal.dom.store.impl; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; @@ -37,11 +39,13 @@ public class DatastoreTestTask { private WriteTransactionCustomizer cleanup; private YangInstanceIdentifier changePath; private DataChangeScope changeScope; - private boolean postSetup = false; + private volatile boolean postSetup = false; private final ChangeEventListener internalListener; + private final TestDCLExecutorService dclExecutorService; - public DatastoreTestTask(final DOMStore datastore) { + public DatastoreTestTask(final DOMStore datastore, final TestDCLExecutorService dclExecutorService) { this.store = datastore; + this.dclExecutorService = dclExecutorService; internalListener = new ChangeEventListener(); } @@ -79,7 +83,7 @@ public class DatastoreTestTask { return this; } - public void run() throws InterruptedException, ExecutionException { + public void run() throws InterruptedException, ExecutionException, TimeoutException { if (setup != null) { execute(setup); } @@ -89,13 +93,17 @@ public class DatastoreTestTask { } Preconditions.checkState(write != null, "Write Transaction must be set."); + postSetup = true; + dclExecutorService.afterTestSetup(); + execute(write); if (registration != null) { registration.close(); } + if (changeListener != null) { - changeListener.onDataChanged(internalListener.receivedChange.get()); + changeListener.onDataChanged(getChangeEvent()); } if (read != null) { read.verify(store.newReadOnlyTransaction()); @@ -105,8 +113,26 @@ public class DatastoreTestTask { } } - public Future>> getChangeEvent() { - return internalListener.receivedChange; + public AsyncDataChangeEvent> getChangeEvent() { + try { + return internalListener.receivedChange.get(10, TimeUnit.SECONDS); + } catch( Exception e ) { + fail( "Error getting the AsyncDataChangeEvent from the Future: " + e ); + } + + // won't get here + return null; + } + + public void verifyNoChangeEvent() { + try { + Object unexpected = internalListener.receivedChange.get(500, TimeUnit.MILLISECONDS); + fail( "Got unexpected AsyncDataChangeEvent from the Future: " + unexpected ); + } catch( TimeoutException e ) { + // Expected + } catch( Exception e ) { + fail( "Error getting the AsyncDataChangeEvent from the Future: " + e ); + } } private void execute(final WriteTransactionCustomizer writeCustomizer) throws InterruptedException, @@ -120,11 +146,11 @@ public class DatastoreTestTask { } public interface WriteTransactionCustomizer { - public void customize(DOMStoreReadWriteTransaction tx); + void customize(DOMStoreReadWriteTransaction tx); } public interface ReadTransactionVerifier { - public void verify(DOMStoreReadTransaction tx); + void verify(DOMStoreReadTransaction tx); } private final class ChangeEventListener implements @@ -143,32 +169,15 @@ public class DatastoreTestTask { public static final WriteTransactionCustomizer simpleWrite(final YangInstanceIdentifier path, final NormalizedNode data) { - return new WriteTransactionCustomizer() { - - @Override - public void customize(final DOMStoreReadWriteTransaction tx) { - tx.write(path, data); - } - }; + return tx -> tx.write(path, data); } public static final WriteTransactionCustomizer simpleMerge(final YangInstanceIdentifier path, final NormalizedNode data) { - return new WriteTransactionCustomizer() { - - @Override - public void customize(final DOMStoreReadWriteTransaction tx) { - tx.merge(path, data); - } - }; + return tx -> tx.merge(path, data); } public static final WriteTransactionCustomizer simpleDelete(final YangInstanceIdentifier path) { - return new WriteTransactionCustomizer() { - @Override - public void customize(final DOMStoreReadWriteTransaction tx) { - tx.delete(path); - } - }; + return tx -> tx.delete(path); } }