X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=test-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Ftestcommon%2FAbstractDropTest.java;h=00600cdb17c9b455051366614629a3e4933bb441;hb=28f2bced3075329036dff49feaa771c8f7e24a9e;hp=2f48d20eb143816f43c327e029c9a8f398aa30cc;hpb=6aefd793fa213511f779521c7dde1f293359f9da;p=openflowplugin.git diff --git a/test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/AbstractDropTest.java b/test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/AbstractDropTest.java index 2f48d20eb1..00600cdb17 100644 --- a/test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/AbstractDropTest.java +++ b/test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/AbstractDropTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -8,17 +8,17 @@ package org.opendaylight.openflowplugin.testcommon; import static org.opendaylight.openflowjava.util.ByteBufUtils.macAddressToString; + import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.util.Arrays; import java.util.Collections; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ExecutorService; import java.util.concurrent.RejectedExecutionException; -import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder; @@ -56,49 +56,54 @@ abstract class AbstractDropTest implements PacketProcessingListener, AutoCloseab static final int STARTUP_LOOP_MAX_RETRIES = 8; private static final int PROCESSING_POOL_SIZE = 10000; - private final int POOL_THREAD_AMOUNT = 8; + private static final int POOL_THREAD_AMOUNT = 8; private final ExecutorService executorService; - private static final AtomicIntegerFieldUpdater SENT_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "sent"); + private static final AtomicIntegerFieldUpdater SENT_UPDATER = AtomicIntegerFieldUpdater + .newUpdater(AbstractDropTest.class, "sent"); private volatile int sent; - private static final AtomicIntegerFieldUpdater RCVD_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "rcvd"); + private static final AtomicIntegerFieldUpdater RCVD_UPDATER = AtomicIntegerFieldUpdater + .newUpdater(AbstractDropTest.class, "rcvd"); private volatile int rcvd; - private static final AtomicIntegerFieldUpdater EXCS_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "excs"); + private static final AtomicIntegerFieldUpdater EXCS_UPDATER = AtomicIntegerFieldUpdater + .newUpdater(AbstractDropTest.class, "excs"); private volatile int excs; - protected static final AtomicIntegerFieldUpdater RPC_FUTURE_SUCCESS_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "ftrSuccess"); + protected static final AtomicIntegerFieldUpdater RPC_FUTURE_SUCCESS_UPDATER = + AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "ftrSuccess"); protected volatile int ftrSuccess; - protected static final AtomicIntegerFieldUpdater RPC_FUTURE_FAIL_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "ftrFailed"); + protected static final AtomicIntegerFieldUpdater RPC_FUTURE_FAIL_UPDATER = + AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "ftrFailed"); protected volatile int ftrFailed; - protected static final AtomicIntegerFieldUpdater RUNABLES_EXECUTED = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "runablesExecuted"); + protected static final AtomicIntegerFieldUpdater RUNABLES_EXECUTED = AtomicIntegerFieldUpdater + .newUpdater(AbstractDropTest.class, "runablesExecuted"); protected volatile int runablesExecuted; - protected static final AtomicIntegerFieldUpdater RUNABLES_REJECTED = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "runablesRejected"); + protected static final AtomicIntegerFieldUpdater RUNABLES_REJECTED = AtomicIntegerFieldUpdater + .newUpdater(AbstractDropTest.class, "runablesRejected"); protected volatile int runablesRejected; public final DropTestStats getStats() { - return new DropTestStats(this.sent, this.rcvd, this.excs, this.ftrFailed, this.ftrSuccess, this.runablesExecuted, this.runablesRejected); + return new DropTestStats(this.sent, this.rcvd, this.excs, this.ftrFailed, this.ftrSuccess, + this.runablesExecuted, this.runablesRejected); } - public AbstractDropTest() { - final ArrayBlockingQueue workQueue = new ArrayBlockingQueue(PROCESSING_POOL_SIZE); + AbstractDropTest() { + final ArrayBlockingQueue workQueue = new ArrayBlockingQueue<>(PROCESSING_POOL_SIZE); final ThreadPoolExecutor threadPool = new ThreadPoolExecutor(POOL_THREAD_AMOUNT, POOL_THREAD_AMOUNT, 0, TimeUnit.MILLISECONDS, workQueue); threadPool.setThreadFactory(new ThreadFactoryBuilder().setNameFormat("dropTest-%d").build()); - threadPool.setRejectedExecutionHandler(new RejectedExecutionHandler() { - @Override - public void rejectedExecution(final Runnable r, final ThreadPoolExecutor executor) { - try { - workQueue.put(r); - } catch (final InterruptedException e) { - throw new RejectedExecutionException("Interrupted while waiting on queue", e); - } + threadPool.setRejectedExecutionHandler((rejected, executor) -> { + try { + workQueue.put(rejected); + } catch (final InterruptedException e) { + throw new RejectedExecutionException("Interrupted while waiting on queue", e); } }); @@ -115,11 +120,11 @@ abstract class AbstractDropTest implements PacketProcessingListener, AutoCloseab this.runablesRejected = 0; } - private final void incrementRunableExecuted() { + private void incrementRunableExecuted() { RUNABLES_EXECUTED.incrementAndGet(this); } - private final void incrementRunableRejected() { + private void incrementRunableRejected() { RUNABLES_REJECTED.incrementAndGet(this); } @@ -130,24 +135,22 @@ abstract class AbstractDropTest implements PacketProcessingListener, AutoCloseab RCVD_UPDATER.incrementAndGet(this); try { - executorService.submit(new Runnable() { - @Override - public void run() { - incrementRunableExecuted(); - processPacket(notification); - } + executorService.execute(() -> { + incrementRunableExecuted(); + processPacket(notification); }); - } catch (final Exception e) { + } catch (RejectedExecutionException e) { incrementRunableRejected(); } - LOG.debug("onPacketReceived - Leaving", notification); + LOG.debug("onPacketReceived - {} Leaving", notification); } private static final Instructions DROP_INSTRUCTIONS = makeStaticDropActionInstructions(); private static Instructions makeStaticDropActionInstructions() { // Create an DropAction - final DropActionCase dropAction = new DropActionCaseBuilder().setDropAction(new DropActionBuilder().build()).build(); + final DropActionCase dropAction = new DropActionCaseBuilder().setDropAction( + new DropActionBuilder().build()).build(); // Create an Action final Action ab = new ActionBuilder().setOrder(0).setAction(dropAction).build(); // Create an Apply Action @@ -159,6 +162,7 @@ abstract class AbstractDropTest implements PacketProcessingListener, AutoCloseab return new InstructionsBuilder().setInstruction(Collections.singletonList(ib)).build(); } + @SuppressWarnings("checkstyle:IllegalCatch") private void processPacket(final PacketReceived notification) { try { final byte[] rawPacket = notification.getPayload(); @@ -184,7 +188,7 @@ abstract class AbstractDropTest implements PacketProcessingListener, AutoCloseab processPacket(ncri.firstIdentifierOf(Node.class), match.build(), DROP_INSTRUCTIONS); SENT_UPDATER.incrementAndGet(this); - } catch (final Exception e) { + } catch (RuntimeException e) { LOG.warn("Failed to process packet: {}", e.getMessage()); LOG.debug("Failed to process packet.. ", e); EXCS_UPDATER.incrementAndGet(this);