diff --git a/.travis.yml b/.travis.yml index 68d8189..2ee7a0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,3 +13,6 @@ install: true script: - mvn -U -s .travis-maven-settings.xml clean package -B -V + +before_install: + - sudo apt-get install -y etcd diff --git a/README.md b/README.md index b7843ed..7d25d31 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ The plan is contribute this to opendaylight.org, if and when successful. ## How to build? [![Build Status](https://travis-ci.org/vorburger/opendaylight-etcd.svg?branch=master)](https://travis-ci.org/vorburger/opendaylight-etcd) -1. To get a more recent version of jetcd-core than the currently used 0.0.2, just +1. To get a more recent version of jetcd-core than the currently used 0.0.3, just `git clone https://github.com/coreos/jetcd.git ; cd jetcd ; mvn [-DskipTests] clean install` - +and change POMs in bom/, features/odl-mdsal-broker/ & features/odl-etcd-demo-restconf/. 2. If you're hitting an NPE in org.apache.maven.plugins:maven-javadoc-plugin:3.0.0:jar, just use `mvn -Dmaven.javadoc.skip=true -Dduplicate-finder.skip -DskipTests -Dcheckstyle.skip clean install` to work around it; it's possibly diff --git a/artifacts/pom.xml b/artifacts/pom.xml index 6689945..6e1d345 100644 --- a/artifacts/pom.xml +++ b/artifacts/pom.xml @@ -13,7 +13,7 @@ org.opendaylight.odlparent odlparent-lite - 3.1.3 + 4.0.9 diff --git a/bom/pom.xml b/bom/pom.xml index 5e922fb..aa57a89 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -12,7 +12,7 @@ org.opendaylight.odlparent odlparent-lite - 3.1.3 + 4.0.9 @@ -22,7 +22,7 @@ pom - 0.3.0-SNAPSHOT + 0.3.0 @@ -130,7 +130,7 @@ org.opendaylight.mdsal mdsal-artifacts - 2.6.0-SNAPSHOT + 3.0.6 pom import diff --git a/bundle-parent/pom.xml b/bundle-parent/pom.xml index 01c167b..164e46c 100644 --- a/bundle-parent/pom.xml +++ b/bundle-parent/pom.xml @@ -21,26 +21,6 @@ 0.0.1-SNAPSHOT pom - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - checkstyle.violationSeverity=error - - - - org.codehaus.mojo - findbugs-maven-plugin - - true - - - - - - @@ -50,6 +30,32 @@ pom import + + + org.ops4j.pax.cdi + pax-cdi-api + true + 1.0.0.RC2 + + + com.google.guava + guava + + + + org.codehaus.mojo + animal-sniffer-annotations + + + org.checkerframework + checker-compat-qual + + + com.google.code.findbugs + jsr305 + + + @@ -62,7 +68,13 @@ com.google.truth truth + + + + org.checkerframework + checker-compat-qual + + - diff --git a/demo/src/main/java/org/opendaylight/etcd/demo/DemoMain.java b/demo/src/main/java/org/opendaylight/etcd/demo/DemoMain.java index 1254248..411c23c 100644 --- a/demo/src/main/java/org/opendaylight/etcd/demo/DemoMain.java +++ b/demo/src/main/java/org/opendaylight/etcd/demo/DemoMain.java @@ -7,16 +7,16 @@ */ package org.opendaylight.etcd.demo; -import static com.google.common.base.Charsets.US_ASCII; import static io.etcd.jetcd.options.GetOption.SortOrder.ASCEND; import static io.etcd.jetcd.options.GetOption.SortTarget.KEY; +import static java.nio.charset.StandardCharsets.US_ASCII; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION; import com.google.common.collect.Lists; +import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.Client; -import io.etcd.jetcd.data.ByteSequence; -import io.etcd.jetcd.data.KeyValue; +import io.etcd.jetcd.KeyValue; import io.etcd.jetcd.options.GetOption; import java.util.List; import java.util.concurrent.ExecutionException; diff --git a/demo/src/main/java/org/opendaylight/etcd/demo/PerformanceMain.java b/demo/src/main/java/org/opendaylight/etcd/demo/PerformanceMain.java index b3c56f2..0990c3f 100644 --- a/demo/src/main/java/org/opendaylight/etcd/demo/PerformanceMain.java +++ b/demo/src/main/java/org/opendaylight/etcd/demo/PerformanceMain.java @@ -7,7 +7,7 @@ */ package org.opendaylight.etcd.demo; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION; import io.etcd.jetcd.Client; diff --git a/ds/pom.xml b/ds/pom.xml index 81a010d..8c1035c 100644 --- a/ds/pom.xml +++ b/ds/pom.xml @@ -5,8 +5,9 @@ terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html --> - + 4.0.0 @@ -44,10 +45,10 @@ sal-core-compat - org.ops4j.pax.cdi - pax-cdi-api - true - + org.ops4j.pax.cdi + pax-cdi-api + true + ${project.groupId} @@ -70,9 +71,17 @@ - org.apache.aries.blueprint - blueprint-maven-plugin - + org.apache.aries.blueprint + blueprint-maven-plugin + + + + org.opendaylight.mdsal + mdsal-dom-api + 3.0.6 + + + diff --git a/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdDOMDataBroker.java b/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdDOMDataBroker.java index 5d53eb7..1f115ac 100644 --- a/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdDOMDataBroker.java +++ b/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdDOMDataBroker.java @@ -7,7 +7,7 @@ */ package org.opendaylight.etcd.ds.impl; -import static com.google.common.base.Charsets.US_ASCII; +import static java.nio.charset.StandardCharsets.US_ASCII; import com.google.common.io.Files; import io.etcd.jetcd.Client; diff --git a/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdDataStore.java b/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdDataStore.java index e6781a1..785316f 100644 --- a/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdDataStore.java +++ b/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdDataStore.java @@ -7,10 +7,10 @@ */ package org.opendaylight.etcd.ds.impl; +import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.Client; import io.etcd.jetcd.KV; -import io.etcd.jetcd.data.ByteSequence; -import io.etcd.jetcd.data.KeyValue; +import io.etcd.jetcd.KeyValue; import io.etcd.jetcd.watch.WatchEvent; import java.time.Duration; import java.util.List; diff --git a/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdServerUtils.java b/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdServerUtils.java index 4ec7dd7..858f750 100644 --- a/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdServerUtils.java +++ b/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdServerUtils.java @@ -9,9 +9,9 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; +import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.KV; -import io.etcd.jetcd.data.ByteSequence; -import io.etcd.jetcd.data.Response.Header; +import io.etcd.jetcd.Response.Header; import io.etcd.jetcd.options.GetOption; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; diff --git a/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdWatcher.java b/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdWatcher.java index 07427d6..ebf2a66 100644 --- a/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdWatcher.java +++ b/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdWatcher.java @@ -9,18 +9,13 @@ import static java.util.Objects.requireNonNull; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; +import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.Client; import io.etcd.jetcd.Watch; import io.etcd.jetcd.Watch.Watcher; -import io.etcd.jetcd.common.exception.ClosedClientException; -import io.etcd.jetcd.data.ByteSequence; import io.etcd.jetcd.options.WatchOption; import io.etcd.jetcd.watch.WatchEvent; -import io.etcd.jetcd.watch.WatchResponse; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.PreDestroy; @@ -76,36 +71,21 @@ public void close() { } private Watcher watch(long revision) { - Watcher watcher = etcdWatch.watch(prefix, - WatchOption.newBuilder().withPrefix(prefix).withRevision(revision).build()); - // TODO is .withRange(prefix + 1) needed?! - Futures.addCallback(executor.submit(() -> { - while (isOpen.get()) { - WatchResponse response = watcher.listen(); - List events = response.getEvents(); - for (WatchEvent event : events) { - LOG.info("{} watch: eventType={}, KV={}", name, event.getEventType(), - KeyValues.toStringable(event.getKeyValue())); - } - consumer.accept(response.getHeader().getRevision(), events); - } - return null; - }), new FutureCallback() { - - @Override - public void onFailure(Throwable throwable) { - // InterruptedException is normal during close() above - // ClosedClientException happens if we close abruptly due to an error (not normally) - if (!(throwable instanceof InterruptedException) && !(throwable instanceof ClosedClientException)) { - LOG.error("{} watch: executor.submit() (eventually) failed: ", name, throwable); - } + Watch.Listener listener = Watch.listener(response -> { + List events = response.getEvents(); + for (WatchEvent event : events) { + LOG.info("{} watch: eventType={}, KV={}", name, event.getEventType(), + KeyValues.toStringable(event.getKeyValue())); } - - @Override - public void onSuccess(Void nothing) { - // This will happen when isOpen becomes false on close() + try { + consumer.accept(response.getHeader().getRevision(), events); + } catch (EtcdException e) { + LOG.error("watch consumer accept failed", e); } - }, MoreExecutors.directExecutor()); + }); + Watcher watcher = etcdWatch.watch(prefix, + WatchOption.newBuilder().withPrefix(prefix).withRevision(revision).build(), listener); + // TODO is .withRange(prefix + 1) needed?! return watcher; } } diff --git a/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdWatcherSplittingConsumer.java b/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdWatcherSplittingConsumer.java index 98d8c81..5cce3f5 100644 --- a/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdWatcherSplittingConsumer.java +++ b/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdWatcherSplittingConsumer.java @@ -12,7 +12,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.ImmutableSet; -import io.etcd.jetcd.data.ByteSequence; +import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.watch.WatchEvent; import java.util.ArrayList; import java.util.List; diff --git a/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdYangKV.java b/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdYangKV.java index 9864e29..a7e92fb 100644 --- a/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdYangKV.java +++ b/ds/src/main/java/org/opendaylight/etcd/ds/impl/EtcdYangKV.java @@ -14,11 +14,11 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteStreams; +import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.Client; import io.etcd.jetcd.KV; +import io.etcd.jetcd.KeyValue; import io.etcd.jetcd.Txn; -import io.etcd.jetcd.data.ByteSequence; -import io.etcd.jetcd.data.KeyValue; import io.etcd.jetcd.kv.TxnResponse; import io.etcd.jetcd.op.Op; import io.etcd.jetcd.options.DeleteOption; diff --git a/ds/src/main/java/org/opendaylight/etcd/ds/inmemory/copypaste/ChainedTransactionCommitImpl.java b/ds/src/main/java/org/opendaylight/etcd/ds/inmemory/copypaste/ChainedTransactionCommitImpl.java index 1bde1b5..f796d9b 100644 --- a/ds/src/main/java/org/opendaylight/etcd/ds/inmemory/copypaste/ChainedTransactionCommitImpl.java +++ b/ds/src/main/java/org/opendaylight/etcd/ds/inmemory/copypaste/ChainedTransactionCommitImpl.java @@ -7,7 +7,8 @@ */ package org.opendaylight.etcd.ds.inmemory.copypaste; -import com.google.common.base.Preconditions; +import static java.util.Objects.requireNonNull; + import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; @@ -22,7 +23,7 @@ final class ChainedTransactionCommitImpl extends InMemoryDOMStoreThreePhaseCommi final DOMStoreTransactionChainImpl txChain, final Exception operationError) { super(store, transaction, modification, operationError); - this.txChain = Preconditions.checkNotNull(txChain); + this.txChain = requireNonNull(txChain); } @Override diff --git a/ds/src/main/java/org/opendaylight/etcd/ds/inmemory/copypaste/DOMStoreTransactionChainImpl.java b/ds/src/main/java/org/opendaylight/etcd/ds/inmemory/copypaste/DOMStoreTransactionChainImpl.java index 85fca6e..4d27277 100644 --- a/ds/src/main/java/org/opendaylight/etcd/ds/inmemory/copypaste/DOMStoreTransactionChainImpl.java +++ b/ds/src/main/java/org/opendaylight/etcd/ds/inmemory/copypaste/DOMStoreTransactionChainImpl.java @@ -7,7 +7,8 @@ */ package org.opendaylight.etcd.ds.inmemory.copypaste; -import com.google.common.base.Preconditions; +import static java.util.Objects.requireNonNull; + import org.opendaylight.mdsal.dom.spi.store.AbstractSnapshotBackedTransactionChain; import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort; import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction; @@ -19,7 +20,7 @@ final class DOMStoreTransactionChainImpl extends AbstractSnapshotBackedTransacti private final InMemoryDOMDataStore store; DOMStoreTransactionChainImpl(final InMemoryDOMDataStore store) { - this.store = Preconditions.checkNotNull(store); + this.store = requireNonNull(store); } @Override diff --git a/ds/src/main/java/org/opendaylight/etcd/ds/inmemory/copypaste/InMemoryDOMDataStore.java b/ds/src/main/java/org/opendaylight/etcd/ds/inmemory/copypaste/InMemoryDOMDataStore.java index c3892ac..3fc981d 100644 --- a/ds/src/main/java/org/opendaylight/etcd/ds/inmemory/copypaste/InMemoryDOMDataStore.java +++ b/ds/src/main/java/org/opendaylight/etcd/ds/inmemory/copypaste/InMemoryDOMDataStore.java @@ -7,7 +7,8 @@ */ package org.opendaylight.etcd.ds.inmemory.copypaste; -import com.google.common.base.Preconditions; +import static java.util.Objects.requireNonNull; + import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; @@ -69,8 +70,8 @@ public InMemoryDOMDataStore(final String name, final ExecutorService dataChangeL public InMemoryDOMDataStore(final String name, final ExecutorService dataChangeListenerExecutor, final int maxDataChangeListenerQueueSize, final boolean debugTransactions) { - this.name = Preconditions.checkNotNull(name); - this.dataChangeListenerExecutor = Preconditions.checkNotNull(dataChangeListenerExecutor); + this.name = requireNonNull(name); + this.dataChangeListenerExecutor = requireNonNull(dataChangeListenerExecutor); this.debugTransactions = debugTransactions; changePublisher = new InMemoryDOMStoreTreeChangePublisher(this.dataChangeListenerExecutor, maxDataChangeListenerQueueSize); diff --git a/ds/src/main/java/org/opendaylight/etcd/ds/inmemory/copypaste/InMemoryDOMStoreThreePhaseCommitCohort.java b/ds/src/main/java/org/opendaylight/etcd/ds/inmemory/copypaste/InMemoryDOMStoreThreePhaseCommitCohort.java index 975b0d9..7bfc422 100644 --- a/ds/src/main/java/org/opendaylight/etcd/ds/inmemory/copypaste/InMemoryDOMStoreThreePhaseCommitCohort.java +++ b/ds/src/main/java/org/opendaylight/etcd/ds/inmemory/copypaste/InMemoryDOMStoreThreePhaseCommitCohort.java @@ -9,8 +9,8 @@ package org.opendaylight.etcd.ds.inmemory.copypaste; import static com.google.common.base.Preconditions.checkState; +import static java.util.Objects.requireNonNull; -import com.google.common.base.Preconditions; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -42,9 +42,9 @@ class InMemoryDOMStoreThreePhaseCommitCohort implements DOMStoreThreePhaseCommit final SnapshotBackedWriteTransaction writeTransaction, final DataTreeModification modification, final Exception operationError) { - this.transaction = Preconditions.checkNotNull(writeTransaction); - this.modification = Preconditions.checkNotNull(modification); - this.store = Preconditions.checkNotNull(store); + this.transaction = requireNonNull(writeTransaction); + this.modification = requireNonNull(modification); + this.store = requireNonNull(store); this.operationError = operationError; } diff --git a/ds/src/main/java/org/opendaylight/etcd/ds/stream/copypaste/AbstractNormalizedNodeDataOutput.java b/ds/src/main/java/org/opendaylight/etcd/ds/stream/copypaste/AbstractNormalizedNodeDataOutput.java index d6b5fa1..92daf73 100644 --- a/ds/src/main/java/org/opendaylight/etcd/ds/stream/copypaste/AbstractNormalizedNodeDataOutput.java +++ b/ds/src/main/java/org/opendaylight/etcd/ds/stream/copypaste/AbstractNormalizedNodeDataOutput.java @@ -7,6 +7,8 @@ */ package org.opendaylight.etcd.ds.stream.copypaste; +import static java.util.Objects.requireNonNull; + import com.google.common.base.Preconditions; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.DataOutput; @@ -47,7 +49,7 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut private QName lastLeafSetQName; AbstractNormalizedNodeDataOutput(DataOutput output) { - this.output = Preconditions.checkNotNull(output); + this.output = requireNonNull(output); } protected void ensureHeaderWritten() throws IOException { @@ -168,7 +170,7 @@ public void writeNormalizedNode(NormalizedNode node) throws IOException { @Override public void leafNode(NodeIdentifier name, Object value) throws IOException, IllegalArgumentException { - Preconditions.checkNotNull(name, "Node identifier should not be null"); + requireNonNull(name, "Node identifier should not be null"); LOG.trace("Writing a new leaf node"); startNode(NodeTypes.LEAF_NODE, name.getNodeType()); @@ -179,7 +181,7 @@ public void leafNode(NodeIdentifier name, Object value) throws IOException, Ille public void startLeafSet(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException { - Preconditions.checkNotNull(name, "Node identifier should not be null"); + requireNonNull(name, "Node identifier should not be null"); LOG.trace("Starting a new leaf set"); lastLeafSetQName = name.getNodeType(); @@ -189,7 +191,7 @@ public void startLeafSet(NodeIdentifier name, int childSizeHint) @Override public void startOrderedLeafSet(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException { - Preconditions.checkNotNull(name, "Node identifier should not be null"); + requireNonNull(name, "Node identifier should not be null"); LOG.trace("Starting a new ordered leaf set"); lastLeafSetQName = name.getNodeType(); @@ -214,7 +216,7 @@ public void leafSetEntryNode(QName name, Object value) throws IOException, Illeg @Override public void startContainerNode(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException { - Preconditions.checkNotNull(name, "Node identifier should not be null"); + requireNonNull(name, "Node identifier should not be null"); LOG.trace("Starting a new container node"); @@ -224,7 +226,7 @@ public void startContainerNode(NodeIdentifier name, int childSizeHint) @Override public void startYangModeledAnyXmlNode(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException { - Preconditions.checkNotNull(name, "Node identifier should not be null"); + requireNonNull(name, "Node identifier should not be null"); LOG.trace("Starting a new yang modeled anyXml node"); @@ -234,7 +236,7 @@ public void startYangModeledAnyXmlNode(NodeIdentifier name, int childSizeHint) @Override public void startUnkeyedList(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException { - Preconditions.checkNotNull(name, "Node identifier should not be null"); + requireNonNull(name, "Node identifier should not be null"); LOG.trace("Starting a new unkeyed list"); startNode(NodeTypes.UNKEYED_LIST, name.getNodeType()); @@ -243,7 +245,7 @@ public void startUnkeyedList(NodeIdentifier name, int childSizeHint) @Override public void startUnkeyedListItem(NodeIdentifier name, int childSizeHint) throws IOException, IllegalStateException { - Preconditions.checkNotNull(name, "Node identifier should not be null"); + requireNonNull(name, "Node identifier should not be null"); LOG.trace("Starting a new unkeyed list item"); startNode(NodeTypes.UNKEYED_LIST_ITEM, name.getNodeType()); @@ -252,7 +254,7 @@ public void startUnkeyedListItem(NodeIdentifier name, int childSizeHint) @Override public void startMapNode(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException { - Preconditions.checkNotNull(name, "Node identifier should not be null"); + requireNonNull(name, "Node identifier should not be null"); LOG.trace("Starting a new map node"); startNode(NodeTypes.MAP_NODE, name.getNodeType()); @@ -261,7 +263,7 @@ public void startMapNode(NodeIdentifier name, int childSizeHint) @Override public void startMapEntryNode(NodeIdentifierWithPredicates identifier, int childSizeHint) throws IOException, IllegalArgumentException { - Preconditions.checkNotNull(identifier, "Node identifier should not be null"); + requireNonNull(identifier, "Node identifier should not be null"); LOG.trace("Starting a new map entry node"); startNode(NodeTypes.MAP_ENTRY_NODE, identifier.getNodeType()); @@ -272,7 +274,7 @@ public void startMapEntryNode(NodeIdentifierWithPredicates identifier, int child @Override public void startOrderedMapNode(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException { - Preconditions.checkNotNull(name, "Node identifier should not be null"); + requireNonNull(name, "Node identifier should not be null"); LOG.trace("Starting a new ordered map node"); startNode(NodeTypes.ORDERED_MAP_NODE, name.getNodeType()); @@ -281,7 +283,7 @@ public void startOrderedMapNode(NodeIdentifier name, int childSizeHint) @Override public void startChoiceNode(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException { - Preconditions.checkNotNull(name, "Node identifier should not be null"); + requireNonNull(name, "Node identifier should not be null"); LOG.trace("Starting a new choice node"); startNode(NodeTypes.CHOICE_NODE, name.getNodeType()); @@ -290,7 +292,7 @@ public void startChoiceNode(NodeIdentifier name, int childSizeHint) @Override public void startAugmentationNode(AugmentationIdentifier identifier) throws IOException, IllegalArgumentException { - Preconditions.checkNotNull(identifier, "Node identifier should not be null"); + requireNonNull(identifier, "Node identifier should not be null"); LOG.trace("Starting a new augmentation node"); output.writeByte(NodeTypes.AUGMENTATION_NODE); @@ -299,7 +301,7 @@ public void startAugmentationNode(AugmentationIdentifier identifier) @Override public void anyxmlNode(NodeIdentifier name, Object value) throws IOException, IllegalArgumentException { - Preconditions.checkNotNull(name, "Node identifier should not be null"); + requireNonNull(name, "Node identifier should not be null"); LOG.trace("Writing any xml node"); startNode(NodeTypes.ANY_XML_NODE, name.getNodeType()); @@ -333,7 +335,7 @@ public void flush() throws IOException { } protected void startNode(byte nodeType, QName qname) throws IOException { - Preconditions.checkNotNull(qname, "QName of node identifier should not be null."); + requireNonNull(qname, "QName of node identifier should not be null."); startNode(nodeType); // Write Start Tag writeQName(qname); diff --git a/ds/src/main/java/org/opendaylight/etcd/ds/stream/copypaste/NormalizedNodeInputStreamReader.java b/ds/src/main/java/org/opendaylight/etcd/ds/stream/copypaste/NormalizedNodeInputStreamReader.java index 46f6e0e..5b453b9 100644 --- a/ds/src/main/java/org/opendaylight/etcd/ds/stream/copypaste/NormalizedNodeInputStreamReader.java +++ b/ds/src/main/java/org/opendaylight/etcd/ds/stream/copypaste/NormalizedNodeInputStreamReader.java @@ -8,7 +8,8 @@ package org.opendaylight.etcd.ds.stream.copypaste; -import com.google.common.base.Preconditions; +import static java.util.Objects.requireNonNull; + import com.google.common.base.Strings; import com.google.errorprone.annotations.Var; import java.io.DataInput; @@ -79,7 +80,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput private boolean readSignatureMarker = true; protected NormalizedNodeInputStreamReader(DataInput input, boolean versionChecked) { - this.input = Preconditions.checkNotNull(input); + this.input = requireNonNull(input); readSignatureMarker = !versionChecked; } diff --git a/ds/src/main/java/org/opendaylight/etcd/utils/ByteSequences.java b/ds/src/main/java/org/opendaylight/etcd/utils/ByteSequences.java index a3ea088..78103e0 100644 --- a/ds/src/main/java/org/opendaylight/etcd/utils/ByteSequences.java +++ b/ds/src/main/java/org/opendaylight/etcd/utils/ByteSequences.java @@ -8,7 +8,7 @@ package org.opendaylight.etcd.utils; import com.google.errorprone.annotations.Var; -import io.etcd.jetcd.data.ByteSequence; +import io.etcd.jetcd.ByteSequence; import java.util.Arrays; /** diff --git a/ds/src/main/java/org/opendaylight/etcd/utils/KeyValues.java b/ds/src/main/java/org/opendaylight/etcd/utils/KeyValues.java index 40bedac..bd514dc 100644 --- a/ds/src/main/java/org/opendaylight/etcd/utils/KeyValues.java +++ b/ds/src/main/java/org/opendaylight/etcd/utils/KeyValues.java @@ -7,8 +7,8 @@ */ package org.opendaylight.etcd.utils; -import io.etcd.jetcd.data.ByteSequence; -import io.etcd.jetcd.data.KeyValue; +import io.etcd.jetcd.ByteSequence; +import io.etcd.jetcd.KeyValue; /** * Utilities for {@link ByteSequence}. diff --git a/ds/src/main/java/org/opendaylight/etcd/utils/LoggingKV.java b/ds/src/main/java/org/opendaylight/etcd/utils/LoggingKV.java index 06640fd..893d659 100644 --- a/ds/src/main/java/org/opendaylight/etcd/utils/LoggingKV.java +++ b/ds/src/main/java/org/opendaylight/etcd/utils/LoggingKV.java @@ -11,9 +11,9 @@ import com.google.common.base.MoreObjects; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.KV; import io.etcd.jetcd.Txn; -import io.etcd.jetcd.data.ByteSequence; import io.etcd.jetcd.kv.CompactResponse; import io.etcd.jetcd.kv.DeleteResponse; import io.etcd.jetcd.kv.GetResponse; diff --git a/ds/src/main/resources/org/opendaylight/blueprint/ds-blueprint.xml b/ds/src/main/resources/OSGI-INF/blueprint/ds-blueprint.xml similarity index 100% rename from ds/src/main/resources/org/opendaylight/blueprint/ds-blueprint.xml rename to ds/src/main/resources/OSGI-INF/blueprint/ds-blueprint.xml diff --git a/ds/src/test/java/org/opendaylight/etcd/ds/impl/EtcdWatcherSplittingConsumerTest.java b/ds/src/test/java/org/opendaylight/etcd/ds/impl/EtcdWatcherSplittingConsumerTest.java index 2f51947..1cb90ec 100644 --- a/ds/src/test/java/org/opendaylight/etcd/ds/impl/EtcdWatcherSplittingConsumerTest.java +++ b/ds/src/test/java/org/opendaylight/etcd/ds/impl/EtcdWatcherSplittingConsumerTest.java @@ -16,8 +16,9 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; -import io.etcd.jetcd.data.ByteSequence; -import io.etcd.jetcd.data.KeyValue; +import io.etcd.jetcd.ByteSequence; +import io.etcd.jetcd.KeyValue; +import io.etcd.jetcd.shaded.com.google.protobuf.ByteString; import io.etcd.jetcd.watch.WatchEvent; import io.etcd.jetcd.watch.WatchEvent.EventType; import java.util.Collections; @@ -87,8 +88,9 @@ public void testOnlyConfigAndOperAndAnotherOneToIgnore() throws EtcdException { private static WatchEvent newWatchEvent(ByteSequence key) { return new WatchEvent( - new KeyValue(io.etcd.jetcd.api.KeyValue.newBuilder().setKey(key.getByteString()).build()), null, - EventType.PUT); + new KeyValue( + io.etcd.jetcd.api.KeyValue.newBuilder().setKey(ByteString.copyFrom(key.getBytes())).build()), + null, EventType.PUT); } private static class TestConsumer implements CheckedConsumer, EtcdException> { diff --git a/ds/src/test/java/org/opendaylight/etcd/ds/impl/EtcdYangKVTest.java b/ds/src/test/java/org/opendaylight/etcd/ds/impl/EtcdYangKVTest.java index 83944b7..f719d6d 100644 --- a/ds/src/test/java/org/opendaylight/etcd/ds/impl/EtcdYangKVTest.java +++ b/ds/src/test/java/org/opendaylight/etcd/ds/impl/EtcdYangKVTest.java @@ -9,8 +9,8 @@ import static com.google.common.truth.Truth.assertThat; +import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.Client; -import io.etcd.jetcd.data.ByteSequence; import org.junit.Test; import org.mockito.Mockito; import org.opendaylight.etcd.utils.ByteSequences; diff --git a/ds/src/test/java/org/opendaylight/etcd/utils/test/ByteSequencesTest.java b/ds/src/test/java/org/opendaylight/etcd/utils/test/ByteSequencesTest.java index fa105a6..d909818 100644 --- a/ds/src/test/java/org/opendaylight/etcd/utils/test/ByteSequencesTest.java +++ b/ds/src/test/java/org/opendaylight/etcd/utils/test/ByteSequencesTest.java @@ -8,10 +8,10 @@ package org.opendaylight.etcd.utils.test; import static com.google.common.truth.Truth.assertThat; -import static io.etcd.jetcd.data.ByteSequence.from; +import static io.etcd.jetcd.ByteSequence.from; import static org.opendaylight.etcd.utils.ByteSequences.toStringable; -import io.etcd.jetcd.data.ByteSequence; +import io.etcd.jetcd.ByteSequence; import org.junit.Test; /** diff --git a/eos/src/main/java/org/opendaylight/etcd/eos/impl/DelegatingDOMEntityOwnershipService.java b/eos/src/main/java/org/opendaylight/etcd/eos/impl/DelegatingDOMEntityOwnershipService.java index f6e4f1a..a8fd85f 100644 --- a/eos/src/main/java/org/opendaylight/etcd/eos/impl/DelegatingDOMEntityOwnershipService.java +++ b/eos/src/main/java/org/opendaylight/etcd/eos/impl/DelegatingDOMEntityOwnershipService.java @@ -7,7 +7,7 @@ */ package org.opendaylight.etcd.eos.impl; -import com.google.common.base.Optional; +import java.util.Optional; import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException; import org.opendaylight.mdsal.eos.common.api.EntityOwnershipState; import org.opendaylight.mdsal.eos.dom.api.DOMEntity; diff --git a/features/features-etcd/pom.xml b/features/features-etcd/pom.xml index 84305d3..cc11a7a 100644 --- a/features/features-etcd/pom.xml +++ b/features/features-etcd/pom.xml @@ -13,7 +13,7 @@ org.opendaylight.odlparent feature-repo-parent - 3.1.3 + 4.0.9 diff --git a/features/odl-etcd-datastore/pom.xml b/features/odl-etcd-datastore/pom.xml index e1cc7fc..01b66ba 100644 --- a/features/odl-etcd-datastore/pom.xml +++ b/features/odl-etcd-datastore/pom.xml @@ -7,7 +7,7 @@ org.opendaylight.odlparent single-feature-parent - 3.1.3 + 4.0.9 diff --git a/features/odl-etcd-demo-restconf/pom.xml b/features/odl-etcd-demo-restconf/pom.xml index bd72274..9d5356e 100644 --- a/features/odl-etcd-demo-restconf/pom.xml +++ b/features/odl-etcd-demo-restconf/pom.xml @@ -7,7 +7,7 @@ org.opendaylight.odlparent single-feature-parent - 3.1.3 + 4.0.9 @@ -52,7 +52,7 @@ io.etcd jetcd-launcher-maven-plugin - 0.3.0-SNAPSHOT + 0.3.0 start-etcd @@ -71,5 +71,34 @@ + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + io.etcd + jetcd-launcher-maven-plugin + [0.3.0,) + + start + + + + + + + + + + + + diff --git a/features/odl-mdsal-broker/pom.xml b/features/odl-mdsal-broker/pom.xml index 3f11a16..367aff4 100644 --- a/features/odl-mdsal-broker/pom.xml +++ b/features/odl-mdsal-broker/pom.xml @@ -7,7 +7,7 @@ org.opendaylight.odlparent single-feature-parent - 3.1.3 + 4.0.9 @@ -91,7 +91,7 @@ io.etcd jetcd-launcher-maven-plugin - 0.3.0-SNAPSHOT + 0.3.0 start-etcd @@ -110,5 +110,34 @@ + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + io.etcd + jetcd-launcher-maven-plugin + [0.3.0,) + + start + + + + + + + + + + + + diff --git a/features/pom.xml b/features/pom.xml new file mode 100644 index 0000000..a4c6bd3 --- /dev/null +++ b/features/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + + org.opendaylight.odlparent + odlparent-lite + 4.0.9 + + + + org.opendaylight.etcd + features-aggregator + 0.0.1-SNAPSHOT + pom + + + odl-etcd-datastore + odl-mdsal-broker + + features-etcd + + + diff --git a/karaf/pom.xml b/karaf/pom.xml index d020689..fef76a0 100644 --- a/karaf/pom.xml +++ b/karaf/pom.xml @@ -12,7 +12,7 @@ org.opendaylight.odlparent karaf4-parent - 3.1.3 + 4.0.9 diff --git a/launcher/src/test/java/org/opendaylight/etcd/launcher/test/EtcdLauncherTest.java b/launcher/src/test/java/org/opendaylight/etcd/launcher/test/EtcdLauncherTest.java index cfe8422..c859bee 100644 --- a/launcher/src/test/java/org/opendaylight/etcd/launcher/test/EtcdLauncherTest.java +++ b/launcher/src/test/java/org/opendaylight/etcd/launcher/test/EtcdLauncherTest.java @@ -7,14 +7,14 @@ */ package org.opendaylight.etcd.launcher.test; -import static com.google.common.base.Charsets.UTF_8; import static com.google.common.truth.Truth.assertThat; +import static java.nio.charset.StandardCharsets.UTF_8; import ch.vorburger.exec.ManagedProcessException; +import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.Client; import io.etcd.jetcd.KV; -import io.etcd.jetcd.data.ByteSequence; -import io.etcd.jetcd.data.KeyValue; +import io.etcd.jetcd.KeyValue; import io.etcd.jetcd.kv.GetResponse; import java.io.IOException; import java.nio.file.Paths; diff --git a/pom.xml b/pom.xml index c74c968..af08c6c 100644 --- a/pom.xml +++ b/pom.xml @@ -31,12 +31,10 @@ ds test-model testutils + test-netconf demo eos - features/odl-etcd-datastore - features/odl-mdsal-broker - features/odl-etcd-demo-restconf - features/features-etcd + features karaf artifacts diff --git a/test-model/pom.xml b/test-model/pom.xml index 166ed33..c890068 100644 --- a/test-model/pom.xml +++ b/test-model/pom.xml @@ -5,7 +5,7 @@ org.opendaylight.mdsal binding-parent - 0.13.1-SNAPSHOT + 3.0.6 diff --git a/test-netconf/pom.xml b/test-netconf/pom.xml new file mode 100644 index 0000000..c814090 --- /dev/null +++ b/test-netconf/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + + org.opendaylight.etcd + bundle-parent + 0.0.1-SNAPSHOT + ../bundle-parent + + + test-netconf + + + + ${project.groupId} + testutils + ${project.version} + test + + + + org.opendaylight.netconf + restconf-nb-rfc8040 + + 1.10.0-SNAPSHOT + + + org.opendaylight.mdsal.binding.model.ietf + rfc7895 + + + + + diff --git a/test-netconf/src/test/java/org/opendaylight/etcd/netconf/test/RestConfTest.java b/test-netconf/src/test/java/org/opendaylight/etcd/netconf/test/RestConfTest.java new file mode 100644 index 0000000..cefd35f --- /dev/null +++ b/test-netconf/src/test/java/org/opendaylight/etcd/netconf/test/RestConfTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2019 Red Hat, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.etcd.netconf.test; + +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.opendaylight.etcd.testutils.EtcdDataBrokerRule; +import org.opendaylight.etcd.testutils.EtcdLauncherRule; +import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler; + +/** + * Test RESTCONF running on etcd. + * + * @author Michael Vorburger.ch + */ +public class RestConfTest { + + // TODO when https://git.opendaylight.org/gerrit/#/c/79388/ is merged, use that + + public static @ClassRule EtcdLauncherRule etcdLauncher = new EtcdLauncherRule(); + + public @Rule EtcdDataBrokerRule dbRule = new EtcdDataBrokerRule(etcdLauncher); + + @Test + // for https://github.com/vorburger/opendaylight-etcd/issues/8, but doesn't + // really reproduce it, unless there are a lot of YANG models on the classpath + public void testSchemaContextHandlerInitialization() { + try (TransactionChainHandler transactionChainHandler = new TransactionChainHandler(dbRule.getDOMDataBroker())) { + try (SchemaContextHandler schemaContextHandler = SchemaContextHandler.newInstance(transactionChainHandler, + dbRule.getDOMSchemaService())) { + schemaContextHandler.init(); + schemaContextHandler.onGlobalContextUpdated(dbRule.getDOMSchemaService().getGlobalContext()); + } + } + } + + @Test + @Ignore // TODO https://github.com/vorburger/opendaylight-etcd/issues/9 + public void testSchemaContextHandlerInitializationAgain() { + try (TransactionChainHandler transactionChainHandler = new TransactionChainHandler(dbRule.getDOMDataBroker())) { + try (SchemaContextHandler schemaContextHandler = SchemaContextHandler.newInstance(transactionChainHandler, + dbRule.getDOMSchemaService())) { + schemaContextHandler.init(); + schemaContextHandler.onGlobalContextUpdated(dbRule.getDOMSchemaService().getGlobalContext()); + } + } + } +} diff --git a/testutils/pom.xml b/testutils/pom.xml index 50bce95..c1f1f53 100644 --- a/testutils/pom.xml +++ b/testutils/pom.xml @@ -45,12 +45,16 @@ test-jar compile + + junit + junit + compile + ${project.groupId} launcher ${project.version} - test org.opendaylight.controller diff --git a/testutils/src/main/java/org/opendaylight/etcd/testutils/EtcdDataBrokerRule.java b/testutils/src/main/java/org/opendaylight/etcd/testutils/EtcdDataBrokerRule.java new file mode 100644 index 0000000..0f7ab2e --- /dev/null +++ b/testutils/src/main/java/org/opendaylight/etcd/testutils/EtcdDataBrokerRule.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2019 Red Hat, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.etcd.testutils; + +import io.etcd.jetcd.Client; +import java.net.URI; +import java.util.Collection; +import java.util.Collections; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; +import org.opendaylight.etcd.ds.impl.TestTool; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.dom.api.DOMDataBroker; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; + +/** + * JUnit Rule providing a {@link DataBroker} & {@link DOMDataBroker} backed by etcd. + * + * @author Michael Vorburger.ch + */ +public class EtcdDataBrokerRule implements TestRule { + + private final Collection etcdServerURIs; + private final String name; + + protected TestEtcdDataBrokerProvider currentProvider; + + public EtcdDataBrokerRule(EtcdLauncherRule launcherRule, String name) { + etcdServerURIs = launcherRule.getClusterURIs(); + this.name = name; + } + + public EtcdDataBrokerRule(EtcdLauncherRule launcherRule) { + this(launcherRule, EtcdDataBrokerRule.class.getSimpleName()); + } + + public EtcdDataBrokerRule(String etcdServerURI) { + etcdServerURIs = Collections.singleton(URI.create(etcdServerURI)); + name = EtcdDataBrokerRule.class.getSimpleName(); + } + + @Override + public Statement apply(Statement statement, Description description) { + return new Statement() { + + @Override + public void evaluate() throws Throwable { + try (Client client = Client.builder().endpoints(etcdServerURIs).build()) { + try (TestEtcdDataBrokerProvider dbProvider = new TestEtcdDataBrokerProvider(client, name)) { + currentProvider = dbProvider; + statement.evaluate(); + } + currentProvider = null; + } + } + }; + } + + public DOMSchemaService getDOMSchemaService() { + return currentProvider.getDOMSchemaService(); + } + + public DOMDataBroker getDOMDataBroker() { + return currentProvider.getDOMDataBroker(); + } + + public DataBroker getDataBroker() { + return currentProvider.getDataBroker(); + } + + public TestTool getTestTool() { + return currentProvider.getTestTool(); + } +} diff --git a/testutils/src/main/java/org/opendaylight/etcd/testutils/EtcdLauncherRule.java b/testutils/src/main/java/org/opendaylight/etcd/testutils/EtcdLauncherRule.java new file mode 100644 index 0000000..4faee03 --- /dev/null +++ b/testutils/src/main/java/org/opendaylight/etcd/testutils/EtcdLauncherRule.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2019 Red Hat, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.etcd.testutils; + +import java.net.URI; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collection; +import java.util.Collections; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; +import org.opendaylight.etcd.launcher.EtcdLauncher; + +/** + * JUnit Rule for {@link EtcdLauncher}. + * + * @author Michael Vorburger.ch + */ +public class EtcdLauncherRule implements TestRule { + + // TODO upstream this into jetcd ... + + protected final Path etcdWorkingDirectory; + protected EtcdLauncher currentEtcdServer; + + public EtcdLauncherRule() { + this(Paths.get("target/etcd")); + } + + public EtcdLauncherRule(Path etcdWorkingDirectory) { + this.etcdWorkingDirectory = etcdWorkingDirectory; + } + + @Override + public Statement apply(Statement statement, Description description) { + return new Statement() { + + @Override + public void evaluate() throws Throwable { + try (EtcdLauncher etcdServer = new EtcdLauncher(etcdWorkingDirectory, true)) { + etcdServer.start(); + currentEtcdServer = etcdServer; + + statement.evaluate(); + } + currentEtcdServer = null; + } + }; + } + + public Collection getClusterURIs() { + if (currentEtcdServer != null) { + return Collections.singleton(currentEtcdServer.getClusterURI()); + } else { + throw new IllegalStateException("getClusterURIs() can only be called with active rule"); + } + } +} diff --git a/testutils/src/main/java/org/opendaylight/etcd/testutils/TestEtcdDataBrokerProvider.java b/testutils/src/main/java/org/opendaylight/etcd/testutils/TestEtcdDataBrokerProvider.java index 385be2f..2474c36 100644 --- a/testutils/src/main/java/org/opendaylight/etcd/testutils/TestEtcdDataBrokerProvider.java +++ b/testutils/src/main/java/org/opendaylight/etcd/testutils/TestEtcdDataBrokerProvider.java @@ -27,6 +27,7 @@ import org.opendaylight.mdsal.binding.generator.util.JavassistUtils; import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections; import org.opendaylight.mdsal.dom.api.DOMDataBroker; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.yangtools.yang.binding.YangModuleInfo; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -37,13 +38,14 @@ */ public class TestEtcdDataBrokerProvider implements AutoCloseable { + private final MockSchemaService schemaService; private final EtcdDOMDataBrokerProvider wiring; private final DataBroker dataBroker; // TODO pass Client instead of ClientBuilder public TestEtcdDataBrokerProvider(Client client, String name) throws Exception { // from org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTestCustomizer - MockSchemaService schemaService = new MockSchemaService(); + schemaService = new MockSchemaService(); // create DOMDataBroker wiring = new EtcdDOMDataBrokerProvider(client, name, schemaService); @@ -70,6 +72,10 @@ public void close() throws Exception { wiring.close(); } + public DOMSchemaService getDOMSchemaService() { + return schemaService; + } + public DOMDataBroker getDOMDataBroker() { return wiring.getDOMDataBroker(); } diff --git a/testutils/src/test/java/org/opendaylight/etcd/testutils/test/EtcdDBTest.java b/testutils/src/test/java/org/opendaylight/etcd/testutils/test/EtcdDBTest.java index 774eba4..13dbe94 100644 --- a/testutils/src/test/java/org/opendaylight/etcd/testutils/test/EtcdDBTest.java +++ b/testutils/src/test/java/org/opendaylight/etcd/testutils/test/EtcdDBTest.java @@ -15,30 +15,26 @@ import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION; import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL; -import ch.vorburger.exec.ManagedProcessException; +import io.etcd.jetcd.ByteSequence; import io.etcd.jetcd.Client; import io.etcd.jetcd.KV; -import io.etcd.jetcd.data.ByteSequence; -import io.etcd.jetcd.data.KeyValue; +import io.etcd.jetcd.KeyValue; import io.etcd.jetcd.kv.GetResponse; import io.etcd.jetcd.options.DeleteOption; import io.etcd.jetcd.options.GetOption; -import java.io.IOException; -import java.nio.file.Paths; import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.opendaylight.etcd.ds.impl.EtcdDataStore; -import org.opendaylight.etcd.launcher.EtcdLauncher; +import org.opendaylight.etcd.testutils.EtcdLauncherRule; import org.opendaylight.etcd.testutils.TestEtcdDataBrokerProvider; import org.opendaylight.infrautils.testutils.LogRule; import org.opendaylight.mdsal.binding.api.DataBroker; @@ -77,7 +73,7 @@ public class EtcdDBTest { private static final InstanceIdentifier TOP_PATH = InstanceIdentifier.create(Top.class); - private static EtcdLauncher etcdServer; + public static @ClassRule EtcdLauncherRule etcdLauncher = new EtcdLauncherRule(); private Client client; private TestEtcdDataBrokerProvider dbProviderA; @@ -89,17 +85,9 @@ public class EtcdDBTest { // public @Rule LogCaptureRule logCaptureRule = new LogCaptureRule(); public @Rule LogRule logRule = new LogRule(); - // TODO Make an EtcdClassRule to replace the @BeforeClass - - @BeforeClass - public static void beforeClass() throws ManagedProcessException, IOException { - etcdServer = new EtcdLauncher(Paths.get("target/etcd"), true); - etcdServer.start(); - } - @Before public void before() throws Exception { - client = Client.builder().endpoints(etcdServer.getEndpointURL()).build(); + client = Client.builder().endpoints(etcdLauncher.getClusterURIs()).build(); // STOP any DB Watcher that is possibly still running from previous test closeProviders(); @@ -134,12 +122,6 @@ public void after() throws Exception { client.close(); } - @AfterClass - public static void afterClass() throws ManagedProcessException { - etcdServer.close(); - etcdServer = null; - } - @Test public void testDataBrokerIsNotNull() { assertThat(dataBrokerA).isNotNull(); diff --git a/testutils/src/test/java/org/opendaylight/etcd/testutils/test/EtcdDataBrokerRuleTest.java b/testutils/src/test/java/org/opendaylight/etcd/testutils/test/EtcdDataBrokerRuleTest.java new file mode 100644 index 0000000..ea41df9 --- /dev/null +++ b/testutils/src/test/java/org/opendaylight/etcd/testutils/test/EtcdDataBrokerRuleTest.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2019 Red Hat, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.etcd.testutils.test; + +import static com.google.common.truth.Truth.assertThat; + +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.opendaylight.etcd.testutils.EtcdDataBrokerRule; +import org.opendaylight.etcd.testutils.EtcdLauncherRule; + +/** + * Test for the {@link EtcdDataBrokerRule}. + * + * @author Michael Vorburger.ch + */ +public class EtcdDataBrokerRuleTest { + + public static @ClassRule EtcdLauncherRule etcdLauncher = new EtcdLauncherRule(); + + public @Rule EtcdDataBrokerRule dbRule = new EtcdDataBrokerRule(etcdLauncher); + + @Test + public void testDataBroker() { + assertThat(dbRule.getDataBroker()).isNotNull(); + } +}