From f935d94ef4071ad57e87173e71b1ae9188e49324 Mon Sep 17 00:00:00 2001 From: "miroslav.kovac" Date: Thu, 2 Mar 2017 12:56:19 +0100 Subject: [PATCH] Unit tests for controller RequestException Change-Id: Ic8c0768a28fb9aa3656358668656a8d3b34639b1 Signed-off-by: miroslav.kovac --- .../commands/DeadHistoryExceptionTest.java | 31 +++++++++++++ .../DeadTransactionExceptionTest.java | 32 +++++++++++++ .../commands/NotLeaderExceptionTest.java | 39 ++++++++++++++++ .../OutOfOrderRequestExceptionTest.java | 32 +++++++++++++ .../commands/UnknownHistoryExceptionTest.java | 35 ++++++++++++++ .../access/concepts/RequestExceptionTest.java | 28 +++++++++++ .../RetiredGenerationExceptionTest.java | 29 ++++++++++++ .../concepts/RuntimeRequestExceptionTest.java | 46 +++++++++++++++++++ .../UnsupportedRequestExceptionTest.java | 45 ++++++++++++++++++ 9 files changed, 317 insertions(+) create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/DeadHistoryExceptionTest.java create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/DeadTransactionExceptionTest.java create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/NotLeaderExceptionTest.java create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/OutOfOrderRequestExceptionTest.java create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/UnknownHistoryExceptionTest.java create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/RequestExceptionTest.java create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/RetiredGenerationExceptionTest.java create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/RuntimeRequestExceptionTest.java create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/UnsupportedRequestExceptionTest.java 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 index 0000000000..595ef1902b --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/DeadHistoryExceptionTest.java @@ -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 { + + 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 index 0000000000..a610330694 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/DeadTransactionExceptionTest.java @@ -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 { + + 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 index 0000000000..32cc72f13a --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/NotLeaderExceptionTest.java @@ -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 { + + 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 index 0000000000..4f045adbd8 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/OutOfOrderRequestExceptionTest.java @@ -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 { + + 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 index 0000000000..87d5fc139f --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/UnknownHistoryExceptionTest.java @@ -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 { + + 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 index 0000000000..8d5b5460a7 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/RequestExceptionTest.java @@ -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 { + + 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 index 0000000000..1d0f016ce7 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/RetiredGenerationExceptionTest.java @@ -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 { + + 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 index 0000000000..27f82b83bf --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/RuntimeRequestExceptionTest.java @@ -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 { + + 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 index 0000000000..f054c8d9bc --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/UnsupportedRequestExceptionTest.java @@ -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 { + + 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()); + } + +} -- 2.36.6