Merge "Cosmetics: check in pom.xml files as _sort_pom_ wants them to be"
authorDevin Avery <devin.avery@brocade.com>
Wed, 29 Oct 2014 14:17:58 +0000 (14:17 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 29 Oct 2014 14:17:58 +0000 (14:17 +0000)
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeOutputStreamWriter.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamWriter.java [deleted file]
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeWriter.java [deleted file]
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SampleNormalizedNodeSerializable.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardWriteTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java

index bdc52bca688a0c354f9c91ad7de6c6b774bcd966..b59a32efc9bd96e0bd4ad157b0faa565dafa948b 100644 (file)
@@ -55,19 +55,22 @@ import java.util.Set;
 
 public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamReader {
 
-    private DataInputStream reader;
-
     private static final Logger LOG = LoggerFactory.getLogger(NormalizedNodeInputStreamReader.class);
 
-    private Map<Integer, String> codedStringMap = new HashMap<>();
     private static final String REVISION_ARG = "?revision=";
 
+    private final DataInputStream reader;
+
+    private final Map<Integer, String> codedStringMap = new HashMap<>();
+
+    private QName lastLeafSetQName;
+
     public NormalizedNodeInputStreamReader(InputStream stream) throws IOException {
         Preconditions.checkNotNull(stream);
         reader = new DataInputStream(stream);
     }
 
-
+    @Override
     public NormalizedNode<?, ?> readNormalizedNode() throws IOException {
         NormalizedNode<?, ?> node = null;
 
@@ -89,20 +92,21 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead
             node = augmentationBuilder.build();
 
         } else {
-            QName qName = readQName();
-
             if(nodeType == NodeTypes.LEAF_SET_ENTRY_NODE) {
                 LOG.debug("Reading leaf set entry node. Will create NodeWithValue instance identifier");
 
                 // Read the object value
                 Object value = readObject();
 
-                YangInstanceIdentifier.NodeWithValue nodeWithValue = new YangInstanceIdentifier.NodeWithValue(qName, value);
-                node =  Builders.leafSetEntryBuilder().withNodeIdentifier(nodeWithValue).withValue(value).build();
+                YangInstanceIdentifier.NodeWithValue nodeWithValue = new YangInstanceIdentifier.NodeWithValue(
+                        lastLeafSetQName, value);
+                node =  Builders.leafSetEntryBuilder().withNodeIdentifier(nodeWithValue).
+                        withValue(value).build();
 
             } else if(nodeType == NodeTypes.MAP_ENTRY_NODE) {
                 LOG.debug("Reading map entry node. Will create node identifier with predicates.");
 
+                QName qName = readQName();
                 YangInstanceIdentifier.NodeIdentifierWithPredicates nodeIdentifier =
                     new YangInstanceIdentifier.NodeIdentifierWithPredicates(qName, readKeyValueMap());
                 DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder
@@ -114,6 +118,8 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead
 
             } else {
                 LOG.debug("Creating standard node identifier. ");
+
+                QName qName = readQName();
                 YangInstanceIdentifier.NodeIdentifier identifier = new YangInstanceIdentifier.NodeIdentifier(qName);
                 node = readNodeIdentifierDependentNode(nodeType, identifier);
 
@@ -186,7 +192,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead
                 LOG.debug("Read leaf set node");
                 ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder =
                     Builders.leafSetBuilder().withNodeIdentifier(identifier);
-                leafSetBuilder = addLeafSetChildren(leafSetBuilder);
+                leafSetBuilder = addLeafSetChildren(identifier.getNodeType(), leafSetBuilder);
                 return leafSetBuilder.build();
 
             default :
@@ -325,11 +331,14 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead
         }
     }
 
-    private ListNodeBuilder<Object, LeafSetEntryNode<Object>> addLeafSetChildren(ListNodeBuilder<Object,
-        LeafSetEntryNode<Object>> builder)
+    private ListNodeBuilder<Object, LeafSetEntryNode<Object>> addLeafSetChildren(QName nodeType,
+            ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder)
         throws IOException {
 
         LOG.debug("Reading children of leaf set");
+
+        lastLeafSetQName = nodeType;
+
         LeafSetEntryNode<Object> child = (LeafSetEntryNode<Object>)readNormalizedNode();
 
         while(child != null) {
index 05a47a0401a18c2774caae0c7cc85fa6f07b9ebe..cbd7bf885373b331fb71a9d6899efc755b85f767 100644 (file)
@@ -14,6 +14,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.Iterables;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -41,11 +42,11 @@ import java.util.Set;
 
 public class NormalizedNodeOutputStreamWriter implements NormalizedNodeStreamWriter{
 
-    private DataOutputStream writer;
-
     private static final Logger LOG = LoggerFactory.getLogger(NormalizedNodeOutputStreamWriter.class);
 
-    private Map<String, Integer> stringCodeMap = new HashMap<>();
+    private final DataOutputStream writer;
+
+    private final Map<String, Integer> stringCodeMap = new HashMap<>();
 
     public NormalizedNodeOutputStreamWriter(OutputStream stream) throws IOException {
         Preconditions.checkNotNull(stream);
@@ -70,12 +71,10 @@ public class NormalizedNodeOutputStreamWriter implements NormalizedNodeStreamWri
     }
 
     @Override
-    public void leafSetEntryNode(YangInstanceIdentifier.NodeWithValue name, Object value) throws IOException, IllegalArgumentException {
-        Preconditions.checkNotNull(name, "Node identifier should not be null");
-
+    public void leafSetEntryNode(Object value) throws IOException, IllegalArgumentException {
         LOG.debug("Writing a new leaf set entry node");
-        startNode(name.getNodeType(), NodeTypes.LEAF_SET_ENTRY_NODE);
 
+        writer.writeByte(NodeTypes.LEAF_SET_ENTRY_NODE);
         writeObject(value);
     }
 
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamWriter.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamWriter.java
deleted file mode 100644 (file)
index af95b61..0000000
+++ /dev/null
@@ -1,219 +0,0 @@
-
-/*
- * Copyright (c) 2014 Cisco Systems, 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.controller.cluster.datastore.node.utils.stream;
-
-import java.io.Closeable;
-import java.io.Flushable;
-import java.io.IOException;
-
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-
-/**
- * Event Stream Writer based on Normalized Node tree representation
- *
- * <h3>Writing Event Stream</h3>
- *
- * <ul>
- * <li><code>container</code> - Container node representation, start event is
- * emitted using {@link #startContainerNode(YangInstanceIdentifier.NodeIdentifier, int)}
- * and node end event is
- * emitted using {@link #endNode()}. Container node is implementing
- * {@link org.opendaylight.yangtools.yang.binding.DataObject} interface.
- *
- * <li><code>list</code> - YANG list statement has two representation in event
- * stream - unkeyed list and map. Unkeyed list is YANG list which did not
- * specify key.</li>
- *
- * <ul>
- * <li><code>Map</code> - Map start event is emitted using
- * {@link #startMapNode(YangInstanceIdentifier.NodeIdentifier, int)}
- * and is ended using {@link #endNode()}. Each map entry start is emitted using
- * {@link #startMapEntryNode(YangInstanceIdentifier.NodeIdentifierWithPredicates, int)}
- * with Map of keys
- * and finished using {@link #endNode()}.</li>
- *
- * <li><code>UnkeyedList</code> - Unkeyed list represent list without keys,
- * unkeyed list start is emitted using
- * {@link #startUnkeyedList(YangInstanceIdentifier.NodeIdentifier, int)} list
- * end is emitted using {@link #endNode()}. Each list item is emitted using
- * {@link #startUnkeyedListItem(YangInstanceIdentifier.NodeIdentifier, int)}
- * and ended using {@link #endNode()}.</li>
- * </ul>
- *
- * <li><code>leaf</code> - Leaf node event is emitted using
- * {@link #leafNode(YangInstanceIdentifier.NodeIdentifier, Object)}.
- * {@link #endNode()} MUST NOT BE emitted for
- * leaf node.</li>
- *
- * <li><code>leaf-list</code> - Leaf list start is emitted using
- * {@link #startLeafSet(YangInstanceIdentifier.NodeIdentifier, int)}.
- * Leaf list end is emitted using
- * {@link #endNode()}. Leaf list entries are emitted using
- * {@link #leafSetEntryNode(YangInstanceIdentifier.NodeWithValue name, Object).
- *
- * <li><code>anyxml - Anyxml node event is emitted using
- * {@link #leafNode(YangInstanceIdentifier.NodeIdentifier, Object)}. {@link #endNode()} MUST NOT BE emitted
- * for anyxml node.</code></li>
- *
- *
- * <li><code>choice</code> Choice node event is emmited by
- * {@link #startChoiceNode(YangInstanceIdentifier.NodeIdentifier, int)} event and
- * finished by invoking {@link #endNode()}
- * <li>
- * <code>augment</code> - Represents augmentation, augmentation node is started
- * by invoking {@link #startAugmentationNode(YangInstanceIdentifier.AugmentationIdentifier)} and
- * finished by invoking {@link #endNode()}.</li>
- *
- * </ul>
- *
- * <h3>Implementation notes</h3>
- *
- * <p>
- * Implementations of this interface must not hold user suppled objects
- * and resources needlessly.
- *
- */
-
-public interface NormalizedNodeStreamWriter extends Closeable, Flushable {
-
-    public final int UNKNOWN_SIZE = -1;
-
-    /**
-     * Write the leaf node identifier and value to the stream.
-     * @param name
-     * @param value
-     * @throws IOException
-     * @throws IllegalArgumentException
-     */
-    void leafNode(YangInstanceIdentifier.NodeIdentifier name, Object value)
-        throws IOException, IllegalArgumentException;
-
-    /**
-     * Start writing leaf Set node. You must call {@link #endNode()} once you are done writing all of its children.
-     * @param name
-     * @param childSizeHint is the estimated children count. Usage is optional in implementation.
-     * @throws IOException
-     * @throws IllegalArgumentException
-     */
-    void startLeafSet(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint)
-        throws IOException, IllegalArgumentException;
-
-    /**
-     * Write the leaf Set Entry Node object to the stream with identifier and value.
-     * @param name
-     * @param value
-     * @throws IOException
-     * @throws IllegalArgumentException
-     */
-    void leafSetEntryNode(YangInstanceIdentifier.NodeWithValue name, Object value)
-        throws IOException, IllegalArgumentException;
-
-    /**
-     * Start writing container node. You must call {@link #endNode()} once you are done writing all of its children.
-     * @param name
-     * @param childSizeHint is the estimated children count. Usage is optional in implementation.
-     * @throws IOException
-     * @throws IllegalArgumentException
-     */
-    void startContainerNode(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint)
-        throws IOException, IllegalArgumentException;
-
-    /**
-     * Start writing unkeyed list node. You must call {@link #endNode()} once you are done writing all of its children.
-     * @param name
-     * @param childSizeHint is the estimated children count. Usage is optional in implementation.
-     * @throws IOException
-     * @throws IllegalArgumentException
-     */
-    void startUnkeyedList(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint)
-        throws IOException, IllegalArgumentException;
-
-    /**
-     * Start writing unkeyed list item. You must call {@link #endNode()} once you are done writing all of its children.
-     * @param name
-     * @param childSizeHint is the estimated children count. Usage is optional in implementation.
-     * @throws IOException
-     * @throws IllegalStateException
-     */
-    void startUnkeyedListItem(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint)
-        throws IOException, IllegalStateException;
-
-    /**
-     * Start writing map node. You must call {@link #endNode()} once you are done writing all of its children.
-     * @param name
-     * @param childSizeHint is the estimated children count. Usage is optional in implementation.
-     * @throws IOException
-     * @throws IllegalArgumentException
-     */
-    void startMapNode(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint)
-        throws IOException, IllegalArgumentException;
-
-    /**
-     * Start writing map entry node. You must call {@link #endNode()} once you are done writing all of its children.
-     * @param identifier
-     * @param childSizeHint is the estimated children count. Usage is optional in implementation.
-     * @throws IOException
-     * @throws IllegalArgumentException
-     */
-    void startMapEntryNode(YangInstanceIdentifier.NodeIdentifierWithPredicates identifier, int childSizeHint)
-        throws IOException, IllegalArgumentException;
-
-    /**
-     * Start writing ordered map node. You must call {@link #endNode()} once you are done writing all of its children.
-     * @param name
-     * @param childSizeHint is the estimated children count. Usage is optional in implementation.
-     * @throws IOException
-     * @throws IllegalArgumentException
-     */
-    void startOrderedMapNode(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint)
-        throws IOException, IllegalArgumentException;
-
-    /**
-     * Start writing choice node. You must call {@link #endNode()} once you are done writing all of its children.
-     * @param name
-     * @param childSizeHint is the estimated children count. Usage is optional in implementation.
-     * @throws IOException
-     * @throws IllegalArgumentException
-     */
-    void startChoiceNode(YangInstanceIdentifier.NodeIdentifier name, int childSizeHint)
-        throws IOException, IllegalArgumentException;
-
-    /**
-     * Start writing augmentation node. You must call {@link #endNode()} once you are done writing all of its children.
-     * @param identifier
-     * @throws IOException
-     * @throws IllegalArgumentException
-     */
-    void startAugmentationNode(YangInstanceIdentifier.AugmentationIdentifier identifier)
-        throws IOException, IllegalArgumentException;
-
-    /**
-     * Write any xml node identifier and value to the stream
-     * @param name
-     * @param value
-     * @throws IOException
-     * @throws IllegalArgumentException
-     */
-    void anyxmlNode(YangInstanceIdentifier.NodeIdentifier name, Object value)
-        throws IOException, IllegalArgumentException;
-
-    /**
-     * This method should be used to add end symbol/identifier of node in the stream.
-     * @throws IOException
-     * @throws IllegalStateException
-     */
-    void endNode() throws IOException, IllegalStateException;
-
-    @Override
-    void close() throws IOException;
-
-    @Override
-    void flush() throws IOException;
-}
index 052f609e92f395653d7bd1776ea4f1eefc216c5a..ae548dba23aa781420efbde6c8ce1522f365a1c1 100644 (file)
@@ -16,19 +16,19 @@ import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.datastore.util.TestModel;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 
-import static org.junit.Assert.fail;
-
 public class NormalizedNodeStreamReaderWriterTest {
 
     final NormalizedNode<?, ?> input = TestModel.createTestContainer();
 
     @Test
-    public void testNormalizedNodeStreamReaderWriter() {
+    public void testNormalizedNodeStreamReaderWriter() throws IOException {
 
         byte[] byteData = null;
 
@@ -39,17 +39,14 @@ public class NormalizedNodeStreamReaderWriterTest {
             normalizedNodeWriter.write(input);
             byteData = byteArrayOutputStream.toByteArray();
 
-        } catch (IOException e) {
-            fail("Writing to OutputStream failed :" + e.toString());
         }
 
-        try(NormalizedNodeInputStreamReader reader = new NormalizedNodeInputStreamReader(new ByteArrayInputStream(byteData))) {
+        try(NormalizedNodeInputStreamReader reader = new NormalizedNodeInputStreamReader(
+                new ByteArrayInputStream(byteData))) {
 
             NormalizedNode<?,?> node = reader.readNormalizedNode();
             Assert.assertEquals(input, node);
 
-        } catch (IOException e) {
-            fail("Reading from InputStream failed :" + e.toString());
         }
     }
 
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeWriter.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeWriter.java
deleted file mode 100644 (file)
index 845038e..0000000
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Copyright (c) 2014 Cisco Systems, 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.controller.cluster.datastore.node.utils.stream;
-
-import com.google.common.base.Preconditions;
-import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode;
-import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
-import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
-
-import java.io.Closeable;
-import java.io.Flushable;
-import java.io.IOException;
-import java.util.Collection;
-
-import static org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeStreamWriter.UNKNOWN_SIZE;
-
-
-/**
- * This class is used only for testing purpose for now, we may use similar logic while integrating
- * with cluster
- */
-
-public class NormalizedNodeWriter implements Closeable, Flushable {
-    private final NormalizedNodeStreamWriter writer;
-
-    private NormalizedNodeWriter(final NormalizedNodeStreamWriter writer) {
-        this.writer = Preconditions.checkNotNull(writer);
-    }
-
-    protected final NormalizedNodeStreamWriter getWriter() {
-        return writer;
-    }
-
-    /**
-     * Create a new writer backed by a {@link org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter}.
-     *
-     * @param writer Back-end writer
-     * @return A new instance.
-     */
-    public static NormalizedNodeWriter forStreamWriter(final NormalizedNodeStreamWriter writer) {
-        return new NormalizedNodeWriter(writer);
-    }
-
-
-    /**
-     * Iterate over the provided {@link org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode} and emit write
-     * events to the encapsulated {@link org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter}.
-     *
-     * @param node Node
-     * @return
-     * @throws java.io.IOException when thrown from the backing writer.
-     */
-    public final NormalizedNodeWriter write(final NormalizedNode<?, ?> node) throws IOException {
-        if (wasProcessedAsComplexNode(node)) {
-            return this;
-        }
-
-        if (wasProcessAsSimpleNode(node)) {
-            return this;
-        }
-
-        throw new IllegalStateException("It wasn't possible to serialize node " + node);
-    }
-
-    @Override
-    public void flush() throws IOException {
-        writer.flush();
-    }
-
-    @Override
-    public void close() throws IOException {
-        writer.flush();
-        writer.close();
-    }
-
-    /**
-     * Emit a best guess of a hint for a particular set of children. It evaluates the
-     * iterable to see if the size can be easily gotten to. If it is, we hint at the
-     * real number of child nodes. Otherwise we emit UNKNOWN_SIZE.
-     *
-     * @param children Child nodes
-     * @return Best estimate of the collection size required to hold all the children.
-     */
-    static final int childSizeHint(final Iterable<?> children) {
-        return (children instanceof Collection) ? ((Collection<?>) children).size() : UNKNOWN_SIZE;
-    }
-
-    private boolean wasProcessAsSimpleNode(final NormalizedNode<?, ?> node) throws IOException {
-        if (node instanceof LeafSetEntryNode) {
-            final LeafSetEntryNode<?> nodeAsLeafList = (LeafSetEntryNode<?>)node;
-            writer.leafSetEntryNode(nodeAsLeafList.getIdentifier(), nodeAsLeafList.getValue());
-            return true;
-        } else if (node instanceof LeafNode) {
-            final LeafNode<?> nodeAsLeaf = (LeafNode<?>)node;
-            writer.leafNode(nodeAsLeaf.getIdentifier(), nodeAsLeaf.getValue());
-            return true;
-        } else if (node instanceof AnyXmlNode) {
-            final AnyXmlNode anyXmlNode = (AnyXmlNode)node;
-            writer.anyxmlNode(anyXmlNode.getIdentifier(), anyXmlNode.getValue());
-            return true;
-        }
-
-        return false;
-    }
-
-    /**
-     * Emit events for all children and then emit an endNode() event.
-     *
-     * @param children Child iterable
-     * @return True
-     * @throws java.io.IOException when the writer reports it
-     */
-    protected final boolean writeChildren(final Iterable<? extends NormalizedNode<?, ?>> children) throws IOException {
-        for (NormalizedNode<?, ?> child : children) {
-            write(child);
-        }
-
-        writer.endNode();
-        return true;
-    }
-
-    protected boolean writeMapEntryNode(final MapEntryNode node) throws IOException {
-        writer.startMapEntryNode(node.getIdentifier(), childSizeHint(node.getValue()));
-        return writeChildren(node.getValue());
-    }
-
-    private boolean wasProcessedAsComplexNode(final NormalizedNode<?, ?> node) throws IOException {
-        if (node instanceof ContainerNode) {
-            final ContainerNode n = (ContainerNode) node;
-            writer.startContainerNode(n.getIdentifier(), childSizeHint(n.getValue()));
-            return writeChildren(n.getValue());
-        }
-        if (node instanceof MapEntryNode) {
-            return writeMapEntryNode((MapEntryNode) node);
-        }
-        if (node instanceof UnkeyedListEntryNode) {
-            final UnkeyedListEntryNode n = (UnkeyedListEntryNode) node;
-            writer.startUnkeyedListItem(n.getIdentifier(), childSizeHint(n.getValue()));
-            return writeChildren(n.getValue());
-        }
-        if (node instanceof ChoiceNode) {
-            final ChoiceNode n = (ChoiceNode) node;
-            writer.startChoiceNode(n.getIdentifier(), childSizeHint(n.getValue()));
-            return writeChildren(n.getValue());
-        }
-        if (node instanceof AugmentationNode) {
-            final AugmentationNode n = (AugmentationNode) node;
-            writer.startAugmentationNode(n.getIdentifier());
-            return writeChildren(n.getValue());
-        }
-        if (node instanceof UnkeyedListNode) {
-            final UnkeyedListNode n = (UnkeyedListNode) node;
-            writer.startUnkeyedList(n.getIdentifier(), childSizeHint(n.getValue()));
-            return writeChildren(n.getValue());
-        }
-        if (node instanceof OrderedMapNode) {
-            final OrderedMapNode n = (OrderedMapNode) node;
-            writer.startOrderedMapNode(n.getIdentifier(), childSizeHint(n.getValue()));
-            return writeChildren(n.getValue());
-        }
-        if (node instanceof MapNode) {
-            final MapNode n = (MapNode) node;
-            writer.startMapNode(n.getIdentifier(), childSizeHint(n.getValue()));
-            return writeChildren(n.getValue());
-        }
-        if (node instanceof LeafSetNode) {
-            //covers also OrderedLeafSetNode for which doesn't exist start* method
-            final LeafSetNode<?> n = (LeafSetNode<?>) node;
-            writer.startLeafSet(n.getIdentifier(), childSizeHint(n.getValue()));
-            return writeChildren(n.getValue());
-        }
-
-        return false;
-    }
-}
index 33d48a52786c73c79d4eb708e40513d96531024c..10a2ad90a5bfebed8d15926dc8bd166623e0ff9c 100644 (file)
@@ -10,6 +10,8 @@ package org.opendaylight.controller.cluster.datastore.node.utils.stream;
 
 
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
 
 import java.io.IOException;
 import java.io.ObjectInputStream;
@@ -18,6 +20,7 @@ import java.io.Serializable;
 import java.net.URISyntaxException;
 
 public class SampleNormalizedNodeSerializable implements Serializable {
+    private static final long serialVersionUID = 1L;
 
     private NormalizedNode<?, ?> input;
 
index 21c210daf252fc4633b12882bb18dfea99779aa5..b0eaf98d59c9ccd2d1eda1f6d782736db238290e 100644 (file)
@@ -11,6 +11,7 @@
 package org.opendaylight.controller.cluster.datastore;
 
 import akka.actor.ActorRef;
+import akka.actor.PoisonPill;
 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats;
 import org.opendaylight.controller.cluster.datastore.messages.DeleteData;
 import org.opendaylight.controller.cluster.datastore.messages.DeleteDataReply;
@@ -87,12 +88,12 @@ public class ShardWriteTransaction extends ShardTransaction {
         }
     }
 
-    private void writeData(DOMStoreWriteTransaction transaction, WriteData message, boolean returnSerialized) {
+    private void writeData(DOMStoreWriteTransaction transaction, WriteData message,
+            boolean returnSerialized) {
+        LOG.debug("writeData at path : {}", message.getPath());
+
         modification.addModification(
                 new WriteModification(message.getPath(), message.getData(), getSchemaContext()));
-        if(LOG.isDebugEnabled()) {
-            LOG.debug("writeData at path : " + message.getPath().toString());
-        }
         try {
             transaction.write(message.getPath(), message.getData());
             WriteDataReply writeDataReply = new WriteDataReply();
@@ -103,12 +104,13 @@ public class ShardWriteTransaction extends ShardTransaction {
         }
     }
 
-    private void mergeData(DOMStoreWriteTransaction transaction, MergeData message, boolean returnSerialized) {
+    private void mergeData(DOMStoreWriteTransaction transaction, MergeData message,
+            boolean returnSerialized) {
+        LOG.debug("mergeData at path : {}", message.getPath());
+
         modification.addModification(
                 new MergeModification(message.getPath(), message.getData(), getSchemaContext()));
-        if(LOG.isDebugEnabled()) {
-            LOG.debug("mergeData at path : " + message.getPath().toString());
-        }
+
         try {
             transaction.merge(message.getPath(), message.getData());
             MergeDataReply mergeDataReply = new MergeDataReply();
@@ -119,10 +121,10 @@ public class ShardWriteTransaction extends ShardTransaction {
         }
     }
 
-    private void deleteData(DOMStoreWriteTransaction transaction, DeleteData message, boolean returnSerialized) {
-        if(LOG.isDebugEnabled()) {
-            LOG.debug("deleteData at path : " + message.getPath().toString());
-        }
+    private void deleteData(DOMStoreWriteTransaction transaction, DeleteData message,
+            boolean returnSerialized) {
+        LOG.debug("deleteData at path : {}", message.getPath());
+
         modification.addModification(new DeleteModification(message.getPath()));
         try {
             transaction.delete(message.getPath());
@@ -134,12 +136,19 @@ public class ShardWriteTransaction extends ShardTransaction {
         }
     }
 
-    private void readyTransaction(DOMStoreWriteTransaction transaction, ReadyTransaction message, boolean returnSerialized) {
+    private void readyTransaction(DOMStoreWriteTransaction transaction, ReadyTransaction message,
+            boolean returnSerialized) {
+        String transactionID = getTransactionID();
+
+        LOG.debug("readyTransaction : {}", transactionID);
+
         DOMStoreThreePhaseCommitCohort cohort =  transaction.ready();
 
-        getShardActor().forward(new ForwardedReadyTransaction(
-            getTransactionID(), cohort, modification, returnSerialized),
-                getContext());
+        getShardActor().forward(new ForwardedReadyTransaction(transactionID, cohort, modification,
+                returnSerialized), getContext());
+
+        // The shard will handle the commit from here so we're no longer needed - self-destruct.
+        getSelf().tell(PoisonPill.getInstance(), getSelf());
     }
 
     // These classes are in here for test purposes only
index 17731de5cd48918a1d03d04ec6dece68b9321e5a..6375e3c7fba51fa02c077ac49d01def5eed5d22a 100644 (file)
@@ -12,6 +12,7 @@ package org.opendaylight.controller.cluster.datastore;
 
 import akka.actor.ActorRef;
 import akka.actor.Props;
+import akka.pattern.AskTimeoutException;
 import akka.testkit.TestActorRef;
 import com.google.common.util.concurrent.ListeningExecutorService;
 import com.google.common.util.concurrent.MoreExecutors;
@@ -155,7 +156,7 @@ public class ShardTransactionFailureTest extends AbstractActorTest {
         Await.result(future, Duration.create(3, TimeUnit.SECONDS));
     }
 
-    @Test(expected = IllegalStateException.class)
+    @Test(expected = AskTimeoutException.class)
     public void testNegativeWriteWithTransactionReady() throws Exception {
 
 
@@ -187,7 +188,7 @@ public class ShardTransactionFailureTest extends AbstractActorTest {
         Await.result(future, Duration.create(3, TimeUnit.SECONDS));
     }
 
-    @Test(expected = IllegalStateException.class)
+    @Test(expected = AskTimeoutException.class)
     public void testNegativeReadWriteWithTransactionReady() throws Exception {
 
 
@@ -224,7 +225,7 @@ public class ShardTransactionFailureTest extends AbstractActorTest {
             .serialize(Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).build());
     }
 
-    @Test(expected = IllegalStateException.class)
+    @Test(expected = AskTimeoutException.class)
     public void testNegativeMergeTransactionReady() throws Exception {
 
 
@@ -256,7 +257,7 @@ public class ShardTransactionFailureTest extends AbstractActorTest {
     }
 
 
-    @Test(expected = IllegalStateException.class)
+    @Test(expected = AskTimeoutException.class)
     public void testNegativeDeleteDataWhenTransactionReady() throws Exception {
 
 
index 711f3d7a72a16b615224246e07e3adb750b7cff6..793df8e0ca9776f7d21c07fcbaf7788be8f562bd 100644 (file)
@@ -88,9 +88,9 @@ public class ShardTransactionTest extends AbstractActorTest {
             testOnReceiveReadData(getSystem().actorOf(props, "testReadDataRW"));
         }
 
-        private void testOnReceiveReadData(final ActorRef subject) {
+        private void testOnReceiveReadData(final ActorRef transaction) {
             //serialized read
-            subject.tell(new ReadData(YangInstanceIdentifier.builder().build()).toSerializable(),
+            transaction.tell(new ReadData(YangInstanceIdentifier.builder().build()).toSerializable(),
                 getRef());
 
             ShardTransactionMessages.ReadDataReply replySerialized =
@@ -101,7 +101,7 @@ public class ShardTransactionTest extends AbstractActorTest {
                 .getNormalizedNode());
 
             // unserialized read
-            subject.tell(new ReadData(YangInstanceIdentifier.builder().build()),getRef());
+            transaction.tell(new ReadData(YangInstanceIdentifier.builder().build()),getRef());
 
             ReadDataReply reply = expectMsgClass(duration("5 seconds"), ReadDataReply.class);
 
@@ -126,9 +126,9 @@ public class ShardTransactionTest extends AbstractActorTest {
                     props, "testReadDataWhenDataNotFoundRW"));
         }
 
-        private void testOnReceiveReadDataWhenDataNotFound(final ActorRef subject) {
+        private void testOnReceiveReadDataWhenDataNotFound(final ActorRef transaction) {
             // serialized read
-            subject.tell(new ReadData(TestModel.TEST_PATH).toSerializable(), getRef());
+            transaction.tell(new ReadData(TestModel.TEST_PATH).toSerializable(), getRef());
 
             ShardTransactionMessages.ReadDataReply replySerialized =
                 expectMsgClass(duration("5 seconds"), ReadDataReply.SERIALIZABLE_CLASS);
@@ -137,7 +137,7 @@ public class ShardTransactionTest extends AbstractActorTest {
                 testSchemaContext, TestModel.TEST_PATH, replySerialized).getNormalizedNode() == null);
 
             // unserialized read
-            subject.tell(new ReadData(TestModel.TEST_PATH),getRef());
+            transaction.tell(new ReadData(TestModel.TEST_PATH),getRef());
 
             ReadDataReply reply = expectMsgClass(duration("5 seconds"), ReadDataReply.class);
 
@@ -160,8 +160,8 @@ public class ShardTransactionTest extends AbstractActorTest {
             testOnReceiveDataExistsPositive(getSystem().actorOf(props, "testDataExistsPositiveRW"));
         }
 
-        private void testOnReceiveDataExistsPositive(final ActorRef subject) {
-            subject.tell(new DataExists(YangInstanceIdentifier.builder().build()).toSerializable(),
+        private void testOnReceiveDataExistsPositive(final ActorRef transaction) {
+            transaction.tell(new DataExists(YangInstanceIdentifier.builder().build()).toSerializable(),
                 getRef());
 
             ShardTransactionMessages.DataExistsReply replySerialized =
@@ -170,7 +170,7 @@ public class ShardTransactionTest extends AbstractActorTest {
             assertTrue(DataExistsReply.fromSerializable(replySerialized).exists());
 
             // unserialized read
-            subject.tell(new DataExists(YangInstanceIdentifier.builder().build()),getRef());
+            transaction.tell(new DataExists(YangInstanceIdentifier.builder().build()),getRef());
 
             DataExistsReply reply = expectMsgClass(duration("5 seconds"), DataExistsReply.class);
 
@@ -193,8 +193,8 @@ public class ShardTransactionTest extends AbstractActorTest {
             testOnReceiveDataExistsNegative(getSystem().actorOf(props, "testDataExistsNegativeRW"));
         }
 
-        private void testOnReceiveDataExistsNegative(final ActorRef subject) {
-            subject.tell(new DataExists(TestModel.TEST_PATH).toSerializable(), getRef());
+        private void testOnReceiveDataExistsNegative(final ActorRef transaction) {
+            transaction.tell(new DataExists(TestModel.TEST_PATH).toSerializable(), getRef());
 
             ShardTransactionMessages.DataExistsReply replySerialized =
                 expectMsgClass(duration("5 seconds"), ShardTransactionMessages.DataExistsReply.class);
@@ -202,7 +202,7 @@ public class ShardTransactionTest extends AbstractActorTest {
             assertFalse(DataExistsReply.fromSerializable(replySerialized).exists());
 
             // unserialized read
-            subject.tell(new DataExists(TestModel.TEST_PATH),getRef());
+            transaction.tell(new DataExists(TestModel.TEST_PATH),getRef());
 
             DataExistsReply reply = expectMsgClass(duration("5 seconds"), DataExistsReply.class);
 
@@ -229,20 +229,18 @@ public class ShardTransactionTest extends AbstractActorTest {
             final ActorRef shard = createShard();
             final Props props = ShardTransaction.props(store.newWriteOnlyTransaction(), shard,
                     testSchemaContext, datastoreContext, shardStats, "txn");
-            final ActorRef subject =
-                getSystem().actorOf(props, "testWriteData");
+            final ActorRef transaction = getSystem().actorOf(props, "testWriteData");
 
-            subject.tell(new WriteData(TestModel.TEST_PATH,
+            transaction.tell(new WriteData(TestModel.TEST_PATH,
                 ImmutableNodes.containerNode(TestModel.TEST_QNAME), TestModel.createTestContext()).toSerializable(),
                 getRef());
 
-            ShardTransactionMessages.WriteDataReply replySerialized =
-                expectMsgClass(duration("5 seconds"), ShardTransactionMessages.WriteDataReply.class);
+            expectMsgClass(duration("5 seconds"), ShardTransactionMessages.WriteDataReply.class);
 
-            assertModification(subject, WriteModification.class);
+            assertModification(transaction, WriteModification.class);
 
             //unserialized write
-            subject.tell(new WriteData(TestModel.TEST_PATH,
+            transaction.tell(new WriteData(TestModel.TEST_PATH,
                 ImmutableNodes.containerNode(TestModel.TEST_QNAME),
                 TestModel.createTestContext()),
                 getRef());
@@ -257,20 +255,18 @@ public class ShardTransactionTest extends AbstractActorTest {
             final ActorRef shard = createShard();
             final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard,
                     testSchemaContext, datastoreContext, shardStats, "txn");
-            final ActorRef subject =
-                getSystem().actorOf(props, "testMergeData");
+            final ActorRef transaction = getSystem().actorOf(props, "testMergeData");
 
-            subject.tell(new MergeData(TestModel.TEST_PATH,
+            transaction.tell(new MergeData(TestModel.TEST_PATH,
                 ImmutableNodes.containerNode(TestModel.TEST_QNAME), testSchemaContext).toSerializable(),
                 getRef());
 
-            ShardTransactionMessages.MergeDataReply replySerialized =
-                expectMsgClass(duration("5 seconds"), ShardTransactionMessages.MergeDataReply.class);
+            expectMsgClass(duration("5 seconds"), ShardTransactionMessages.MergeDataReply.class);
 
-            assertModification(subject, MergeModification.class);
+            assertModification(transaction, MergeModification.class);
 
             //unserialized merge
-            subject.tell(new MergeData(TestModel.TEST_PATH,
+            transaction.tell(new MergeData(TestModel.TEST_PATH,
                 ImmutableNodes.containerNode(TestModel.TEST_QNAME), testSchemaContext),
                 getRef());
 
@@ -284,18 +280,16 @@ public class ShardTransactionTest extends AbstractActorTest {
             final ActorRef shard = createShard();
             final Props props = ShardTransaction.props( store.newWriteOnlyTransaction(), shard,
                     testSchemaContext, datastoreContext, shardStats, "txn");
-            final ActorRef subject =
-                getSystem().actorOf(props, "testDeleteData");
+            final ActorRef transaction = getSystem().actorOf(props, "testDeleteData");
 
-            subject.tell(new DeleteData(TestModel.TEST_PATH).toSerializable(), getRef());
+            transaction.tell(new DeleteData(TestModel.TEST_PATH).toSerializable(), getRef());
 
-            ShardTransactionMessages.DeleteDataReply replySerialized =
-                expectMsgClass(duration("5 seconds"), ShardTransactionMessages.DeleteDataReply.class);
+            expectMsgClass(duration("5 seconds"), ShardTransactionMessages.DeleteDataReply.class);
 
-            assertModification(subject, DeleteModification.class);
+            assertModification(transaction, DeleteModification.class);
 
             //unserialized merge
-            subject.tell(new DeleteData(TestModel.TEST_PATH), getRef());
+            transaction.tell(new DeleteData(TestModel.TEST_PATH), getRef());
 
             expectMsgClass(duration("5 seconds"), DeleteDataReply.class);
         }};
@@ -308,12 +302,16 @@ public class ShardTransactionTest extends AbstractActorTest {
             final ActorRef shard = createShard();
             final Props props = ShardTransaction.props( store.newReadWriteTransaction(), shard,
                     testSchemaContext, datastoreContext, shardStats, "txn");
-            final ActorRef subject =
-                getSystem().actorOf(props, "testReadyTransaction");
+            final ActorRef transaction = getSystem().actorOf(props, "testReadyTransaction");
 
-            subject.tell(new ReadyTransaction().toSerializable(), getRef());
+            watch(transaction);
 
-            expectMsgClass(duration("5 seconds"), ReadyTransactionReply.SERIALIZABLE_CLASS);
+            transaction.tell(new ReadyTransaction().toSerializable(), getRef());
+
+            expectMsgAnyClassOf(duration("5 seconds"), ReadyTransactionReply.SERIALIZABLE_CLASS,
+                    Terminated.class);
+            expectMsgAnyClassOf(duration("5 seconds"), ReadyTransactionReply.SERIALIZABLE_CLASS,
+                    Terminated.class);
         }};
 
         // test
@@ -321,12 +319,16 @@ public class ShardTransactionTest extends AbstractActorTest {
             final ActorRef shard = createShard();
             final Props props = ShardTransaction.props( store.newReadWriteTransaction(), shard,
                 testSchemaContext, datastoreContext, shardStats, "txn");
-            final ActorRef subject =
-                getSystem().actorOf(props, "testReadyTransaction2");
+            final ActorRef transaction = getSystem().actorOf(props, "testReadyTransaction2");
+
+            watch(transaction);
 
-            subject.tell(new ReadyTransaction(), getRef());
+            transaction.tell(new ReadyTransaction(), getRef());
 
-            expectMsgClass(duration("5 seconds"), ReadyTransactionReply.class);
+            expectMsgAnyClassOf(duration("5 seconds"), ReadyTransactionReply.class,
+                    Terminated.class);
+            expectMsgAnyClassOf(duration("5 seconds"), ReadyTransactionReply.class,
+                    Terminated.class);
         }};
 
     }
@@ -338,14 +340,14 @@ public class ShardTransactionTest extends AbstractActorTest {
             final ActorRef shard = createShard();
             final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard,
                     testSchemaContext, datastoreContext, shardStats, "txn");
-            final ActorRef subject = getSystem().actorOf(props, "testCloseTransaction");
+            final ActorRef transaction = getSystem().actorOf(props, "testCloseTransaction");
 
-            watch(subject);
+            watch(transaction);
 
-            subject.tell(new CloseTransaction().toSerializable(), getRef());
+            transaction.tell(new CloseTransaction().toSerializable(), getRef());
 
             expectMsgClass(duration("3 seconds"), CloseTransactionReply.SERIALIZABLE_CLASS);
-            expectMsgClass(duration("3 seconds"), Terminated.class);
+            expectTerminated(duration("3 seconds"), transaction);
         }};
     }
 
@@ -354,9 +356,9 @@ public class ShardTransactionTest extends AbstractActorTest {
         final ActorRef shard = createShard();
         final Props props = ShardTransaction.props(store.newReadOnlyTransaction(), shard,
                 testSchemaContext, datastoreContext, shardStats, "txn");
-        final TestActorRef subject = TestActorRef.apply(props,getSystem());
+        final TestActorRef<ShardTransaction> transaction = TestActorRef.apply(props,getSystem());
 
-        subject.receive(new DeleteData(TestModel.TEST_PATH).toSerializable(), ActorRef.noSender());
+        transaction.receive(new DeleteData(TestModel.TEST_PATH).toSerializable(), ActorRef.noSender());
     }
 
     @Test
@@ -369,26 +371,12 @@ public class ShardTransactionTest extends AbstractActorTest {
             final ActorRef shard = createShard();
             final Props props = ShardTransaction.props(store.newReadWriteTransaction(), shard,
                     testSchemaContext, datastoreContext, shardStats, "txn");
-            final ActorRef subject =
+            final ActorRef transaction =
                 getSystem().actorOf(props, "testShardTransactionInactivity");
 
-            watch(subject);
+            watch(transaction);
 
-            // The shard Tx actor should receive a ReceiveTimeout message and self-destruct.
-
-            final String termination = new ExpectMsg<String>(duration("3 seconds"), "match hint") {
-                // do not put code outside this method, will run afterwards
-                @Override
-                protected String match(Object in) {
-                    if (in instanceof Terminated) {
-                        return "match";
-                    } else {
-                        throw noMatch();
-                    }
-                }
-            }.get(); // this extracts the received message
-
-            assertEquals("match", termination);
+            expectMsgClass(duration("3 seconds"), Terminated.class);
         }};
     }
 }