import org.apache.commons.lang.SerializationUtils;
import org.junit.Assert;
import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
import org.opendaylight.controller.cluster.datastore.util.TestModel;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
writer.close();
}
- @SuppressWarnings("deprecation")
@Test
public void testNormalizedNodeAndYangInstanceIdentifierStreaming() throws IOException {
writer.writeYangInstanceIdentifier(path);
- NormalizedNodeInputStreamReader reader = new NormalizedNodeInputStreamReader(
+ NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(
ByteStreams.newDataInput(byteArrayOutputStream.toByteArray()));
NormalizedNode<?,?> node = reader.readNormalizedNode();
writer.close();
}
- @SuppressWarnings("deprecation")
@Test(expected = InvalidNormalizedNodeStreamException.class, timeout = 10000)
public void testInvalidNormalizedNodeStream() throws IOException {
- byte[] protobufBytes = new NormalizedNodeToNodeCodec().encode(
- TestModel.createBaseTestContainerBuilder().build()).getNormalizedNode().toByteArray();
-
- NormalizedNodeInputStreamReader reader = new NormalizedNodeInputStreamReader(
- ByteStreams.newDataInput(protobufBytes));
+ byte[] invalidBytes = {1,2,3};
+ NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(
+ ByteStreams.newDataInput(invalidBytes));
reader.readNormalizedNode();
}
- @SuppressWarnings("deprecation")
@Test(expected = InvalidNormalizedNodeStreamException.class, timeout = 10000)
public void testInvalidYangInstanceIdentifierStream() throws IOException {
- byte[] protobufBytes = {1,2,3};
- NormalizedNodeInputStreamReader reader = new NormalizedNodeInputStreamReader(
- ByteStreams.newDataInput(protobufBytes));
+ byte[] invalidBytes = {1,2,3};
+ NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(
+ ByteStreams.newDataInput(invalidBytes));
reader.readYangInstanceIdentifier();
}
package org.opendaylight.controller.cluster.datastore.utils;
import com.google.common.base.Preconditions;
-import com.google.protobuf.InvalidProtocolBufferException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
-import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
-import org.opendaylight.controller.cluster.datastore.node.utils.stream.InvalidNormalizedNodeStreamException;
import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataInput;
import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput;
import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputOutput;
import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputStreamReader;
-import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
public static NormalizedNode<?, ?> deserializeNormalizedNode(byte [] bytes) {
try {
return tryDeserializeNormalizedNode(new DataInputStream(new ByteArrayInputStream(bytes)));
- } catch (InvalidNormalizedNodeStreamException e) {
- // Probably from legacy protobuf serialization - try that.
- try {
- NormalizedNodeMessages.Node serializedNode = NormalizedNodeMessages.Node.parseFrom(bytes);
- return new NormalizedNodeToNodeCodec().decode(serializedNode);
- } catch (InvalidProtocolBufferException e2) {
- throw new IllegalArgumentException("Error deserializing NormalizedNode", e);
- }
} catch (IOException e) {
throw new IllegalArgumentException("Error deserializing NormalizedNode", e);
}
+++ /dev/null
-/*
- * Copyright (c) 2015 Brocade Communications 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.compat;
-
-import static org.junit.Assert.assertEquals;
-
-import akka.actor.ActorRef;
-import akka.actor.PoisonPill;
-import akka.testkit.TestActorRef;
-import java.util.Collections;
-import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.AbstractShardTest;
-import org.opendaylight.controller.cluster.datastore.Shard;
-import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
-import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry;
-import org.opendaylight.controller.cluster.raft.Snapshot;
-import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
-import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
-
-/**
- * Unit tests for backwards compatibility with pre-Lithium versions.
- *
- * @author Thomas Pantelis
- */
-public class PreLithiumShardTest extends AbstractShardTest {
- @Test
- public void testApplyHelium2VersionSnapshot() throws Exception {
- TestActorRef<Shard> shard = TestActorRef.create(getSystem(), newShardProps(),
- "testApplyHelium2VersionSnapshot");
-
- NormalizedNodeToNodeCodec codec = new NormalizedNodeToNodeCodec();
-
- DataTree store = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
- store.setSchemaContext(SCHEMA_CONTEXT);
-
- writeToStore(store, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
-
- YangInstanceIdentifier root = YangInstanceIdentifier.EMPTY;
- NormalizedNode<?,?> expected = readStore(store, root);
-
- NormalizedNodeMessages.Container encode = codec.encode(expected);
-
- Snapshot snapshot = Snapshot.create(encode.getNormalizedNode().toByteString().toByteArray(),
- Collections.<ReplicatedLogEntry>emptyList(), 1, 2, 3, 4);
-
- shard.underlyingActor().getRaftActorSnapshotCohort().applySnapshot(snapshot.getState());
-
- NormalizedNode<?,?> actual = readStore(shard, root);
-
- assertEquals("Root node", expected, actual);
-
- shard.tell(PoisonPill.getInstance(), ActorRef.noSender());
- }
-}
+++ /dev/null
-/*
- * 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.md.cluster.datastore.model;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
-import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-public class SampleModelsTest {
- @Test
- public void testPeopleModel() {
- final NormalizedNode<?, ?> expected = PeopleModel.create();
-
-
- final NormalizedNodeMessages.Container node =
- new NormalizedNodeToNodeCodec()
- .encode(expected);
-
- final NormalizedNodeMessages.Node normalizedNode =
- node.getNormalizedNode();
-
- final NormalizedNode<?,?> actual = new NormalizedNodeToNodeCodec().decode(normalizedNode);
-
-
- Assert.assertEquals(expected, actual);
-
- }
-
-
- @Test
- public void testCarsModel() {
- final NormalizedNode<?, ?> expected = CarsModel.create();
-
-
- final NormalizedNodeMessages.Container node =
- new NormalizedNodeToNodeCodec()
- .encode(expected);
-
- final NormalizedNodeMessages.Node normalizedNode =
- node.getNormalizedNode();
-
- final NormalizedNode<?,?> actual = new NormalizedNodeToNodeCodec().decode(
- normalizedNode);
-
-
- Assert.assertEquals(expected, actual);
-
- }
-}