Fix unit test failures 59/22659/3
authorTom Pantelis <tpanteli@brocade.com>
Tue, 16 Jun 2015 01:11:19 +0000 (21:11 -0400)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 16 Jun 2015 08:04:03 +0000 (08:04 +0000)
A couple tests in ShardTransactionTest are failing on jenkins builds:

java.lang.AssertionError: assertion failed: expected class
org.opendaylight.controller.protobuff.messages.cohort3pc.ThreePhaseCommitCohortMessages$CommitTransactionReply,
found class akka.actor.Status$Failure
at scala.Predef$.assert(Predef.scala:179)
at
akka.testkit.TestKitBase$class.expectMsgClass_internal(TestKit.scala:424)
at
akka.testkit.TestKitBase$class.expectMsgClass(TestKit.scala:419)
at akka.testkit.TestKit.expectMsgClass(TestKit.scala:718)
at akka.testkit.JavaTestKit.expectMsgClass(JavaTestKit.java:408)
at
org.opendaylight.controller.cluster.datastore.ShardTransactionTest$14.<init>(ShardTransactionTest.java:474)
at
org.opendaylight.controller.cluster.datastore.ShardTransactionTest.testOnReceiveBatchedModificationsReadyWithImmediateCommit(ShardTransactionTest.java:454)

The tests use a "desc" leaf node but it's not defined in the test yang.
Nothing has changed in these tests so it appears there was a recent change
in yangtools to validate the node structure on put/merge.

I also fixed an intermittent timing failure in
PreLithiumShardTest#testHelium2VersionApplyStateLegacy that I see a
couple times.

Also, JsonToNnTest  has been failing on merge builds:

org.junit.ComparisonFailure: expected:<...me cont wasn't found[].> but
was:<...me cont wasn't found[ under
(urn:ietf:params:xml:ns:netconf:base:1.0)data].>
at org.junit.Assert.assertEquals(Assert.java:115)
at org.junit.Assert.assertEquals(Assert.java:144)
at
org.opendaylight.controller.sal.restconf.impl.json.to.nn.test.JsonToNnTest.incorrectTopLevelElementsTest(JsonToNnTest.java:129)

Apparently a change elsewhere added more text to the error message. I
changed the test to use the containsString matcher instead of exact
match.

Change-Id: I33ef71bce50ff39e26dcf2b443679c8eb34dd0dd
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreLithiumShardTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/TestModel.java
opendaylight/md-sal/sal-distributed-datastore/src/test/resources/odl-datastore-test.yang
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/nn/test/JsonToNnTest.java

index 07b7f0e33462dc70df6d025fb8ae36b73795b199..f5de8a129cfffd8e39cd5aabc8551e9bc72743f6 100644 (file)
@@ -133,20 +133,24 @@ public class PreLithiumShardTest extends AbstractShardTest {
 
     @Test
     public void testHelium2VersionApplyStateLegacy() throws Exception {
+        new ShardTestKit(getSystem()) {{
+            TestActorRef<Shard> shard = TestActorRef.create(getSystem(), newShardProps(),
+                    "testHelium2VersionApplyStateLegacy");
 
-        TestActorRef<Shard> shard = TestActorRef.create(getSystem(), newShardProps(), "testHelium2VersionApplyStateLegacy");
+            waitUntilLeader(shard);
 
-        NormalizedNode<?, ?> node = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+            NormalizedNode<?, ?> node = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
 
-        ApplyState applyState = new ApplyState(null, "test", new ReplicatedLogImplEntry(1, 2,
-                newLegacyByteStringPayload(new WriteModification(TestModel.TEST_PATH, node))));
+            ApplyState applyState = new ApplyState(null, "test", new ReplicatedLogImplEntry(1, 2,
+                    newLegacyByteStringPayload(new WriteModification(TestModel.TEST_PATH, node))));
 
-        shard.underlyingActor().onReceiveCommand(applyState);
+            shard.underlyingActor().onReceiveCommand(applyState);
 
-        NormalizedNode<?,?> actual = readStore(shard, TestModel.TEST_PATH);
-        assertEquals("Applied state", node, actual);
+            NormalizedNode<?,?> actual = readStore(shard, TestModel.TEST_PATH);
+            assertEquals("Applied state", node, actual);
 
-        shard.tell(PoisonPill.getInstance(), ActorRef.noSender());
+            shard.tell(PoisonPill.getInstance(), ActorRef.noSender());
+        }};
     }
 
     @Test
index 07e9b299420240fdccd12d231f256da7f4c588b2..c4fb9a11dd0a9b4bdbd9129da1ba0cd4cf759ae4 100644 (file)
@@ -35,7 +35,6 @@ public class TestModel {
     public static final QName ID_QNAME = QName.create(TEST_QNAME, "id");
     public static final QName NAME_QNAME = QName.create(TEST_QNAME, "name");
     public static final QName DESC_QNAME = QName.create(TEST_QNAME, "desc");
-    public static final QName VALUE_QNAME = QName.create(TEST_QNAME, "value");
     private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
 
     public static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier.of(TEST_QNAME);
index e36f38ea964a4d56850dd9d9f5a70a38256d0fba..98c7bb453d94b6279c4cdc302c668fafddcadb18 100644 (file)
@@ -8,6 +8,14 @@ module odl-datastore-test {
     }
 
     container test {
+        leaf name {
+            type string;
+        }
+
+        leaf desc {
+            type string;
+        }
+
         list outer-list {
             key id;
             leaf id {
index 6940a4195c19d3f97c964a62cc3bc614e44c40f0..c11a570d3491fa5ea45f715a1dc4da1b89a125bd 100644 (file)
@@ -7,18 +7,17 @@
  */
 package org.opendaylight.controller.sal.restconf.impl.json.to.nn.test;
 
+import static org.hamcrest.CoreMatchers.containsString;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-
 import java.io.IOException;
 import java.io.InputStream;
-
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
-
 import org.junit.Test;
 import org.opendaylight.controller.sal.rest.impl.JsonNormalizedNodeBodyReader;
 import org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest;
@@ -126,9 +125,8 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
             countExceptions++;
         }
         assertNotNull(exception);
-        assertEquals(
-                "Error parsing input: Schema node with name cont wasn't found.",
-                exception.getErrors().get(0).getErrorMessage());
+        assertThat(exception.getErrors().get(0).getErrorMessage(),
+                containsString("Error parsing input: Schema node with name cont wasn't found"));
 
         inputStream = this.getClass().getResourceAsStream(
                 "/json-to-nn/wrong-top-level2.json");
@@ -141,9 +139,8 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
             countExceptions++;
         }
         assertNotNull(exception);
-        assertEquals(
-                "Error parsing input: Schema node with name lst1 wasn't found.",
-                exception.getErrors().get(0).getErrorMessage());
+        assertThat(exception.getErrors().get(0).getErrorMessage(),
+                containsString("Error parsing input: Schema node with name lst1 wasn't found"));
 
         inputStream = this.getClass().getResourceAsStream(
                 "/json-to-nn/wrong-top-level3.json");
@@ -156,9 +153,8 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
             countExceptions++;
         }
         assertNotNull(exception);
-        assertEquals(
-                "Error parsing input: Schema node with name lf wasn't found.",
-                exception.getErrors().get(0).getErrorMessage());
+        assertThat(exception.getErrors().get(0).getErrorMessage(),
+                containsString("Error parsing input: Schema node with name lf wasn't found"));
         assertEquals(3, countExceptions);
     }