diff options
author | 2018-09-25 11:15:35 +0200 | |
---|---|---|
committer | 2018-09-25 11:22:18 +0200 | |
commit | 556a0f59abc9b09005d40945bc20948d69e4f98e (patch) | |
tree | 76d795ae59aba49521fc4fdc7d65062c946147be /infra/translate-impl/src | |
parent | 46bcceb927b1bce07c1c9517f45470703293eb84 (diff) |
Bump ODL dependencies to Fluorine (HONEYCOMB-433)
Change-Id: I142ebd2899272feff00abe7d4bae708f093ee3ec
Signed-off-by: Michal Cmarada <michal.cmarada@pantheon.tech>
Diffstat (limited to 'infra/translate-impl/src')
8 files changed, 65 insertions, 12 deletions
diff --git a/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/read/GenericInitReader.java b/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/read/GenericInitReader.java index e55bc8ab6..147cbd3cc 100644 --- a/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/read/GenericInitReader.java +++ b/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/read/GenericInitReader.java @@ -19,6 +19,9 @@ package io.fd.honeycomb.translate.impl.read; import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION; import com.google.common.base.Optional; +import com.google.common.util.concurrent.FluentFuture; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.MoreExecutors; import io.fd.honeycomb.translate.read.InitFailedException; import io.fd.honeycomb.translate.read.InitReader; import io.fd.honeycomb.translate.read.ReadContext; @@ -26,8 +29,10 @@ import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -68,6 +73,17 @@ public final class GenericInitReader<O extends DataObject, B extends Builder<O>> static void writeInit(final DataBroker broker, final Initialized<? extends DataObject> init) { final WriteTransaction writeTx = broker.newWriteOnlyTransaction(); writeTx.merge(CONFIGURATION, (InstanceIdentifier) init.getId(), init.getData(), true); - writeTx.submit(); + FluentFuture<? extends CommitInfo> future = writeTx.commit(); + future.addCallback(new FutureCallback<CommitInfo>() { + @Override + public void onSuccess(@NullableDecl final CommitInfo commitInfo) { + LOG.debug("Transaction: {} successfully committed.", writeTx); + } + + @Override + public void onFailure(final Throwable throwable) { + LOG.warn("Transaction: {} failed.", writeTx); + } + }, MoreExecutors.directExecutor()); } } diff --git a/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/GenericListWriter.java b/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/GenericListWriter.java index ff683b810..cc4800a65 100644 --- a/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/GenericListWriter.java +++ b/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/GenericListWriter.java @@ -92,7 +92,7 @@ public final class GenericListWriter<D extends DataObject & Identifiable<K>, K e // Make sure the key is present if (isWildcarded(id)) { return RWUtils.replaceLastInId(id, - new InstanceIdentifier.IdentifiableItem<>(id.getTargetType(), current.getKey())); + new InstanceIdentifier.IdentifiableItem<>(id.getTargetType(), current.key())); } else { return id; } diff --git a/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/registry/SubtreeWriter.java b/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/registry/SubtreeWriter.java index e510bc33c..bdda21611 100644 --- a/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/registry/SubtreeWriter.java +++ b/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/registry/SubtreeWriter.java @@ -24,6 +24,7 @@ import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.honeycomb.translate.write.Writer; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -99,7 +100,20 @@ final class SubtreeWriter<D extends DataObject> implements Writer<D> { } return false; } - return handledChildTypes.contains(instanceIdentifier); + return handledChildTypes.parallelStream() + .filter(childIiD -> instanceIdentifier.getTargetType().equals(childIiD.getTargetType())) + .anyMatch(instanceIdentifier1 -> isPathEqual(instanceIdentifier, instanceIdentifier1)); + } + + private boolean isPathEqual(@Nonnull final InstanceIdentifier<?> iid, final InstanceIdentifier<?> childIiD) { + // Verifying path because the same type can be used in several places. + Iterator<InstanceIdentifier.PathArgument> pathArguments = iid.getPathArguments().iterator(); + for (final InstanceIdentifier.PathArgument pathArgument : childIiD.getPathArguments()) { + if (!pathArguments.hasNext() || !pathArgument.getType().equals(pathArguments.next().getType())) { + return false; + } + } + return true; } @Override diff --git a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/read/AbstractListReaderTest.java b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/read/AbstractListReaderTest.java index 5c08ce237..e8d26b660 100644 --- a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/read/AbstractListReaderTest.java +++ b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/read/AbstractListReaderTest.java @@ -131,7 +131,7 @@ public abstract class AbstractListReaderTest { } @Override - public TestingKey getKey() { + public TestingKey key() { return new TestingKey(); } diff --git a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/read/GenericInitListReaderTest.java b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/read/GenericInitListReaderTest.java index f695e66d7..b7fadda6c 100644 --- a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/read/GenericInitListReaderTest.java +++ b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/read/GenericInitListReaderTest.java @@ -24,15 +24,19 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; +import com.google.common.util.concurrent.FluentFuture; +import com.google.common.util.concurrent.Futures; import io.fd.honeycomb.translate.read.InitFailedException; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; import org.junit.Test; import org.mockito.Mock; +import org.mockito.stubbing.Answer; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.yangtools.concepts.Builder; public class GenericInitListReaderTest extends AbstractListReaderTest { @@ -69,12 +73,13 @@ public class GenericInitListReaderTest extends AbstractListReaderTest { final Initialized<TestingData> initialized = Initialized.create(DATA_OBJECT_ID, data); when(getCustomizer().isPresent(any(), any(), any())).thenReturn(true); doReturn(initialized).when(getCustomizer()).init(any(), any(), any()); + when(writeTx.commit()).thenReturn(FluentFuture.from(Futures.immediateFuture(null))); when(broker.newWriteOnlyTransaction()).thenReturn(writeTx); getReader().init(broker, DATA_OBJECT_ID, ctx); verify(writeTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION, DATA_OBJECT_ID, data, true); - verify(writeTx, times(2)).submit(); + verify(writeTx, times(2)).commit(); } @Test(expected = InitFailedException.class) diff --git a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/read/GenericIntReaderTest.java b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/read/GenericIntReaderTest.java index ef3de457f..1d9f5d55b 100644 --- a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/read/GenericIntReaderTest.java +++ b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/read/GenericIntReaderTest.java @@ -22,6 +22,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; +import com.google.common.util.concurrent.FluentFuture; +import com.google.common.util.concurrent.Futures; import io.fd.honeycomb.translate.read.InitFailedException; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; @@ -66,12 +68,13 @@ public class GenericIntReaderTest extends AbstractReaderTest { when(getCustomizer().isPresent(DATA_OBJECT_ID, data, ctx)).thenReturn(true); doReturn(initialized).when(getCustomizer()).init(DATA_OBJECT_ID, data, ctx); + when(writeTx.commit()).thenReturn(FluentFuture.from(Futures.immediateFuture(null))); when(broker.newWriteOnlyTransaction()).thenReturn(writeTx); getReader().init(broker, DATA_OBJECT_ID, ctx); verify(writeTx).merge(LogicalDatastoreType.CONFIGURATION, DATA_OBJECT_ID, data, true); - verify(writeTx).submit(); + verify(writeTx).commit(); } @Test(expected = InitFailedException.class) diff --git a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericListWriterTest.java b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericListWriterTest.java index 20cabc5b4..36ab85eff 100644 --- a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericListWriterTest.java +++ b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericListWriterTest.java @@ -60,8 +60,8 @@ public class GenericListWriterTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); writer = new GenericListWriter<>(DATA_OBJECT_ID, customizer, validator); - when(before.getKey()).thenReturn(beforeKey); - when(after.getKey()).thenReturn(keyAfter); + when(before.key()).thenReturn(beforeKey); + when(after.key()).thenReturn(keyAfter); } @Test diff --git a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/registry/SubtreeWriterTest.java b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/registry/SubtreeWriterTest.java index 65b2f375b..839674fb4 100644 --- a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/registry/SubtreeWriterTest.java +++ b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/registry/SubtreeWriterTest.java @@ -29,6 +29,7 @@ import io.fd.honeycomb.translate.impl.write.NoopWriters.NonDirectUpdateWriterCus import io.fd.honeycomb.translate.impl.write.NoopWriters.ParentImplDirectUpdateWriterCustomizer; import io.fd.honeycomb.translate.util.DataObjects; import io.fd.honeycomb.translate.write.Writer; +import java.io.UncheckedIOException; import java.util.Collections; import java.util.Set; import org.hamcrest.CoreMatchers; @@ -66,15 +67,29 @@ public class SubtreeWriterTest { } @Test + public void testCanHandleChild() throws Exception { + final SubtreeWriter<?> forWriter = createSubtreeWriter(); + + InstanceIdentifier<DataObjects.DataObject4.DataObject41.DataObject411> testIid = InstanceIdentifier.create( + DataObjects.DataObject4.class).child(DataObjects.DataObject4.DataObject41.class).child( + DataObjects.DataObject4.DataObject41.DataObject411.class); + assertTrue(forWriter.canProcess(testIid)); + } + + @Test public void testSubtreeWriterCreation() throws Exception { - final SubtreeWriter<?> forWriter = (SubtreeWriter<?>) SubtreeWriter.createForWriter(Sets.newHashSet( + final SubtreeWriter<?> forWriter = createSubtreeWriter(); + + assertEquals(writer.getManagedDataObjectType(), forWriter.getManagedDataObjectType()); + assertEquals(3, forWriter.getHandledChildTypes().size()); + } + + private SubtreeWriter<?> createSubtreeWriter() { + return (SubtreeWriter<?>) SubtreeWriter.createForWriter(Sets.newHashSet( DataObjects.DataObject4.DataObject41.IID, DataObjects.DataObject4.DataObject41.DataObject411.IID, DataObjects.DataObject4.DataObject42.IID), writer); - - assertEquals(writer.getManagedDataObjectType(), forWriter.getManagedDataObjectType()); - assertEquals(3, forWriter.getHandledChildTypes().size()); } @Test |