From: Tom Pantelis Date: Tue, 16 Jun 2015 01:11:19 +0000 (-0400) Subject: Fix unit test failures X-Git-Tag: release/lithium~16 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=99973eb4479ddffb11beb604e509e661f04f1a9d Fix unit test failures 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.(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 --- diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreLithiumShardTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreLithiumShardTest.java index 07b7f0e334..f5de8a129c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreLithiumShardTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreLithiumShardTest.java @@ -133,20 +133,24 @@ public class PreLithiumShardTest extends AbstractShardTest { @Test public void testHelium2VersionApplyStateLegacy() throws Exception { + new ShardTestKit(getSystem()) {{ + TestActorRef shard = TestActorRef.create(getSystem(), newShardProps(), + "testHelium2VersionApplyStateLegacy"); - TestActorRef 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 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/TestModel.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/TestModel.java index 07e9b29942..c4fb9a11dd 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/TestModel.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/TestModel.java @@ -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); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/resources/odl-datastore-test.yang b/opendaylight/md-sal/sal-distributed-datastore/src/test/resources/odl-datastore-test.yang index e36f38ea96..98c7bb453d 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/resources/odl-datastore-test.yang +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/resources/odl-datastore-test.yang @@ -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 { diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/nn/test/JsonToNnTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/nn/test/JsonToNnTest.java index 6940a4195c..c11a570d34 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/nn/test/JsonToNnTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/nn/test/JsonToNnTest.java @@ -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); }