summaryrefslogtreecommitdiffstats
path: root/infra/translate-impl/src
diff options
context:
space:
mode:
Diffstat (limited to 'infra/translate-impl/src')
-rw-r--r--infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/GenericListWriter.java4
-rw-r--r--infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/GenericWriter.java24
-rw-r--r--infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistry.java22
-rw-r--r--infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/registry/SubtreeWriter.java9
-rw-r--r--infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericListWriterTest.java6
-rw-r--r--infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericWriterTest.java15
-rw-r--r--infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/NoopWriters.java63
-rw-r--r--infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistryBuilderTest.java6
-rw-r--r--infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistryTest.java60
-rw-r--r--infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/registry/SubtreeWriterTest.java31
10 files changed, 190 insertions, 50 deletions
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 4e05ce018..6fbef8e84 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
@@ -16,6 +16,8 @@
package io.fd.honeycomb.translate.impl.write;
+import static io.fd.honeycomb.translate.impl.write.GenericWriter.isUpdateSupported;
+
import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
import io.fd.honeycomb.translate.util.RWUtils;
import io.fd.honeycomb.translate.util.write.AbstractGenericWriter;
@@ -39,7 +41,7 @@ public final class GenericListWriter<D extends DataObject & Identifiable<K>, K e
public GenericListWriter(@Nonnull final InstanceIdentifier<D> type,
@Nonnull final ListWriterCustomizer<D, K> customizer) {
- super(type);
+ super(type, isUpdateSupported(customizer));
this.customizer = customizer;
}
diff --git a/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/GenericWriter.java b/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/GenericWriter.java
index 30d15e370..086936e38 100644
--- a/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/GenericWriter.java
+++ b/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/GenericWriter.java
@@ -23,18 +23,40 @@ import io.fd.honeycomb.translate.write.WriteFailedException;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Generic writer with customizable behavior thanks to injected customizer.
*/
public final class GenericWriter<D extends DataObject> extends AbstractGenericWriter<D> {
+ private static final Logger LOG = LoggerFactory.getLogger(GenericWriter.class);
+ private static final String UPDATE_M = "updateCurrentAttributes";
private final WriterCustomizer<D> customizer;
public GenericWriter(@Nonnull final InstanceIdentifier<D> type,
@Nonnull final WriterCustomizer<D> customizer) {
- super(type);
+ super(type, isUpdateSupported(customizer));
this.customizer = customizer;
+
+ }
+
+ static boolean isUpdateSupported(final @Nonnull WriterCustomizer<?> customizer) {
+ try {
+ // if customizer overrides updateCurrentAttributes method, it will be used, otherwise updates will be broken into individual
+ // delete + create pairs
+ final Class<? extends WriterCustomizer> customizerClass = customizer.getClass();
+ final Class<?> updateDeclaringClass = customizerClass
+ .getMethod(UPDATE_M, InstanceIdentifier.class, DataObject.class, DataObject.class, WriteContext.class)
+ .getDeclaringClass();
+ final boolean supportsUpdate = !WriterCustomizer.class.equals(updateDeclaringClass);
+ LOG.debug("Customizer {} update support : {}|Update declaring class {}", customizerClass, supportsUpdate,
+ updateDeclaringClass);
+ return supportsUpdate;
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException("Unable to detect if customizer supports update", e);
+ }
}
@Override
diff --git a/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistry.java b/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistry.java
index 418f4b4b7..e21297aa3 100644
--- a/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistry.java
+++ b/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistry.java
@@ -92,8 +92,8 @@ final class FlatWriterRegistry implements WriterRegistry {
}
@Override
- public void update(@Nonnull final DataObjectUpdates updates,
- @Nonnull final WriteContext ctx) throws TranslationException {
+ public void processModifications(@Nonnull final DataObjectUpdates updates,
+ @Nonnull final WriteContext ctx) throws TranslationException {
if (updates.isEmpty()) {
return;
}
@@ -115,6 +115,17 @@ final class FlatWriterRegistry implements WriterRegistry {
LOG.trace("Update successful for: {}", updates);
}
+ @Override
+ public boolean writerSupportsUpdate(@Nonnull final InstanceIdentifier<?> type) {
+ Writer writer = getWriter(type);
+
+ if(writer == null){
+ writer = getSubtreeWriterResponsible(type);
+ }
+
+ return checkNotNull(writer, "Unable to find writer for %s", type).supportsDirectUpdate();
+ }
+
private void singleUpdate(@Nonnull final Multimap<InstanceIdentifier<?>, ? extends DataObjectUpdate> updates,
@Nonnull final WriteContext ctx) throws WriteFailedException {
if (updates.isEmpty()) {
@@ -136,16 +147,17 @@ final class FlatWriterRegistry implements WriterRegistry {
LOG.trace("Performing single type update with writer: {}", writer);
for (DataObjectUpdate singleUpdate : singleTypeUpdates) {
- writer.update(singleUpdate.getId(), singleUpdate.getDataBefore(), singleUpdate.getDataAfter(), ctx);
+ writer.processModification(singleUpdate.getId(), singleUpdate.getDataBefore(), singleUpdate.getDataAfter(), ctx);
}
}
+ @Nullable
private Writer<?> getSubtreeWriterResponsible(final InstanceIdentifier<?> singleType) {
return writers.values().stream()
.filter(w -> w instanceof SubtreeWriter)
.filter(w -> ((SubtreeWriter<?>) w).getHandledChildTypes().contains(singleType))
.findFirst()
- .get();
+ .orElse(null);
}
private Collection<DataObjectUpdate> getParentDataObjectUpdate(final WriteContext ctx,
@@ -208,7 +220,7 @@ final class FlatWriterRegistry implements WriterRegistry {
for (DataObjectUpdate singleUpdate : writersData) {
try {
- writer.update(singleUpdate.getId(), singleUpdate.getDataBefore(), singleUpdate.getDataAfter(), ctx);
+ writer.processModification(singleUpdate.getId(), singleUpdate.getDataBefore(), singleUpdate.getDataAfter(), ctx);
processedNodes.add(singleUpdate.getId());
LOG.trace("Update successful for type: {}", writerType);
LOG.debug("Update successful for: {}", singleUpdate);
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 fc6ecc67e..b2a571b40 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
@@ -62,11 +62,16 @@ final class SubtreeWriter<D extends DataObject> implements Writer<D> {
}
@Override
- public void update(
+ public void processModification(
@Nonnull final InstanceIdentifier<? extends DataObject> id,
@Nullable final DataObject dataBefore,
@Nullable final DataObject dataAfter, @Nonnull final WriteContext ctx) throws WriteFailedException {
- delegate.update(id, dataBefore, dataAfter, ctx);
+ delegate.processModification(id, dataBefore, dataAfter, ctx);
+ }
+
+ @Override
+ public boolean supportsDirectUpdate() {
+ return delegate.supportsDirectUpdate();
}
@Override
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 2f50ece79..91785b25e 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
@@ -71,13 +71,13 @@ public class GenericListWriterTest {
(InstanceIdentifier<IdentifiableDataObject>) InstanceIdentifier.create(Collections
.singleton(new InstanceIdentifier.IdentifiableItem<>(IdentifiableDataObject.class, keyAfter)));
- writer.update(DATA_OBJECT_ID, before, after, ctx);
+ writer.processModification(DATA_OBJECT_ID, before, after, ctx);
verify(customizer).updateCurrentAttributes(keyedIdBefore, before, after, ctx);
- writer.update(DATA_OBJECT_ID, before, null, ctx);
+ writer.processModification(DATA_OBJECT_ID, before, null, ctx);
verify(customizer).deleteCurrentAttributes(keyedIdBefore, before, ctx);
- writer.update(DATA_OBJECT_ID, null, after, ctx);
+ writer.processModification(DATA_OBJECT_ID, null, after, ctx);
verify(customizer).writeCurrentAttributes(keyedIdAfter, after, ctx);
}
diff --git a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericWriterTest.java b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericWriterTest.java
index 3caea571e..c9d381ad4 100644
--- a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericWriterTest.java
+++ b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericWriterTest.java
@@ -17,6 +17,8 @@
package io.fd.honeycomb.translate.impl.write;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.verify;
@@ -53,13 +55,13 @@ public class GenericWriterTest {
@Test
public void testUpdate() throws Exception {
assertEquals(DATA_OBJECT_ID, writer.getManagedDataObjectType());
- writer.update(DATA_OBJECT_ID, before, after, ctx);
+ writer.processModification(DATA_OBJECT_ID, before, after, ctx);
verify(customizer).updateCurrentAttributes(DATA_OBJECT_ID, before, after, ctx);
- writer.update(DATA_OBJECT_ID, before, null, ctx);
+ writer.processModification(DATA_OBJECT_ID, before, null, ctx);
verify(customizer).deleteCurrentAttributes(DATA_OBJECT_ID, before, ctx);
- writer.update(DATA_OBJECT_ID, null, after, ctx);
+ writer.processModification(DATA_OBJECT_ID, null, after, ctx);
verify(customizer).writeCurrentAttributes(DATA_OBJECT_ID, after, ctx);
}
@@ -85,4 +87,11 @@ public class GenericWriterTest {
writer = new GenericWriter<>(DATA_OBJECT_ID, customizer);
writer.deleteCurrentAttributes(DATA_OBJECT_ID, before, ctx);
}
+
+ @Test
+ public void testUpdateSupported() {
+ assertFalse(GenericWriter.isUpdateSupported(new NoopWriters.NonDirectUpdateWriterCustomizer()));
+ assertTrue(GenericWriter.isUpdateSupported(new NoopWriters.DirectUpdateWriterCustomizer()));
+ assertTrue(GenericWriter.isUpdateSupported(new NoopWriters.ParentImplDirectUpdateWriterCustomizer()));
+ }
} \ No newline at end of file
diff --git a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/NoopWriters.java b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/NoopWriters.java
new file mode 100644
index 000000000..8ea91d282
--- /dev/null
+++ b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/NoopWriters.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.translate.impl.write;
+
+import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public final class NoopWriters {
+
+ private NoopWriters() {
+ }
+
+ public static class NonDirectUpdateWriterCustomizer implements WriterCustomizer<DataObject> {
+
+ @Override
+ public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<DataObject> id,
+ @Nonnull final DataObject dataAfter,
+ @Nonnull final WriteContext writeContext)
+ throws WriteFailedException {
+ // NOOP
+ }
+
+ @Override
+ public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<DataObject> id,
+ @Nonnull final DataObject dataBefore,
+ @Nonnull final WriteContext writeContext)
+ throws WriteFailedException {
+ // NOOP
+ }
+ }
+
+ public static class DirectUpdateWriterCustomizer extends NonDirectUpdateWriterCustomizer {
+
+ @Override
+ public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<DataObject> id,
+ @Nonnull final DataObject dataBefore, @Nonnull final DataObject dataAfter,
+ @Nonnull final WriteContext writeContext) throws WriteFailedException {
+ // is direct support
+ }
+ }
+
+ public static class ParentImplDirectUpdateWriterCustomizer extends DirectUpdateWriterCustomizer {
+ // parent impls directly
+ }
+}
diff --git a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistryBuilderTest.java b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistryBuilderTest.java
index feaba726c..dd1adb368 100644
--- a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistryBuilderTest.java
+++ b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistryBuilderTest.java
@@ -87,9 +87,9 @@ public class FlatWriterRegistryBuilderTest {
Multimaps.forMap(Collections.singletonMap(id, update)),
Multimaps.forMap(Collections.emptyMap()));
final WriteContext ctx = mock(WriteContext.class);
- build.update(updates, ctx);
+ build.processModifications(updates, ctx);
- verify(writer).update(id, before, after, ctx);
+ verify(writer).processModification(id, before, after, ctx);
}
@Test(expected = IllegalArgumentException.class)
@@ -104,7 +104,7 @@ public class FlatWriterRegistryBuilderTest {
final WriterRegistry.DataObjectUpdates updates = new WriterRegistry.DataObjectUpdates(
Multimaps.forMap(Collections.singletonMap(id2, update2)),
Multimaps.forMap(Collections.emptyMap()));
- build.update(updates, mock(WriteContext.class));
+ build.processModifications(updates, mock(WriteContext.class));
}
@Test
diff --git a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistryTest.java b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistryTest.java
index f66ab8f90..72a91cb00 100644
--- a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistryTest.java
+++ b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistryTest.java
@@ -84,10 +84,10 @@ public class FlatWriterRegistryTest {
final DataObject1 dataObject = mock(DataObject1.class);
updates.put(DataObject1.IID, DataObjectUpdate.create(iid, dataObject, dataObject));
updates.put(DataObject1.IID, DataObjectUpdate.create(iid2, dataObject, dataObject));
- flatWriterRegistry.update(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
+ flatWriterRegistry.processModifications(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
- verify(writer1).update(iid, dataObject, dataObject, ctx);
- verify(writer1).update(iid2, dataObject, dataObject, ctx);
+ verify(writer1).processModification(iid, dataObject, dataObject, ctx);
+ verify(writer1).processModification(iid2, dataObject, dataObject, ctx);
// Invoked when registry is being created
verifyNoMoreInteractions(writer1);
verifyZeroInteractions(writer2);
@@ -105,11 +105,11 @@ public class FlatWriterRegistryTest {
final InstanceIdentifier<DataObject2> iid2 = InstanceIdentifier.create(DataObject2.class);
final DataObject2 dataObject2 = mock(DataObject2.class);
updates.put(DataObject2.IID, DataObjectUpdate.create(iid2, dataObject2, dataObject2));
- flatWriterRegistry.update(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
+ flatWriterRegistry.processModifications(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
final InOrder inOrder = inOrder(writer1, writer2);
- inOrder.verify(writer1).update(iid, dataObject, dataObject, ctx);
- inOrder.verify(writer2).update(iid2, dataObject2, dataObject2, ctx);
+ inOrder.verify(writer1).processModification(iid, dataObject, dataObject, ctx);
+ inOrder.verify(writer2).processModification(iid2, dataObject2, dataObject2, ctx);
verifyNoMoreInteractions(writer1);
verifyNoMoreInteractions(writer2);
@@ -128,12 +128,12 @@ public class FlatWriterRegistryTest {
final DataObject2 dataObject2 = mock(DataObject2.class);
deletes.put(
DataObject2.IID, ((DataObjectUpdate.DataObjectDelete) DataObjectUpdate.create(iid2, dataObject2, null)));
- flatWriterRegistry.update(new WriterRegistry.DataObjectUpdates(ImmutableMultimap.of(), deletes), ctx);
+ flatWriterRegistry.processModifications(new WriterRegistry.DataObjectUpdates(ImmutableMultimap.of(), deletes), ctx);
final InOrder inOrder = inOrder(writer1, writer2);
// Reversed order of invocation, first writer2 and then writer1
- inOrder.verify(writer2).update(iid2, dataObject2, null, ctx);
- inOrder.verify(writer1).update(iid, dataObject, null, ctx);
+ inOrder.verify(writer2).processModification(iid2, dataObject2, null, ctx);
+ inOrder.verify(writer1).processModification(iid, dataObject, null, ctx);
verifyNoMoreInteractions(writer1);
verifyNoMoreInteractions(writer2);
@@ -159,15 +159,15 @@ public class FlatWriterRegistryTest {
DataObject2.IID, ((DataObjectUpdate.DataObjectDelete) DataObjectUpdate.create(iid2, dataObject2, null)));
// Writer 2 update
updates.put(DataObject2.IID, DataObjectUpdate.create(iid2, dataObject2, dataObject2));
- flatWriterRegistry.update(new WriterRegistry.DataObjectUpdates(updates, deletes), ctx);
+ flatWriterRegistry.processModifications(new WriterRegistry.DataObjectUpdates(updates, deletes), ctx);
final InOrder inOrder = inOrder(writer1, writer2);
// Reversed order of invocation, first writer2 and then writer1 for deletes
- inOrder.verify(writer2).update(iid2, dataObject2, null, ctx);
- inOrder.verify(writer1).update(iid, dataObject, null, ctx);
+ inOrder.verify(writer2).processModification(iid2, dataObject2, null, ctx);
+ inOrder.verify(writer1).processModification(iid, dataObject, null, ctx);
// Then also updates are processed
- inOrder.verify(writer1).update(iid, dataObject, dataObject, ctx);
- inOrder.verify(writer2).update(iid2, dataObject2, dataObject2, ctx);
+ inOrder.verify(writer1).processModification(iid, dataObject, dataObject, ctx);
+ inOrder.verify(writer2).processModification(iid2, dataObject2, dataObject2, ctx);
verifyNoMoreInteractions(writer1);
verifyNoMoreInteractions(writer2);
@@ -181,7 +181,7 @@ public class FlatWriterRegistryTest {
final Multimap<InstanceIdentifier<?>, DataObjectUpdate> updates = HashMultimap.create();
addUpdate(updates, DataObject1.class);
addUpdate(updates, DataObject2.class);
- flatWriterRegistry.update(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
+ flatWriterRegistry.processModifications(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
}
@Test
@@ -191,14 +191,14 @@ public class FlatWriterRegistryTest {
// Writer1 always fails
doThrow(new RuntimeException()).when(writer1)
- .update(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), any(WriteContext.class));
+ .processModification(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), any(WriteContext.class));
final Multimap<InstanceIdentifier<?>, DataObjectUpdate> updates = HashMultimap.create();
addUpdate(updates, DataObject1.class);
addUpdate(updates, DataObject2.class);
try {
- flatWriterRegistry.update(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
+ flatWriterRegistry.processModifications(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
fail("Bulk update should have failed on writer1");
} catch (WriterRegistry.BulkUpdateException e) {
assertThat(e.getUnrevertedSubtrees(), hasSize(2));
@@ -215,7 +215,7 @@ public class FlatWriterRegistryTest {
// Writer1 always fails
doThrow(new RuntimeException()).when(writer3)
- .update(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), any(WriteContext.class));
+ .processModification(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), any(WriteContext.class));
final Multimap<InstanceIdentifier<?>, DataObjectUpdate> updates = HashMultimap.create();
addUpdate(updates, DataObject1.class);
@@ -226,26 +226,26 @@ public class FlatWriterRegistryTest {
updates.put(DataObject2.IID, DataObjectUpdate.create(iid2, before2, after2));
try {
- flatWriterRegistry.update(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
+ flatWriterRegistry.processModifications(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
fail("Bulk update should have failed on writer1");
} catch (WriterRegistry.BulkUpdateException e) {
assertThat(e.getUnrevertedSubtrees().size(), is(1));
final InOrder inOrder = inOrder(writer1, writer2, writer3);
inOrder.verify(writer1)
- .update(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), any(WriteContext.class));
+ .processModification(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), any(WriteContext.class));
inOrder.verify(writer2)
- .update(iid2, before2, after2, ctx);
+ .processModification(iid2, before2, after2, ctx);
inOrder.verify(writer3)
- .update(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), any(WriteContext.class));
+ .processModification(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), any(WriteContext.class));
e.revertChanges(revertWriteContext);
// Revert changes. Successful updates are iterated in reverse
// also binding other write context,to verify if update context is not reused
inOrder.verify(writer2)
- .update(iid2, after2, before2, revertWriteContext);
+ .processModification(iid2, after2, before2, revertWriteContext);
inOrder.verify(writer1)
- .update(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), eq(revertWriteContext));
+ .processModification(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), eq(revertWriteContext));
verifyNoMoreInteractions(writer3);
}
}
@@ -258,7 +258,7 @@ public class FlatWriterRegistryTest {
// Writer1 always fails
doThrow(new RuntimeException()).when(writer3)
- .update(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), any(WriteContext.class));
+ .processModification(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), any(WriteContext.class));
final Multimap<InstanceIdentifier<?>, DataObjectUpdate> updates = HashMultimap.create();
addUpdate(updates, DataObject1.class);
@@ -266,12 +266,12 @@ public class FlatWriterRegistryTest {
addUpdate(updates, DataObjects.DataObject3.class);
try {
- flatWriterRegistry.update(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
+ flatWriterRegistry.processModifications(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
fail("Bulk update should have failed on writer1");
} catch (WriterRegistry.BulkUpdateException e) {
// Writer1 always fails from now
doThrow(new RuntimeException()).when(writer1)
- .update(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), any(WriteContext.class));
+ .processModification(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), any(WriteContext.class));
try {
e.revertChanges(revertWriteContext);
} catch (WriterRegistry.Reverter.RevertFailedException e1) {
@@ -293,19 +293,19 @@ public class FlatWriterRegistryTest {
// Writer1 always fails
doThrow(new RuntimeException()).when(writer1)
- .update(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class),
+ .processModification(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class),
any(WriteContext.class));
final Multimap<InstanceIdentifier<?>, DataObjectUpdate> updates = HashMultimap.create();
addKeyedUpdate(updates,DataObjects.DataObject1ChildK.class);
addUpdate(updates, DataObject1.class);
try {
- flatWriterRegistry.update(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
+ flatWriterRegistry.processModifications(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
fail("Bulk update should have failed on writer1");
} catch (WriterRegistry.BulkUpdateException e) {
// Writer1 always fails from now
doThrow(new RuntimeException()).when(writer1)
- .update(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class),
+ .processModification(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class),
any(WriteContext.class));
try {
e.revertChanges(revertWriteContext);
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 ff2f83158..65b2f375b 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
@@ -16,15 +16,21 @@
package io.fd.honeycomb.translate.impl.write.registry;
-import static org.hamcrest.CoreMatchers.hasItem;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import com.google.common.collect.Sets;
+import io.fd.honeycomb.translate.impl.write.GenericWriter;
+import io.fd.honeycomb.translate.impl.write.NoopWriters.DirectUpdateWriterCustomizer;
+import io.fd.honeycomb.translate.impl.write.NoopWriters.NonDirectUpdateWriterCustomizer;
+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.util.Collections;
+import java.util.Set;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
@@ -79,7 +85,28 @@ public class SubtreeWriterTest {
assertEquals(writer.getManagedDataObjectType(), forWriter.getManagedDataObjectType());
assertEquals(1, forWriter.getHandledChildTypes().size());
- assertThat(forWriter.getHandledChildTypes(), CoreMatchers.hasItem(DataObjects.DataObject4.DataObject41.DataObject411.IID));
+ assertThat(forWriter.getHandledChildTypes(),
+ CoreMatchers.hasItem(DataObjects.DataObject4.DataObject41.DataObject411.IID));
+ }
+
+ @Test
+ public void testUpdateSupported() {
+ // test supportsDirectUpdate(), because subtree writer overrides this method and delegate call on delegate writer
+ final InstanceIdentifier<DataObject> fakeIID = InstanceIdentifier.create(DataObject.class);
+ final Set<InstanceIdentifier<?>> handledChildren = Collections.emptySet();
+
+ final NonDirectUpdateWriterCustomizer nonDirectCustomizer = new NonDirectUpdateWriterCustomizer();
+ final DirectUpdateWriterCustomizer directCustomizer = new DirectUpdateWriterCustomizer();
+ final ParentImplDirectUpdateWriterCustomizer parentImplCustomizer =
+ new ParentImplDirectUpdateWriterCustomizer();
+
+ final GenericWriter<DataObject> nonDirectWriter = new GenericWriter<>(fakeIID, nonDirectCustomizer);
+ final GenericWriter<DataObject> directWriter = new GenericWriter<>(fakeIID, directCustomizer);
+ final GenericWriter<DataObject> parentImplWriter = new GenericWriter<>(fakeIID, parentImplCustomizer);
+
+ assertFalse(SubtreeWriter.createForWriter(handledChildren, nonDirectWriter).supportsDirectUpdate());
+ assertTrue(SubtreeWriter.createForWriter(handledChildren, directWriter).supportsDirectUpdate());
+ assertTrue(SubtreeWriter.createForWriter(handledChildren, parentImplWriter).supportsDirectUpdate());
}
} \ No newline at end of file