summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-11-09 09:44:26 +0100
committerMarek Gradzki <mgradzki@cisco.com>2016-11-23 13:03:57 +0000
commit567247ad5a1ba1c8aff3cb2b47211f7c68f0545d (patch)
treeeca23e838a6b1c7e69838b617e25762de1e2170e
parent8e0c7007906730fe4547b0265a895ad8a322a7dc (diff)
HONEYCOMB-170 Add more information to RevertFailedEx
Change-Id: I6b24a1d061c94d57730b20cde4c5b3c39444b119 Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegator.java5
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModificationDiff.java2
-rw-r--r--infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorTest.java14
-rw-r--r--infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/WriterRegistry.java53
-rw-r--r--infra/translate-api/src/test/java/io/fd/honeycomb/translate/write/registry/BulkUpdateExceptionTest.java11
-rw-r--r--infra/translate-api/src/test/java/io/fd/honeycomb/translate/write/registry/RevertFailedExceptionTest.java19
-rw-r--r--infra/translate-impl/pom.xml5
-rw-r--r--infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistry.java4
-rw-r--r--infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/registry/FlatWriterRegistryTest.java120
9 files changed, 142 insertions, 91 deletions
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegator.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegator.java
index 3de9131c0..f4989aa37 100644
--- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegator.java
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegator.java
@@ -146,13 +146,14 @@ public final class ModifiableDataTreeDelegator extends ModifiableDataTreeManager
LOG.info("Changes successfully reverted");
} catch (WriterRegistry.Reverter.RevertFailedException revertFailedException) {
// fail with failed revert
- LOG.error("Failed to revert successful changes", revertFailedException);
+ LOG.error("Failed to revert successful(comitted) changes, failure occurred for: {}. State might be corrupted.",
+ revertFailedException.getFailedUpdate(), revertFailedException);
throw revertFailedException;
}
// fail with success revert
// not passing the cause,its logged above and it would be logged after transaction
// ended again(prevent double logging of same error
- throw new WriterRegistry.Reverter.RevertSuccessException(e.getFailedIds());
+ throw new WriterRegistry.Reverter.RevertSuccessException(e.getUnrevertedSubtrees());
} catch (TransactionCommitFailedException e) {
// TODO HONEYCOMB-162 revert should probably occur when context is not written successfully
final String msg = "Error while updating mapping context data";
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModificationDiff.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModificationDiff.java
index 723bb88ad..f999ba1ee 100644
--- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModificationDiff.java
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModificationDiff.java
@@ -246,7 +246,7 @@ final class ModificationDiff {
final com.google.common.base.Optional<NormalizedNode<?, ?>> afterData =
modification.getDataAfter();
checkArgument(beforeData.isPresent() || afterData.isPresent(),
- "Both before and after data are null for $s", modification.getId());
+ "Both before and after data are null for %s", modification.getId());
return NormalizedNodeUpdate.create(modification.getId(), beforeData.orNull(), afterData.orNull());
}
diff --git a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorTest.java b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorTest.java
index 322328508..26a936f23 100644
--- a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorTest.java
+++ b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorTest.java
@@ -82,6 +82,7 @@ public class ModifiableDataTreeDelegatorTest {
private ArgumentCaptor<WriteContext> writeContextCaptor;
private ModifiableDataTreeManager configDataTree;
+ private final DataObjectUpdate update = DataObjectUpdate.create(DEFAULT_ID, null, DEFAULT_DATA_OBJECT);
static final InstanceIdentifier<?> DEFAULT_ID = InstanceIdentifier.create(DataObject.class);
static DataObject DEFAULT_DATA_OBJECT = mockDataObject("serialized", DataObject.class);
@@ -145,7 +146,7 @@ public class ModifiableDataTreeDelegatorTest {
// Fail on update:
final WriterRegistry.Reverter reverter = mock(WriterRegistry.Reverter.class);
final TranslationException failedOnUpdateException = new TranslationException("update failed");
- doThrow(new WriterRegistry.BulkUpdateException(Collections.singleton(DEFAULT_ID), reverter, failedOnUpdateException))
+ doThrow(new WriterRegistry.BulkUpdateException(DEFAULT_ID, update, Collections.singleton(DEFAULT_ID), reverter, failedOnUpdateException))
.when(writer).update(any(WriterRegistry.DataObjectUpdates.class), any(WriteContext.class));
try {
@@ -169,12 +170,13 @@ public class ModifiableDataTreeDelegatorTest {
// Fail on update:
final WriterRegistry.Reverter reverter = mock(WriterRegistry.Reverter.class);
final TranslationException failedOnUpdateException = new TranslationException("update failed");
- doThrow(new WriterRegistry.BulkUpdateException(Collections.singleton(DEFAULT_ID), reverter, failedOnUpdateException))
- .when(writer).update(any(WriterRegistry.DataObjectUpdates.class), any(WriteContext.class));
+ final WriterRegistry.BulkUpdateException bulkFailEx =
+ new WriterRegistry.BulkUpdateException(DEFAULT_ID, update, Collections.singleton(DEFAULT_ID), reverter,
+ failedOnUpdateException);
+ doThrow(bulkFailEx).when(writer).update(any(WriterRegistry.DataObjectUpdates.class), any(WriteContext.class));
// Fail on revert:
- final TranslationException failedOnRevertException = new TranslationException("revert failed");
- doThrow(new WriterRegistry.Reverter.RevertFailedException(Collections.emptySet(), failedOnRevertException))
+ doThrow(new WriterRegistry.Reverter.RevertFailedException(bulkFailEx))
.when(reverter).revert(any(WriteContext.class));
try {
@@ -187,7 +189,7 @@ public class ModifiableDataTreeDelegatorTest {
} catch (WriterRegistry.Reverter.RevertFailedException e) {
verify(writer).update(any(WriterRegistry.DataObjectUpdates.class), any(WriteContext.class));
verify(reverter).revert(any(WriteContext.class));
- assertEquals(failedOnRevertException, e.getCause());
+ assertEquals(bulkFailEx, e.getCause());
}
}
diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/WriterRegistry.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/WriterRegistry.java
index 51e6415a2..5520c00ec 100644
--- a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/WriterRegistry.java
+++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/registry/WriterRegistry.java
@@ -19,7 +19,6 @@ package io.fd.honeycomb.translate.write.registry;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.Beta;
-import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import io.fd.honeycomb.translate.TranslationException;
@@ -134,18 +133,24 @@ public interface WriterRegistry {
class BulkUpdateException extends TranslationException {
private final transient Reverter reverter;
- private final Set<InstanceIdentifier<?>> failedIds;
+ private final InstanceIdentifier<?> failedSubtree;
+ private final DataObjectUpdate failedData;
+ private final Set<InstanceIdentifier<?>> unrevertedSubtrees;
/**
* Constructs an BulkUpdateException.
- * @param failedIds instance identifiers of the data objects that were not processed during bulk update.
+ * @param unhandledSubtrees instance identifiers of the data objects that were not processed during bulk update.
* @param cause the cause of bulk update failure
*/
- public BulkUpdateException(@Nonnull final Set<InstanceIdentifier<?>> failedIds,
+ public BulkUpdateException(@Nonnull final InstanceIdentifier<?> failedSubtree,
+ @Nonnull final DataObjectUpdate failedData,
+ @Nonnull final Set<InstanceIdentifier<?>> unhandledSubtrees,
@Nonnull final Reverter reverter,
@Nonnull final Throwable cause) {
- super("Bulk update failed at: " + failedIds, cause);
- this.failedIds = failedIds;
+ super("Bulk update failed at: " + failedSubtree + " ignored updates: " + unhandledSubtrees, cause);
+ this.failedSubtree = failedSubtree;
+ this.failedData = failedData;
+ this.unrevertedSubtrees = unhandledSubtrees;
this.reverter = checkNotNull(reverter, "reverter should not be null");
}
@@ -160,8 +165,16 @@ public interface WriterRegistry {
reverter.revert(writeContext);
}
- public Set<InstanceIdentifier<?>> getFailedIds() {
- return failedIds;
+ public Set<InstanceIdentifier<?>> getUnrevertedSubtrees() {
+ return unrevertedSubtrees;
+ }
+
+ public InstanceIdentifier<?> getFailedSubtree() {
+ return failedSubtree;
+ }
+
+ public DataObjectUpdate getFailedData() {
+ return failedData;
}
}
@@ -188,20 +201,14 @@ public interface WriterRegistry {
@Beta
class RevertFailedException extends TranslationException {
- // TODO HONEYCOMB-170 change to list of VppDataModifications to make debugging easier
- private final Set<InstanceIdentifier<?>> notRevertedChanges;
-
/**
* Constructs a RevertFailedException with the list of changes that were not reverted.
*
- * @param notRevertedChanges list of changes that were not reverted
* @param cause the cause of revert failure
*/
- public RevertFailedException(@Nonnull final Set<InstanceIdentifier<?>> notRevertedChanges,
- final Throwable cause) {
- super(cause);
- checkNotNull(notRevertedChanges, "notRevertedChanges should not be null");
- this.notRevertedChanges = ImmutableSet.copyOf(notRevertedChanges);
+ public RevertFailedException(@Nonnull final BulkUpdateException cause) {
+ super("Unable to revert changes after failure. Revert failed for "
+ + cause.getFailedSubtree() + " unreverted subtrees: " + cause.getUnrevertedSubtrees(), cause);
}
/**
@@ -211,7 +218,17 @@ public interface WriterRegistry {
*/
@Nonnull
public Set<InstanceIdentifier<?>> getNotRevertedChanges() {
- return notRevertedChanges;
+ return ((BulkUpdateException) getCause()).getUnrevertedSubtrees();
+ }
+
+ /**
+ * Returns the update that caused the failure.
+ *
+ * @return update that caused the failure
+ */
+ @Nonnull
+ public DataObjectUpdate getFailedUpdate() {
+ return ((BulkUpdateException) getCause()).getFailedData();
}
}
diff --git a/infra/translate-api/src/test/java/io/fd/honeycomb/translate/write/registry/BulkUpdateExceptionTest.java b/infra/translate-api/src/test/java/io/fd/honeycomb/translate/write/registry/BulkUpdateExceptionTest.java
index ae0c36d5b..9623db5bc 100644
--- a/infra/translate-api/src/test/java/io/fd/honeycomb/translate/write/registry/BulkUpdateExceptionTest.java
+++ b/infra/translate-api/src/test/java/io/fd/honeycomb/translate/write/registry/BulkUpdateExceptionTest.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import com.google.common.collect.Sets;
+import io.fd.honeycomb.translate.write.DataObjectUpdate;
import io.fd.honeycomb.translate.write.WriteContext;
import java.util.HashSet;
import org.junit.Before;
@@ -35,9 +36,12 @@ public class BulkUpdateExceptionTest {
@Mock
private WriteContext writeContext;
-
@Mock
private WriterRegistry.Reverter reverter;
+ @Mock
+ private DataObject before;
+ @Mock
+ private DataObject after;
@Before
public void setUp() throws Exception {
@@ -48,9 +52,10 @@ public class BulkUpdateExceptionTest {
public void testRevert() throws Exception {
final HashSet<InstanceIdentifier<?>> failedIds = Sets.newHashSet(id);
final WriterRegistry.BulkUpdateException bulkUpdateException =
- new WriterRegistry.BulkUpdateException(failedIds, reverter, new RuntimeException());
+ new WriterRegistry.BulkUpdateException(id, DataObjectUpdate.create(id, before, after),
+ failedIds, reverter, new RuntimeException());
- assertEquals(failedIds, bulkUpdateException.getFailedIds());
+ assertEquals(failedIds, bulkUpdateException.getUnrevertedSubtrees());
bulkUpdateException.revertChanges(writeContext);
verify(reverter).revert(writeContext);
diff --git a/infra/translate-api/src/test/java/io/fd/honeycomb/translate/write/registry/RevertFailedExceptionTest.java b/infra/translate-api/src/test/java/io/fd/honeycomb/translate/write/registry/RevertFailedExceptionTest.java
index 721941d1e..6502235d0 100644
--- a/infra/translate-api/src/test/java/io/fd/honeycomb/translate/write/registry/RevertFailedExceptionTest.java
+++ b/infra/translate-api/src/test/java/io/fd/honeycomb/translate/write/registry/RevertFailedExceptionTest.java
@@ -19,20 +19,37 @@ package io.fd.honeycomb.translate.write.registry;
import static org.junit.Assert.assertEquals;
import com.google.common.collect.Sets;
+import io.fd.honeycomb.translate.write.DataObjectUpdate;
import java.util.Set;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public class RevertFailedExceptionTest {
private InstanceIdentifier<?> id = InstanceIdentifier.create(DataObject.class);
+ @Mock
+ private WriterRegistry.Reverter reverter;
+ @Mock
+ private DataObject before;
+ @Mock
+ private DataObject after;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
@Test
public void testNonRevert() throws Exception {
final Set<InstanceIdentifier<?>> notReverted = Sets.newHashSet(id);
final WriterRegistry.Reverter.RevertFailedException revertFailedException =
- new WriterRegistry.Reverter.RevertFailedException(notReverted, new RuntimeException());
+ new WriterRegistry.Reverter.RevertFailedException(
+ new WriterRegistry.BulkUpdateException(id, DataObjectUpdate.create(id, before, after),
+ notReverted, reverter, new RuntimeException()));
assertEquals(notReverted, revertFailedException.getNotRevertedChanges());
}
} \ No newline at end of file
diff --git a/infra/translate-impl/pom.xml b/infra/translate-impl/pom.xml
index b431c07f9..ca74d3b20 100644
--- a/infra/translate-impl/pom.xml
+++ b/infra/translate-impl/pom.xml
@@ -64,6 +64,11 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
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 990431a15..418f4b4b7 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
@@ -224,7 +224,7 @@ final class FlatWriterRegistry implements WriterRegistry {
.map(DataObjectUpdate::getId)
.filter(id -> !processedNodes.contains(id))
.collect(Collectors.toSet());
- throw new BulkUpdateException(unprocessedChanges, reverter, e);
+ throw new BulkUpdateException(writerType, singleUpdate, unprocessedChanges, reverter, e);
}
}
}
@@ -286,7 +286,7 @@ final class FlatWriterRegistry implements WriterRegistry {
LOG.info("Revert successful");
} catch (BulkUpdateException e) {
LOG.error("Revert failed", e);
- throw new RevertFailedException(e.getFailedIds(), e);
+ throw new RevertFailedException(e);
}
}
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 65742df33..f66ab8f90 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
@@ -16,7 +16,9 @@
package io.fd.honeycomb.translate.impl.write.registry;
+import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
@@ -35,11 +37,11 @@ import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import io.fd.honeycomb.translate.util.DataObjects;
import io.fd.honeycomb.translate.util.DataObjects.DataObject1;
+import io.fd.honeycomb.translate.util.DataObjects.DataObject2;
import io.fd.honeycomb.translate.write.DataObjectUpdate;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.Writer;
import io.fd.honeycomb.translate.write.registry.WriterRegistry;
-import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
@@ -53,7 +55,7 @@ public class FlatWriterRegistryTest {
@Mock
private Writer<DataObject1> writer1;
@Mock
- private Writer<DataObjects.DataObject2> writer2;
+ private Writer<DataObject2> writer2;
@Mock
private Writer<DataObjects.DataObject3> writer3;
@Mock
@@ -66,22 +68,22 @@ public class FlatWriterRegistryTest {
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- when(writer1.getManagedDataObjectType()).thenReturn(DataObjects.DataObject1.IID);
- when(writer2.getManagedDataObjectType()).thenReturn(DataObjects.DataObject2.IID);
+ when(writer1.getManagedDataObjectType()).thenReturn(DataObject1.IID);
+ when(writer2.getManagedDataObjectType()).thenReturn(DataObject2.IID);
when(writer3.getManagedDataObjectType()).thenReturn(DataObjects.DataObject3.IID);
}
@Test
public void testMultipleUpdatesForSingleWriter() throws Exception {
final FlatWriterRegistry flatWriterRegistry =
- new FlatWriterRegistry(ImmutableMap.of(DataObjects.DataObject1.IID, writer1, DataObjects.DataObject2.IID, writer2));
+ new FlatWriterRegistry(ImmutableMap.of(DataObject1.IID, writer1, DataObject2.IID, writer2));
final Multimap<InstanceIdentifier<?>, DataObjectUpdate> updates = HashMultimap.create();
- final InstanceIdentifier<DataObjects.DataObject1> iid = InstanceIdentifier.create(DataObjects.DataObject1.class);
- final InstanceIdentifier<DataObjects.DataObject1> iid2 = InstanceIdentifier.create(DataObjects.DataObject1.class);
- final DataObjects.DataObject1 dataObject = mock(DataObjects.DataObject1.class);
- updates.put(DataObjects.DataObject1.IID, DataObjectUpdate.create(iid, dataObject, dataObject));
- updates.put(DataObjects.DataObject1.IID, DataObjectUpdate.create(iid2, dataObject, dataObject));
+ final InstanceIdentifier<DataObject1> iid = InstanceIdentifier.create(DataObject1.class);
+ final InstanceIdentifier<DataObject1> iid2 = InstanceIdentifier.create(DataObject1.class);
+ 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);
verify(writer1).update(iid, dataObject, dataObject, ctx);
@@ -94,15 +96,15 @@ public class FlatWriterRegistryTest {
@Test
public void testMultipleUpdatesForMultipleWriters() throws Exception {
final FlatWriterRegistry flatWriterRegistry =
- new FlatWriterRegistry(ImmutableMap.of(DataObjects.DataObject1.IID, writer1, DataObjects.DataObject2.IID, writer2));
+ new FlatWriterRegistry(ImmutableMap.of(DataObject1.IID, writer1, DataObject2.IID, writer2));
final Multimap<InstanceIdentifier<?>, DataObjectUpdate> updates = HashMultimap.create();
- final InstanceIdentifier<DataObjects.DataObject1> iid = InstanceIdentifier.create(DataObjects.DataObject1.class);
- final DataObjects.DataObject1 dataObject = mock(DataObjects.DataObject1.class);
- updates.put(DataObjects.DataObject1.IID, DataObjectUpdate.create(iid, dataObject, dataObject));
- final InstanceIdentifier<DataObjects.DataObject2> iid2 = InstanceIdentifier.create(DataObjects.DataObject2.class);
- final DataObjects.DataObject2 dataObject2 = mock(DataObjects.DataObject2.class);
- updates.put(DataObjects.DataObject2.IID, DataObjectUpdate.create(iid2, dataObject2, dataObject2));
+ final InstanceIdentifier<DataObject1> iid = InstanceIdentifier.create(DataObject1.class);
+ final DataObject1 dataObject = mock(DataObject1.class);
+ updates.put(DataObject1.IID, DataObjectUpdate.create(iid, dataObject, dataObject));
+ 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);
final InOrder inOrder = inOrder(writer1, writer2);
@@ -116,15 +118,16 @@ public class FlatWriterRegistryTest {
@Test
public void testMultipleDeletesForMultipleWriters() throws Exception {
final FlatWriterRegistry flatWriterRegistry =
- new FlatWriterRegistry(ImmutableMap.of(DataObjects.DataObject1.IID, writer1, DataObjects.DataObject2.IID, writer2));
+ new FlatWriterRegistry(ImmutableMap.of(DataObject1.IID, writer1, DataObject2.IID, writer2));
final Multimap<InstanceIdentifier<?>, DataObjectUpdate.DataObjectDelete> deletes = HashMultimap.create();
- final InstanceIdentifier<DataObjects.DataObject1> iid = InstanceIdentifier.create(DataObjects.DataObject1.class);
- final DataObjects.DataObject1 dataObject = mock(DataObjects.DataObject1.class);
- deletes.put(DataObjects.DataObject1.IID, ((DataObjectUpdate.DataObjectDelete) DataObjectUpdate.create(iid, dataObject, null)));
- final InstanceIdentifier<DataObjects.DataObject2> iid2 = InstanceIdentifier.create(DataObjects.DataObject2.class);
- final DataObjects.DataObject2 dataObject2 = mock(DataObjects.DataObject2.class);
- deletes.put(DataObjects.DataObject2.IID, ((DataObjectUpdate.DataObjectDelete) DataObjectUpdate.create(iid2, dataObject2, null)));
+ final InstanceIdentifier<DataObject1> iid = InstanceIdentifier.create(DataObject1.class);
+ final DataObject1 dataObject = mock(DataObject1.class);
+ deletes.put(DataObject1.IID, ((DataObjectUpdate.DataObjectDelete) DataObjectUpdate.create(iid, dataObject, null)));
+ final InstanceIdentifier<DataObject2> iid2 = InstanceIdentifier.create(DataObject2.class);
+ 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);
final InOrder inOrder = inOrder(writer1, writer2);
@@ -139,22 +142,23 @@ public class FlatWriterRegistryTest {
@Test
public void testMultipleUpdatesAndDeletesForMultipleWriters() throws Exception {
final FlatWriterRegistry flatWriterRegistry =
- new FlatWriterRegistry(ImmutableMap.of(DataObjects.DataObject1.IID, writer1, DataObjects.DataObject2.IID, writer2));
+ new FlatWriterRegistry(ImmutableMap.of(DataObject1.IID, writer1, DataObject2.IID, writer2));
final Multimap<InstanceIdentifier<?>, DataObjectUpdate.DataObjectDelete> deletes = HashMultimap.create();
final Multimap<InstanceIdentifier<?>, DataObjectUpdate> updates = HashMultimap.create();
- final InstanceIdentifier<DataObjects.DataObject1> iid = InstanceIdentifier.create(DataObjects.DataObject1.class);
- final DataObjects.DataObject1 dataObject = mock(DataObjects.DataObject1.class);
+ final InstanceIdentifier<DataObject1> iid = InstanceIdentifier.create(DataObject1.class);
+ final DataObject1 dataObject = mock(DataObject1.class);
// Writer 1 delete
- deletes.put(DataObjects.DataObject1.IID, ((DataObjectUpdate.DataObjectDelete) DataObjectUpdate.create(iid, dataObject, null)));
+ deletes.put(DataObject1.IID, ((DataObjectUpdate.DataObjectDelete) DataObjectUpdate.create(iid, dataObject, null)));
// Writer 1 update
- updates.put(DataObjects.DataObject1.IID, DataObjectUpdate.create(iid, dataObject, dataObject));
- final InstanceIdentifier<DataObjects.DataObject2> iid2 = InstanceIdentifier.create(DataObjects.DataObject2.class);
- final DataObjects.DataObject2 dataObject2 = mock(DataObjects.DataObject2.class);
+ updates.put(DataObject1.IID, DataObjectUpdate.create(iid, dataObject, dataObject));
+ final InstanceIdentifier<DataObject2> iid2 = InstanceIdentifier.create(DataObject2.class);
+ final DataObject2 dataObject2 = mock(DataObject2.class);
// Writer 2 delete
- deletes.put(DataObjects.DataObject2.IID, ((DataObjectUpdate.DataObjectDelete) DataObjectUpdate.create(iid2, dataObject2, null)));
+ deletes.put(
+ DataObject2.IID, ((DataObjectUpdate.DataObjectDelete) DataObjectUpdate.create(iid2, dataObject2, null)));
// Writer 2 update
- updates.put(DataObjects.DataObject2.IID, DataObjectUpdate.create(iid2, dataObject2, dataObject2));
+ updates.put(DataObject2.IID, DataObjectUpdate.create(iid2, dataObject2, dataObject2));
flatWriterRegistry.update(new WriterRegistry.DataObjectUpdates(updates, deletes), ctx);
final InOrder inOrder = inOrder(writer1, writer2);
@@ -172,34 +176,34 @@ public class FlatWriterRegistryTest {
@Test(expected = IllegalArgumentException.class)
public void testMultipleUpdatesOneMissing() throws Exception {
final FlatWriterRegistry flatWriterRegistry =
- new FlatWriterRegistry(ImmutableMap.of(DataObjects.DataObject1.IID, writer1));
+ new FlatWriterRegistry(ImmutableMap.of(DataObject1.IID, writer1));
final Multimap<InstanceIdentifier<?>, DataObjectUpdate> updates = HashMultimap.create();
- addUpdate(updates, DataObjects.DataObject1.class);
- addUpdate(updates, DataObjects.DataObject2.class);
+ addUpdate(updates, DataObject1.class);
+ addUpdate(updates, DataObject2.class);
flatWriterRegistry.update(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
}
@Test
public void testMultipleUpdatesOneFailing() throws Exception {
final FlatWriterRegistry flatWriterRegistry =
- new FlatWriterRegistry(ImmutableMap.of(DataObjects.DataObject1.IID, writer1, DataObjects.DataObject2.IID, writer2));
+ new FlatWriterRegistry(ImmutableMap.of(DataObject1.IID, writer1, DataObject2.IID, writer2));
// Writer1 always fails
doThrow(new RuntimeException()).when(writer1)
.update(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), any(WriteContext.class));
final Multimap<InstanceIdentifier<?>, DataObjectUpdate> updates = HashMultimap.create();
- addUpdate(updates, DataObjects.DataObject1.class);
- addUpdate(updates, DataObjects.DataObject2.class);
+ addUpdate(updates, DataObject1.class);
+ addUpdate(updates, DataObject2.class);
try {
flatWriterRegistry.update(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
fail("Bulk update should have failed on writer1");
} catch (WriterRegistry.BulkUpdateException e) {
- assertThat(e.getFailedIds().size(), is(2));
- assertThat(e.getFailedIds(), CoreMatchers.hasItem(InstanceIdentifier.create(DataObjects.DataObject2.class)));
- assertThat(e.getFailedIds(), CoreMatchers.hasItem(InstanceIdentifier.create(DataObjects.DataObject1.class)));
+ assertThat(e.getUnrevertedSubtrees(), hasSize(2));
+ assertThat(e.getUnrevertedSubtrees(), hasItem(InstanceIdentifier.create(DataObject2.class)));
+ assertThat(e.getUnrevertedSubtrees(), hasItem(InstanceIdentifier.create(DataObject1.class)));
}
}
@@ -207,25 +211,25 @@ public class FlatWriterRegistryTest {
public void testMultipleUpdatesOneFailingThenRevertWithSuccess() throws Exception {
final FlatWriterRegistry flatWriterRegistry =
new FlatWriterRegistry(
- ImmutableMap.of(DataObjects.DataObject1.IID, writer1, DataObjects.DataObject2.IID, writer2, DataObjects.DataObject3.IID, writer3));
+ ImmutableMap.of(DataObject1.IID, writer1, DataObject2.IID, writer2, DataObjects.DataObject3.IID, writer3));
// Writer1 always fails
doThrow(new RuntimeException()).when(writer3)
.update(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), any(WriteContext.class));
final Multimap<InstanceIdentifier<?>, DataObjectUpdate> updates = HashMultimap.create();
- addUpdate(updates, DataObjects.DataObject1.class);
+ addUpdate(updates, DataObject1.class);
addUpdate(updates, DataObjects.DataObject3.class);
- final InstanceIdentifier<DataObjects.DataObject2> iid2 = InstanceIdentifier.create(DataObjects.DataObject2.class);
- final DataObjects.DataObject2 before2 = mock(DataObjects.DataObject2.class);
- final DataObjects.DataObject2 after2 = mock(DataObjects.DataObject2.class);
- updates.put(DataObjects.DataObject2.IID, DataObjectUpdate.create(iid2, before2, after2));
+ final InstanceIdentifier<DataObject2> iid2 = InstanceIdentifier.create(DataObject2.class);
+ final DataObject2 before2 = mock(DataObject2.class);
+ final DataObject2 after2 = mock(DataObject2.class);
+ updates.put(DataObject2.IID, DataObjectUpdate.create(iid2, before2, after2));
try {
flatWriterRegistry.update(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
fail("Bulk update should have failed on writer1");
} catch (WriterRegistry.BulkUpdateException e) {
- assertThat(e.getFailedIds().size(), is(1));
+ assertThat(e.getUnrevertedSubtrees().size(), is(1));
final InOrder inOrder = inOrder(writer1, writer2, writer3);
inOrder.verify(writer1)
@@ -250,15 +254,15 @@ public class FlatWriterRegistryTest {
public void testMultipleUpdatesOneFailingThenRevertWithFail() throws Exception {
final FlatWriterRegistry flatWriterRegistry =
new FlatWriterRegistry(
- ImmutableMap.of(DataObjects.DataObject1.IID, writer1, DataObjects.DataObject2.IID, writer2, DataObjects.DataObject3.IID, writer3));
+ ImmutableMap.of(DataObject1.IID, writer1, DataObject2.IID, writer2, DataObjects.DataObject3.IID, writer3));
// Writer1 always fails
doThrow(new RuntimeException()).when(writer3)
.update(any(InstanceIdentifier.class), any(DataObject.class), any(DataObject.class), any(WriteContext.class));
final Multimap<InstanceIdentifier<?>, DataObjectUpdate> updates = HashMultimap.create();
- addUpdate(updates, DataObjects.DataObject1.class);
- addUpdate(updates, DataObjects.DataObject2.class);
+ addUpdate(updates, DataObject1.class);
+ addUpdate(updates, DataObject2.class);
addUpdate(updates, DataObjects.DataObject3.class);
try {
@@ -272,8 +276,8 @@ public class FlatWriterRegistryTest {
e.revertChanges(revertWriteContext);
} catch (WriterRegistry.Reverter.RevertFailedException e1) {
assertThat(e1.getNotRevertedChanges().size(), is(1));
- assertThat(e1.getNotRevertedChanges(), CoreMatchers
- .hasItem(InstanceIdentifier.create(DataObjects.DataObject1.class)));
+ assertThat(e1.getNotRevertedChanges(),
+ hasItem(InstanceIdentifier.create(DataObject1.class)));
}
}
}
@@ -285,7 +289,7 @@ public class FlatWriterRegistryTest {
final FlatWriterRegistry flatWriterRegistry =
new FlatWriterRegistry(
- ImmutableMap.of(DataObjects.DataObject1.IID, writer1, DataObjects.DataObject1ChildK.IID,writer4));
+ ImmutableMap.of(DataObject1.IID, writer1, DataObjects.DataObject1ChildK.IID,writer4));
// Writer1 always fails
doThrow(new RuntimeException()).when(writer1)
@@ -294,7 +298,7 @@ public class FlatWriterRegistryTest {
final Multimap<InstanceIdentifier<?>, DataObjectUpdate> updates = HashMultimap.create();
addKeyedUpdate(updates,DataObjects.DataObject1ChildK.class);
- addUpdate(updates, DataObjects.DataObject1.class);
+ addUpdate(updates, DataObject1.class);
try {
flatWriterRegistry.update(new WriterRegistry.DataObjectUpdates(updates, ImmutableMultimap.of()), ctx);
fail("Bulk update should have failed on writer1");
@@ -307,8 +311,8 @@ public class FlatWriterRegistryTest {
e.revertChanges(revertWriteContext);
} catch (WriterRegistry.Reverter.RevertFailedException e1) {
assertThat(e1.getNotRevertedChanges().size(), is(1));
- assertThat(e1.getNotRevertedChanges(), CoreMatchers
- .hasItem(InstanceIdentifier.create(DataObjects.DataObject1.class)));
+ assertThat(e1.getNotRevertedChanges(),
+ hasItem(InstanceIdentifier.create(DataObject1.class)));
}
}
}