--- /dev/null
+/*
+ * 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());
+ }
+
+}
--- /dev/null
+/*
+ * 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());
+ }
+
+}
--- /dev/null
+/*
+ * 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());
+ }
+
+}
--- /dev/null
+/*
+ * 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());
+ }
+
+}
--- /dev/null
+/*
+ * 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());
+ }
+
+}
--- /dev/null
+/*
+ * 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();
+ }
+
+}
--- /dev/null
+/*
+ * 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());
+ }
+}
--- /dev/null
+/*
+ * 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"));
+ }
+ }
+
+}
--- /dev/null
+/*
+ * 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());
+ }
+
+}