Unit tests for controller RequestException 38/52638/9
authormiroslav.kovac <miroslav.kovac@pantheon.tech>
Thu, 2 Mar 2017 11:56:19 +0000 (12:56 +0100)
committerTom Pantelis <tpanteli@brocade.com>
Tue, 7 Mar 2017 15:22:05 +0000 (15:22 +0000)
Change-Id: Ic8c0768a28fb9aa3656358668656a8d3b34639b1
Signed-off-by: miroslav.kovac <miroslav.kovac@pantheon.tech>
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/DeadHistoryExceptionTest.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/DeadTransactionExceptionTest.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/NotLeaderExceptionTest.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/OutOfOrderRequestExceptionTest.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/UnknownHistoryExceptionTest.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/RequestExceptionTest.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/RetiredGenerationExceptionTest.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/RuntimeRequestExceptionTest.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/UnsupportedRequestExceptionTest.java [new file with mode: 0644]

diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/DeadHistoryExceptionTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/DeadHistoryExceptionTest.java
new file mode 100644 (file)
index 0000000..595ef19
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.access.commands;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.opendaylight.controller.cluster.access.concepts.RequestExceptionTest;
+
+public class DeadHistoryExceptionTest extends RequestExceptionTest<DeadHistoryException> {
+
+    private static final DeadHistoryException OBJECT = new DeadHistoryException(100);
+
+    @Override
+    protected void isRetriable() {
+        assertTrue(OBJECT.isRetriable());
+    }
+
+    @Override
+    protected void checkMessage() {
+        final String message = OBJECT.getMessage();
+        assertTrue("Histories up to 100 are accounted for".equals(message));
+        assertNull(OBJECT.getCause());
+    }
+
+}
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/DeadTransactionExceptionTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/DeadTransactionExceptionTest.java
new file mode 100644 (file)
index 0000000..a610330
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.access.commands;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.opendaylight.controller.cluster.access.concepts.RequestException;
+import org.opendaylight.controller.cluster.access.concepts.RequestExceptionTest;
+
+public class DeadTransactionExceptionTest extends RequestExceptionTest<DeadTransactionException> {
+
+    private static final RequestException OBJECT = new DeadTransactionException(100);
+
+    @Override
+    protected void isRetriable() {
+        assertTrue(OBJECT.isRetriable());
+    }
+
+    @Override
+    protected void checkMessage() {
+        final String message = OBJECT.getMessage();
+        assertTrue("Transaction up to 100 are accounted for".equals(message));
+        assertNull(OBJECT.getCause());
+    }
+
+}
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/NotLeaderExceptionTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/NotLeaderExceptionTest.java
new file mode 100644 (file)
index 0000000..32cc72f
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.access.commands;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import akka.actor.ActorRef;
+import akka.actor.ActorSystem;
+import org.junit.Assert;
+import org.opendaylight.controller.cluster.access.concepts.RequestException;
+import org.opendaylight.controller.cluster.access.concepts.RequestExceptionTest;
+
+public class NotLeaderExceptionTest extends RequestExceptionTest<NotLeaderException> {
+
+    private static final ActorSystem ACTOR_SYSTEM = ActorSystem.apply();
+    private static final ActorRef ACTOR = new akka.testkit.TestProbe(ACTOR_SYSTEM).testActor();
+    private static final RequestException OBJECT = new NotLeaderException(ACTOR);
+
+    @Override
+    protected void isRetriable() {
+        Assert.assertFalse(OBJECT.isRetriable());
+    }
+
+    @Override
+    protected void checkMessage() {
+        final String message = OBJECT.getMessage();
+        final String checkMessage = new StringBuilder("Actor ").append(ACTOR.toString())
+                .append(" is not the current leader").toString();
+        assertTrue(checkMessage.equals(message));
+        assertNull(OBJECT.getCause());
+    }
+
+}
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/OutOfOrderRequestExceptionTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/OutOfOrderRequestExceptionTest.java
new file mode 100644 (file)
index 0000000..4f045ad
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.access.commands;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.opendaylight.controller.cluster.access.concepts.RequestException;
+import org.opendaylight.controller.cluster.access.concepts.RequestExceptionTest;
+
+public class OutOfOrderRequestExceptionTest extends RequestExceptionTest<OutOfOrderRequestException> {
+
+    private static final RequestException OBJECT = new OutOfOrderRequestException(100);
+
+    @Override
+    protected void isRetriable() {
+        assertTrue(OBJECT.isRetriable());
+    }
+
+    @Override
+    protected void checkMessage() {
+        final String message = OBJECT.getMessage();
+        assertTrue("Expecting request 100".equals(message));
+        assertNull(OBJECT.getCause());
+    }
+
+}
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/UnknownHistoryExceptionTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/UnknownHistoryExceptionTest.java
new file mode 100644 (file)
index 0000000..87d5fc1
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.access.commands;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.opendaylight.controller.cluster.access.concepts.RequestException;
+import org.opendaylight.controller.cluster.access.concepts.RequestExceptionTest;
+
+public class UnknownHistoryExceptionTest extends RequestExceptionTest<UnknownHistoryException> {
+
+    private static final RequestException OBJECT = new UnknownHistoryException(100L);
+    private static final RequestException OBJECT_NULL_PARAM = new UnknownHistoryException(null);
+
+    @Override
+    protected void isRetriable() {
+        assertTrue(OBJECT.isRetriable());
+    }
+
+    @Override
+    protected void checkMessage() {
+        String message = OBJECT.getMessage();
+        assertTrue("Last known history is 100".equals(message));
+        message = OBJECT_NULL_PARAM.getMessage();
+        assertTrue("Last known history is null".equals(message));
+        assertNull(OBJECT.getCause());
+    }
+
+}
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/RequestExceptionTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/RequestExceptionTest.java
new file mode 100644 (file)
index 0000000..8d5b546
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.access.concepts;
+
+import org.junit.Test;
+
+public abstract class RequestExceptionTest<T extends RequestException> {
+
+    protected abstract void isRetriable();
+
+    protected abstract void checkMessage();
+
+    @Test
+    public void testIsRetriable() {
+        isRetriable();
+    }
+
+    @Test
+    public void testExceptionMessage() {
+        checkMessage();
+    }
+
+}
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/RetiredGenerationExceptionTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/RetiredGenerationExceptionTest.java
new file mode 100644 (file)
index 0000000..1d0f016
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.access.concepts;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+public class RetiredGenerationExceptionTest extends RequestExceptionTest<RetiredGenerationException> {
+
+    private static final RequestException OBJECT = new RetiredGenerationException(100);
+
+    @Override
+    protected void isRetriable() {
+        assertFalse(OBJECT.isRetriable());
+    }
+
+    @Override
+    protected void checkMessage() {
+        final String message = OBJECT.getMessage();
+        assertTrue("Originating generation was superseded by 100".equals(message));
+        assertNull(OBJECT.getCause());
+    }
+}
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/RuntimeRequestExceptionTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/RuntimeRequestExceptionTest.java
new file mode 100644 (file)
index 0000000..27f82b8
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.access.concepts;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class RuntimeRequestExceptionTest extends RequestExceptionTest<RuntimeRequestException> {
+
+    private static final RequestException OBJECT = new RuntimeRequestException(
+            "RuntimeRequestExeption dummy message", new Throwable("throwable dummy message"));
+
+    @Override
+    protected void isRetriable() {
+        assertFalse(OBJECT.isRetriable());
+    }
+
+    @Override
+    protected void checkMessage() {
+        String message = OBJECT.getMessage();
+        assertTrue("RuntimeRequestExeption dummy message".equals(message));
+        message = OBJECT.getCause().getMessage();
+        assertTrue("throwable dummy message".equals(message));
+        assertNotNull(OBJECT.getCause());
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testFail() {
+        try {
+            //check cause can not be null
+            new RuntimeRequestException("dummy message", null);
+        } catch (final NullPointerException ex) {
+            //check message can not be null
+            new RuntimeRequestException(null, new Throwable("dummy throwable"));
+        }
+    }
+
+}
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/UnsupportedRequestExceptionTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/UnsupportedRequestExceptionTest.java
new file mode 100644 (file)
index 0000000..f054c8d
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.access.concepts;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import akka.actor.ActorRef;
+import akka.actor.ActorSystem;
+import akka.testkit.TestProbe;
+import org.opendaylight.controller.cluster.access.commands.CreateLocalHistoryRequest;
+
+public class UnsupportedRequestExceptionTest extends RequestExceptionTest<UnsupportedRequestException> {
+
+    private static final FrontendIdentifier FRONTEND =
+            new FrontendIdentifier(MemberName.forName("test"), FrontendIdentifierTest.ONE_FRONTEND_TYPE);
+    private static final ClientIdentifier CLIENT = new ClientIdentifier(FRONTEND, 0);
+
+    private static final LocalHistoryIdentifier LOCAL_HISTORY = new LocalHistoryIdentifier(CLIENT, 10);
+    private static final ActorSystem SYSTEM = ActorSystem.create("test");
+    private static final ActorRef ACTOR_REF = TestProbe.apply(SYSTEM).ref();
+    private static final Request<?, ?> REQUEST = new CreateLocalHistoryRequest(LOCAL_HISTORY, ACTOR_REF);
+    private static final RequestException OBJECT = new UnsupportedRequestException(REQUEST);
+
+    @Override
+    protected void isRetriable() {
+        assertFalse(OBJECT.isRetriable());
+    }
+
+    @Override
+    protected void checkMessage() {
+        final String message = OBJECT.getMessage();
+        final String checkMessage = "Unsupported request class org.opendaylight.controller"
+                + ".cluster.access.commands.CreateLocalHistoryRequest";
+        assertTrue(checkMessage.equals(message));
+        assertNull(OBJECT.getCause());
+    }
+
+}