From: Robert Varga Date: Sun, 4 Jun 2017 06:43:11 +0000 (+0200) Subject: Fix eclipse/checkstyle warnings X-Git-Tag: release/nitrogen~97 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=6bb7f3a20168a59eeeea366d7d30fa29702e522f;p=yangtools.git Fix eclipse/checkstyle warnings concepts/util should have their checkstyle enforced. Change-Id: I752ce3c75e69446a1284b511b5221553d7187bb5 Signed-off-by: Robert Varga --- diff --git a/common/concepts/pom.xml b/common/concepts/pom.xml index 15d742191f..c6155284fd 100644 --- a/common/concepts/pom.xml +++ b/common/concepts/pom.xml @@ -41,25 +41,25 @@ org.apache.maven.plugins maven-checkstyle-plugin - true + checkstyle.violationSeverity=error - - ${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/ + The following configuration is necessary for maven-site-plugin to + correctly identify the correct deployment path for OpenDaylight Maven + sites. + --> + ${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/ - - - opendaylight-site - ${nexus.site.url}/${project.artifactId}/ - - + + + opendaylight-site + ${nexus.site.url}/${project.artifactId}/ + + diff --git a/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/Identifiable.java b/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/Identifiable.java index 99d6b77197..2e1d5c1e89 100644 --- a/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/Identifiable.java +++ b/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/Identifiable.java @@ -11,7 +11,7 @@ import javax.annotation.Nonnull; public interface Identifiable { /** - * Return this objects Identifier + * Return this objects Identifier. * * @return Object's identifier, must not be null. */ diff --git a/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/SemVer.java b/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/SemVer.java index 234c1469c3..ea4813a051 100644 --- a/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/SemVer.java +++ b/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/SemVer.java @@ -55,10 +55,9 @@ public final class SemVer implements Comparable, Serializable { if (patchIdx == -1) { minorStr = str.substring(minorIdx + 1); return create(Integer.parseInt(str.substring(0, minorIdx), 10), Integer.parseInt(minorStr, 10)); - } else { - minorStr = str.substring(minorIdx + 1, patchIdx); } + minorStr = str.substring(minorIdx + 1, patchIdx); return create(Integer.parseInt(str.substring(0, minorIdx), 10), Integer.parseInt(minorStr, 10), Integer.parseInt(str.substring(patchIdx + 1), 10)); } diff --git a/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/WritableObjects.java b/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/WritableObjects.java index 57a3714257..7d22ec2116 100644 --- a/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/WritableObjects.java +++ b/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/WritableObjects.java @@ -56,7 +56,7 @@ public final class WritableObjects { * @throws NullPointerException if output is null */ public static void writeLong(final DataOutput out, final long value, final int flags) throws IOException { - Preconditions.checkArgument((flags & 0xFFFFFF0F) == 0, "Invalid flags {}", flags); + Preconditions.checkArgument((flags & 0xFFFFFF0F) == 0, "Invalid flags %s", flags); final int bytes = valueBytes(value); out.writeByte(bytes | flags); writeValue(out, value, bytes); @@ -109,27 +109,27 @@ public final class WritableObjects { */ public static long readLongBody(final @Nonnull DataInput in, final byte header) throws IOException { int bytes = header & 0xF; - if (bytes < 8) { - if (bytes > 0) { - long value = 0; - if (bytes >= 4) { - bytes -= 4; - value = (in.readInt() & 0xFFFFFFFFL) << (bytes * Byte.SIZE); - } - if (bytes >= 2) { - bytes -= 2; - value |= in.readUnsignedShort() << (bytes * Byte.SIZE); - } - if (bytes > 0) { - value |= in.readUnsignedByte(); - } - return value; - } else { - return 0; - } - } else { + if (bytes >= 8) { return in.readLong(); } + + if (bytes <= 0) { + return 0; + } + + long value = 0; + if (bytes >= 4) { + bytes -= 4; + value = (in.readInt() & 0xFFFFFFFFL) << bytes * Byte.SIZE; + } + if (bytes >= 2) { + bytes -= 2; + value |= in.readUnsignedShort() << bytes * Byte.SIZE; + } + if (bytes > 0) { + value |= in.readUnsignedByte(); + } + return value; } /** @@ -183,11 +183,11 @@ public final class WritableObjects { int left = bytes; if (left >= 4) { left -= 4; - out.writeInt((int)(value >>> (left * Byte.SIZE))); + out.writeInt((int)(value >>> left * Byte.SIZE)); } if (left >= 2) { left -= 2; - out.writeShort((int)(value >>> (left * Byte.SIZE))); + out.writeShort((int)(value >>> left * Byte.SIZE)); } if (left > 0) { out.writeByte((int)(value & 0xFF)); @@ -203,15 +203,13 @@ public final class WritableObjects { if ((value & 0xFFFFFFFF00000000L) != 0) { if ((value & 0xFFFF000000000000L) != 0) { return (value & 0xFF00000000000000L) != 0 ? 8 : 7; - } else { - return (value & 0x0000FF0000000000L) != 0 ? 6 : 5; } + return (value & 0x0000FF0000000000L) != 0 ? 6 : 5; } else if ((value & 0x00000000FFFFFFFFL) != 0) { if ((value & 0x00000000FFFF0000L) != 0) { return (value & 0x00000000FF000000L) != 0 ? 4 : 3; - } else { - return (value & 0x000000000000FF00L) != 0 ? 2 : 1; } + return (value & 0x000000000000FF00L) != 0 ? 2 : 1; } else { return 0; } diff --git a/common/testutils/pom.xml b/common/testutils/pom.xml index f51392450a..2e757f8bff 100644 --- a/common/testutils/pom.xml +++ b/common/testutils/pom.xml @@ -1,68 +1,80 @@ - 4.0.0 + 4.0.0 - - org.opendaylight.odlparent - bundle-parent - 1.9.0-SNAPSHOT - - + + org.opendaylight.odlparent + bundle-parent + 1.9.0-SNAPSHOT + + - org.opendaylight.yangtools - testutils - 1.2.0-SNAPSHOT - + org.opendaylight.yangtools + testutils + 1.2.0-SNAPSHOT + - - - - org.opendaylight.yangtools - yangtools-artifacts - ${project.version} - import - pom - - - + + + + org.opendaylight.yangtools + yangtools-artifacts + ${project.version} + import + pom + + + - - - - org.slf4j - slf4j-api - - - org.slf4j - slf4j-simple - - - junit - junit - - - org.mockito - mockito-core - compile - - - com.google.truth - truth - - - com.google.guava - guava - + As this test helper project is intended to itself be used as a test + so that the utility code in src/main/java of this project can + be used to write src/test/java code in projects using it, all + here are compile here (the default, don't mention it), and NOT test. + (Only a which only this project would want to use in its own src/test/java code + but not expose to projects depending on it would be test. However that kind of against + the whole point of this project, and currently there no such dependencies here. + --> + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-simple + + + junit + junit + + + org.mockito + mockito-core + compile + + + com.google.truth + truth + + + com.google.guava + guava + - + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + checkstyle.violationSeverity=error + + + + diff --git a/common/util/pom.xml b/common/util/pom.xml index 4f505a8ab0..3b17501382 100644 --- a/common/util/pom.xml +++ b/common/util/pom.xml @@ -64,19 +64,31 @@ - - ${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/ + + ${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/ + + + + opendaylight-site + ${nexus.site.url}/${project.artifactId}/ + + diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/AbstractIdentifier.java b/common/util/src/main/java/org/opendaylight/yangtools/util/AbstractIdentifier.java index dbe5ca69ef..49a05cf50d 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/AbstractIdentifier.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/AbstractIdentifier.java @@ -38,15 +38,15 @@ public abstract class AbstractIdentifier implements Identifier { } @Override - public final boolean equals(final Object o) { - if (this == o) { + public final boolean equals(final Object obj) { + if (this == obj) { return true; } - if (o == null) { + if (obj == null) { return false; } - return getClass().equals(o.getClass()) && value.equals(((AbstractIdentifier)o).value); + return getClass().equals(obj.getClass()) && value.equals(((AbstractIdentifier)obj).value); } @Override diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/AbstractStringIdentifier.java b/common/util/src/main/java/org/opendaylight/yangtools/util/AbstractStringIdentifier.java index a72c253bcd..3d1cd4d057 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/AbstractStringIdentifier.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/AbstractStringIdentifier.java @@ -27,6 +27,7 @@ public abstract class AbstractStringIdentifier } @Override + @SuppressWarnings("checkstyle:parameterName") public final int compareTo(@Nonnull final T o) { return getValue().compareTo(o.getValue()); } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java index 6e65b03658..cef9e469f3 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ClassLoaderUtils.java @@ -33,7 +33,8 @@ public final class ClassLoaderUtils { /** * Runs {@link Supplier} with provided {@link ClassLoader}. * - *

Invokes supplies function and makes sure that original {@link ClassLoader} + *

+ * Invokes supplies function and makes sure that original {@link ClassLoader} * is context {@link ClassLoader} after execution. * * @param cls {@link ClassLoader} to be used. @@ -57,6 +58,7 @@ public final class ClassLoaderUtils { /** * Runs {@link Callable} with provided {@link ClassLoader}. * + *

* Invokes supplies function and makes sure that original {@link ClassLoader} * is context {@link ClassLoader} after execution. * diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ConstantArrayCollection.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ConstantArrayCollection.java index b8dae240da..56ebc36a57 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ConstantArrayCollection.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ConstantArrayCollection.java @@ -43,6 +43,7 @@ final class ConstantArrayCollection implements Collection, Serializable { } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean contains(final Object o) { for (Object wlk : array) { if (o.equals(wlk)) { @@ -56,19 +57,19 @@ final class ConstantArrayCollection implements Collection, Serializable { @Override public Iterator iterator() { return new UnmodifiableIterator() { - private int i = 0; + private int offset = 0; @Override public boolean hasNext() { - return i < array.length; + return offset < array.length; } @Override public E next() { - if (i >= array.length) { + if (offset >= array.length) { throw new NoSuchElementException(); } - return array[i++]; + return array[offset++]; } }; } @@ -80,7 +81,7 @@ final class ConstantArrayCollection implements Collection, Serializable { } @Nonnull - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "checkstyle:parameterName" }) @Override public T[] toArray(@Nonnull final T[] a) { if (a.length < array.length) { @@ -95,16 +96,19 @@ final class ConstantArrayCollection implements Collection, Serializable { } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean add(final E e) { throw new UnsupportedOperationException(); } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean remove(final Object o) { throw new UnsupportedOperationException(); } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean containsAll(@Nonnull final Collection c) { for (Object o : c) { if (!contains(o)) { @@ -116,16 +120,19 @@ final class ConstantArrayCollection implements Collection, Serializable { } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean addAll(@Nonnull final Collection c) { throw new UnsupportedOperationException(); } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean removeAll(@Nonnull final Collection c) { throw new UnsupportedOperationException(); } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean retainAll(@Nonnull final Collection c) { throw new UnsupportedOperationException(); } @@ -163,10 +170,10 @@ final class ConstantArrayCollection implements Collection, Serializable { } final StringBuilder sb = new StringBuilder("["); - int i = 0; - while (i < array.length - 1) { - sb.append(String.valueOf(array[i++])).append(", "); + int offset = 0; + while (offset < array.length - 1) { + sb.append(String.valueOf(array[offset++])).append(", "); } - return sb.append(String.valueOf(array[i])).append(']').toString(); + return sb.append(String.valueOf(array[offset])).append(']').toString(); } } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/EmptyDeque.java b/common/util/src/main/java/org/opendaylight/yangtools/util/EmptyDeque.java index 566b2c37c1..057ac520cd 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/EmptyDeque.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/EmptyDeque.java @@ -40,16 +40,19 @@ public final class EmptyDeque extends AbstractQueue implements Deque, I } @Override - public boolean offer(final E entry) { + @SuppressWarnings("checkstyle:parameterName") + public boolean offer(final E e) { return false; } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean offerFirst(final E e) { return false; } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean offerLast(final E e) { return false; } @@ -105,16 +108,19 @@ public final class EmptyDeque extends AbstractQueue implements Deque, I } @Override + @SuppressWarnings("checkstyle:parameterName") public T[] toArray(final T[] a) { return Preconditions.checkNotNull(a); } @Override + @SuppressWarnings("checkstyle:parameterName") public void addFirst(final E e) { add(e); } @Override + @SuppressWarnings("checkstyle:parameterName") public void addLast(final E e) { add(e); } @@ -140,16 +146,19 @@ public final class EmptyDeque extends AbstractQueue implements Deque, I } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean removeFirstOccurrence(final Object o) { return false; } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean removeLastOccurrence(final Object o) { return false; } @Override + @SuppressWarnings("checkstyle:parameterName") public void push(final E e) { addFirst(e); } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/EvenMoreObjects.java b/common/util/src/main/java/org/opendaylight/yangtools/util/EvenMoreObjects.java index 137ff43e78..47b44ae22c 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/EvenMoreObjects.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/EvenMoreObjects.java @@ -33,7 +33,7 @@ import java.util.function.BiFunction; public final class EvenMoreObjects { @SuppressWarnings("unchecked") - public static boolean equalsHelper(T self, Object other, BooleanEqualsFunction equals) { + public static boolean equalsHelper(final T self, final Object other, final BooleanEqualsFunction equals) { if (other == self) { return true; } @@ -43,7 +43,7 @@ public final class EvenMoreObjects { if (self.getClass() != other.getClass()) { return false; } - return equals.apply(self, (T) other); + return equals.apply(self, (T) other).booleanValue(); } @FunctionalInterface diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ExecutorServiceUtil.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ExecutorServiceUtil.java index e3ee6b2d38..da1a5255ae 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ExecutorServiceUtil.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ExecutorServiceUtil.java @@ -24,9 +24,10 @@ import org.slf4j.LoggerFactory; public final class ExecutorServiceUtil { private static final class WaitInQueueExecutionHandler implements RejectedExecutionHandler { @Override + @SuppressWarnings("checkstyle:parameterName") public void rejectedExecution(final Runnable r, final ThreadPoolExecutor executor) { - if (executor.isShutdown() ) { - throw new RejectedExecutionException( "Executor has been shutdown." ); + if (executor.isShutdown()) { + throw new RejectedExecutionException("Executor has been shutdown."); } try { @@ -57,6 +58,7 @@ public final class ExecutorServiceUtil { public static BlockingQueue offerFailingBlockingQueue(final BlockingQueue delegate) { return new ForwardingBlockingQueue() { @Override + @SuppressWarnings("checkstyle:parameterName") public boolean offer(@Nonnull final E o) { return false; } @@ -83,8 +85,7 @@ public final class ExecutorServiceUtil { * timeout period. If the timeout elapses before termination, the executor is forcefully * shutdown. */ - public static void tryGracefulShutdown(final ExecutorService executor, long timeout, - TimeUnit unit ) { + public static void tryGracefulShutdown(final ExecutorService executor, final long timeout, final TimeUnit unit) { executor.shutdown(); diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableOffsetMap.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableOffsetMap.java index dd5511e10e..f45bbf6f15 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableOffsetMap.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableOffsetMap.java @@ -115,36 +115,36 @@ public abstract class ImmutableOffsetMap implements UnmodifiableMapPhase Map orderedCopyOf(@Nonnull final Map m) { + @Nonnull public static Map orderedCopyOf(@Nonnull final Map map) { // Prevent a copy. Note that ImmutableMap is not listed here because of its potentially larger keySet overhead. - if (m instanceof ImmutableOffsetMap || m instanceof SharedSingletonMap) { - return m; + if (map instanceof ImmutableOffsetMap || map instanceof SharedSingletonMap) { + return map; } // Familiar and efficient to copy - if (m instanceof MutableOffsetMap) { - return ((MutableOffsetMap) m).toUnmodifiableMap(); + if (map instanceof MutableOffsetMap) { + return ((MutableOffsetMap) map).toUnmodifiableMap(); } - final int size = m.size(); + final int size = map.size(); if (size == 0) { // Shares a single object return ImmutableMap.of(); } if (size == 1) { // Efficient single-entry implementation - final Entry e = m.entrySet().iterator().next(); + final Entry e = map.entrySet().iterator().next(); return SharedSingletonMap.orderedOf(e.getKey(), e.getValue()); } - final Map offsets = OffsetMapCache.orderedOffsets(m.keySet()); + final Map offsets = OffsetMapCache.orderedOffsets(map.keySet()); @SuppressWarnings("unchecked") final V[] array = (V[]) new Object[offsets.size()]; - for (Entry e : m.entrySet()) { + for (Entry e : map.entrySet()) { array[offsets.get(e.getKey())] = e.getValue(); } @@ -162,36 +162,36 @@ public abstract class ImmutableOffsetMap implements UnmodifiableMapPhase Map unorderedCopyOf(@Nonnull final Map m) { + @Nonnull public static Map unorderedCopyOf(@Nonnull final Map map) { // Prevent a copy. Note that ImmutableMap is not listed here because of its potentially larger keySet overhead. - if (m instanceof ImmutableOffsetMap || m instanceof SharedSingletonMap) { - return m; + if (map instanceof ImmutableOffsetMap || map instanceof SharedSingletonMap) { + return map; } // Familiar and efficient to copy - if (m instanceof MutableOffsetMap) { - return ((MutableOffsetMap) m).toUnmodifiableMap(); + if (map instanceof MutableOffsetMap) { + return ((MutableOffsetMap) map).toUnmodifiableMap(); } - final int size = m.size(); + final int size = map.size(); if (size == 0) { // Shares a single object return ImmutableMap.of(); } if (size == 1) { // Efficient single-entry implementation - final Entry e = m.entrySet().iterator().next(); + final Entry e = map.entrySet().iterator().next(); return SharedSingletonMap.unorderedOf(e.getKey(), e.getValue()); } - final Map offsets = OffsetMapCache.unorderedOffsets(m.keySet()); + final Map offsets = OffsetMapCache.unorderedOffsets(map.keySet()); @SuppressWarnings("unchecked") final V[] array = (V[]) new Object[offsets.size()]; - for (Entry e : m.entrySet()) { + for (Entry e : map.entrySet()) { array[offsets.get(e.getKey())] = e.getValue(); } @@ -224,27 +224,27 @@ public abstract class ImmutableOffsetMap implements UnmodifiableMapPhase om = (ImmutableOffsetMap) o; + if (obj instanceof ImmutableOffsetMap) { + final ImmutableOffsetMap om = (ImmutableOffsetMap) obj; // If the offset match, the arrays have to match, too if (offsets.equals(om.offsets)) { return Arrays.deepEquals(objects, om.objects); } - } else if (o instanceof MutableOffsetMap) { + } else if (obj instanceof MutableOffsetMap) { // Let MutableOffsetMap do the actual work. - return o.equals(this); + return obj.equals(this); } - final Map other = (Map)o; + final Map other = (Map)obj; // Size and key sets have to match if (size() != other.size() || !keySet().equals(other.keySet())) { @@ -298,6 +298,7 @@ public abstract class ImmutableOffsetMap implements UnmodifiableMapPhase m) { throw new UnsupportedOperationException(); } @@ -328,11 +329,11 @@ public abstract class ImmutableOffsetMap implements UnmodifiableMapPhase it = offsets.keySet().iterator(); - int i = 0; + int offset = 0; while (it.hasNext()) { sb.append(it.next()); sb.append('='); - sb.append(objects[i++]); + sb.append(objects[offset++]); if (it.hasNext()) { sb.append(", "); diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/Immutables.java b/common/util/src/main/java/org/opendaylight/yangtools/util/Immutables.java index da5521f742..43be1d7045 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/Immutables.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/Immutables.java @@ -31,19 +31,19 @@ public final class Immutables { *

Note: This method may return false to immutable objects which * immutability is not known, was defined not using concepts term. * - * @param o + * @param obj * Reference to check * @return true if object is known to be immutable false otherwise. */ - public static boolean isImmutable(final Object o) { - Preconditions.checkArgument(o != null,"Object should not be null"); - if (o instanceof Mutable) { + public static boolean isImmutable(final Object obj) { + Preconditions.checkArgument(obj != null,"Object should not be null"); + if (obj instanceof Mutable) { return false; - } else if (o instanceof Immutable) { + } else if (obj instanceof Immutable) { return true; - } else if (o instanceof String) { + } else if (obj instanceof String) { return true; - } else if (KNOWN_IMMUTABLES.contains(o.getClass())) { + } else if (KNOWN_IMMUTABLES.contains(obj.getClass())) { return true; } return false; diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ListenerRegistry.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ListenerRegistry.java index 32876f6885..798f3e575b 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ListenerRegistry.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ListenerRegistry.java @@ -63,7 +63,7 @@ public class ListenerRegistry implements Iterable extends AbstractObjectRegistration

implements ListenerRegistration

{ - public ListenerRegistrationImpl(final P instance) { + ListenerRegistrationImpl(final P instance) { super(instance); } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/MapAdaptor.java b/common/util/src/main/java/org/opendaylight/yangtools/util/MapAdaptor.java index e6c23ddc05..3e5fec119d 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/MapAdaptor.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/MapAdaptor.java @@ -45,23 +45,12 @@ public final class MapAdaptor { } private static int getProperty(final String name, final int defaultValue) { - try { - final String p = System.getProperty(name); - if (p != null) { - try { - int pi = Integer.valueOf(p); - if (pi <= 0) { - LOG.warn("Ignoring illegal value of {}: has to be a positive number", name); - } else { - return pi; - } - } catch (NumberFormatException e) { - LOG.warn("Ignoring non-numerical value of {}", name, e); - } - } - } catch (Exception e) { - LOG.debug("Failed to get {}", name, e); + final int val = Integer.getInteger(name, defaultValue).intValue(); + if (val > 0) { + return val; } + + LOG.warn("Ignoring illegal value of {}: has to be a positive number", name); return defaultValue; } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/MutableOffsetMap.java b/common/util/src/main/java/org/opendaylight/yangtools/util/MutableOffsetMap.java index ef033b116f..9917de9ea2 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/MutableOffsetMap.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/MutableOffsetMap.java @@ -144,28 +144,28 @@ public abstract class MutableOffsetMap extends AbstractMap implement this.needClone = false; } - public static MutableOffsetMap orderedCopyOf(final Map m) { - if (m instanceof Ordered) { - return ((Ordered) m).clone(); + public static MutableOffsetMap orderedCopyOf(final Map map) { + if (map instanceof Ordered) { + return ((Ordered) map).clone(); } - if (m instanceof ImmutableOffsetMap) { - final ImmutableOffsetMap om = (ImmutableOffsetMap) m; + if (map instanceof ImmutableOffsetMap) { + final ImmutableOffsetMap om = (ImmutableOffsetMap) map; return new Ordered<>(om.offsets(), om.objects()); } - return new Ordered<>(m); + return new Ordered<>(map); } - public static MutableOffsetMap unorderedCopyOf(final Map m) { - if (m instanceof Unordered) { - return ((Unordered) m).clone(); + public static MutableOffsetMap unorderedCopyOf(final Map map) { + if (map instanceof Unordered) { + return ((Unordered) map).clone(); } - if (m instanceof ImmutableOffsetMap) { - final ImmutableOffsetMap om = (ImmutableOffsetMap) m; + if (map instanceof ImmutableOffsetMap) { + final ImmutableOffsetMap om = (ImmutableOffsetMap) map; return new Unordered<>(om.offsets(), om.objects()); } - return new Unordered<>(m); + return new Unordered<>(map); } public static MutableOffsetMap ordered() { @@ -365,7 +365,7 @@ public abstract class MutableOffsetMap extends AbstractMap implement // Construct the values @SuppressWarnings("unchecked") final V[] values = (V[])new Object[keyset.size()]; - int i = 0; + int offset = 0; if (removed != 0) { if (removed != offsets.size()) { for (Entry e : offsets.entrySet()) { @@ -373,16 +373,16 @@ public abstract class MutableOffsetMap extends AbstractMap implement if (o != null && !REMOVED.equals(o)) { @SuppressWarnings("unchecked") final V v = (V) o; - values[i++] = v; + values[offset++] = v; } } } } else { System.arraycopy(objects, 0, values, 0, offsets.size()); - i = offsets.size(); + offset = offsets.size(); } for (V v : newKeys.values()) { - values[i++] = v; + values[offset++] = v; } return modifiedMap(keyset, values); @@ -419,22 +419,22 @@ public abstract class MutableOffsetMap extends AbstractMap implement } @Override - public final boolean equals(final Object o) { - if (o == this) { + public final boolean equals(final Object obj) { + if (obj == this) { return true; } - if (!(o instanceof Map)) { + if (!(obj instanceof Map)) { return false; } - if (o instanceof ImmutableOffsetMap) { - final ImmutableOffsetMap om = (ImmutableOffsetMap) o; + if (obj instanceof ImmutableOffsetMap) { + final ImmutableOffsetMap om = (ImmutableOffsetMap) obj; if (newKeys.isEmpty() && offsets.equals(om.offsets())) { return Arrays.deepEquals(objects, om.objects()); } - } else if (o instanceof MutableOffsetMap) { - final MutableOffsetMap om = (MutableOffsetMap) o; + } else if (obj instanceof MutableOffsetMap) { + final MutableOffsetMap om = (MutableOffsetMap) obj; if (offsets.equals(om.offsets)) { return Arrays.deepEquals(objects, om.objects) && newKeys.equals(om.newKeys); @@ -442,7 +442,7 @@ public abstract class MutableOffsetMap extends AbstractMap implement } // Fall back to brute map compare - final Map other = (Map)o; + final Map other = (Map)obj; // Size and key sets have to match if (size() != other.size() || !keySet().equals(other.keySet())) { @@ -460,8 +460,8 @@ public abstract class MutableOffsetMap extends AbstractMap implement // Ensure all objects are present for (Entry e : offsets.entrySet()) { - final Object obj = objects[e.getValue()]; - if (obj != null && !REMOVED.equals(obj) && !obj.equals(other.get(e.getKey()))) { + final Object val = objects[e.getValue()]; + if (val != null && !REMOVED.equals(val) && !val.equals(other.get(e.getKey()))) { return false; } } @@ -513,6 +513,7 @@ public abstract class MutableOffsetMap extends AbstractMap implement } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean contains(final Object o) { if (!(o instanceof Entry)) { return false; @@ -528,6 +529,7 @@ public abstract class MutableOffsetMap extends AbstractMap implement } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean add(final Entry e) { Preconditions.checkNotNull(e.getValue()); final V p = MutableOffsetMap.this.put(e.getKey(), e.getValue()); @@ -535,6 +537,7 @@ public abstract class MutableOffsetMap extends AbstractMap implement } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean remove(final Object o) { if (!(o instanceof Entry)) { return false; diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/OffsetMapCache.java b/common/util/src/main/java/org/opendaylight/yangtools/util/OffsetMapCache.java index 6c78c9ed6d..df6c35e3f6 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/OffsetMapCache.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/OffsetMapCache.java @@ -74,6 +74,18 @@ final class OffsetMapCache { return unorderedOffsets(args instanceof Set ? (Set)args : ImmutableSet.copyOf(args)); } + @SuppressWarnings("unchecked") + private static Map unorderedOffsets(final Set args) { + final Map existing = (Map) UNORDERED_CACHE.getIfPresent(args); + if (existing != null) { + return existing; + } + + final Map newMap = createMap(args); + final Map raced = UNORDERED_CACHE.asMap().putIfAbsent(newMap.keySet(), newMap); + return raced == null ? newMap : (Map)raced; + } + static V[] adjustedArray(final Map offsets, final List keys, final V[] array) { Verify.verify(offsets.size() == keys.size(), "Offsets %s do not match keys %s", offsets, keys); @@ -94,35 +106,23 @@ final class OffsetMapCache { private static Map createMap(final Collection keys) { final Builder b = ImmutableMap.builder(); - int i = 0; + int counter = 0; for (T arg : keys) { - b.put(arg, i++); + b.put(arg, counter++); } return b.build(); } - @SuppressWarnings("unchecked") - private static Map unorderedOffsets(final Set args) { - final Map existing = (Map) UNORDERED_CACHE.getIfPresent(args); - if (existing != null) { - return existing; - } - - final Map newMap = createMap(args); - final Map raced = UNORDERED_CACHE.asMap().putIfAbsent(newMap.keySet(), newMap); - return raced == null ? newMap : (Map)raced; - } - private static V[] adjustArray(final Map offsets, final List keys, final V[] array) { @SuppressWarnings("unchecked") final V[] ret = (V[]) Array.newInstance(array.getClass().getComponentType(), array.length); - int i = 0; + int offset = 0; for (final K k : keys) { final Integer o = Verify.verifyNotNull(offsets.get(k), "Key %s not present in offsets %s", k, offsets); - ret[o] = array[i++]; + ret[o] = array[offset++]; } return ret; diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/PropertyUtils.java b/common/util/src/main/java/org/opendaylight/yangtools/util/PropertyUtils.java index 1e4f0983ce..222d5f0c7f 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/PropertyUtils.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/PropertyUtils.java @@ -33,10 +33,10 @@ public final class PropertyUtils { * @param defaultValue the default value * @return the System property as an int or the defaultValue if not found. */ - public static int getIntSystemProperty( String propName, int defaultValue ) { + public static int getIntSystemProperty(String propName, int defaultValue) { int propValue = defaultValue; String strValue = System.getProperty(propName); - if (!Strings.isNullOrEmpty(strValue) && !strValue.trim().isEmpty() ) { + if (!Strings.isNullOrEmpty(strValue) && !strValue.trim().isEmpty()) { try { propValue = Integer.parseInt(strValue); } catch (NumberFormatException e) { diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ReadWriteTrieMap.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ReadWriteTrieMap.java index 7eeb2911ec..4d91e1812d 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ReadWriteTrieMap.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ReadWriteTrieMap.java @@ -93,6 +93,7 @@ final class ReadWriteTrieMap implements Map { } @Override + @SuppressWarnings("checkstyle:parameterName") public void putAll(@Nonnull final Map m) { for (Entry e : m.entrySet()) { put(e.getKey(), e.getValue()); @@ -121,8 +122,8 @@ final class ReadWriteTrieMap implements Map { } @Override - public boolean equals(final Object o) { - return delegate.equals(o); + public boolean equals(final Object obj) { + return delegate.equals(obj); } @Override diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/SharedSingletonMap.java b/common/util/src/main/java/org/opendaylight/yangtools/util/SharedSingletonMap.java index cb3dbe8df0..f48425a9c1 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/SharedSingletonMap.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/SharedSingletonMap.java @@ -80,17 +80,17 @@ public abstract class SharedSingletonMap implements Serializable, Unmodifi return new Unordered<>(key, value); } - public static SharedSingletonMap orderedCopyOf(final Map m) { - Preconditions.checkArgument(m.size() == 1); + public static SharedSingletonMap orderedCopyOf(final Map map) { + Preconditions.checkArgument(map.size() == 1); - final Entry e = m.entrySet().iterator().next(); + final Entry e = map.entrySet().iterator().next(); return new Ordered<>(e.getKey(), e.getValue()); } - public static SharedSingletonMap unorderedCopyOf(final Map m) { - Preconditions.checkArgument(m.size() == 1); + public static SharedSingletonMap unorderedCopyOf(final Map map) { + Preconditions.checkArgument(map.size() == 1); - final Entry e = m.entrySet().iterator().next(); + final Entry e = map.entrySet().iterator().next(); return new Unordered<>(e.getKey(), e.getValue()); } @@ -148,6 +148,7 @@ public abstract class SharedSingletonMap implements Serializable, Unmodifi } @Override + @SuppressWarnings("checkstyle:parameterName") public final void putAll(@Nonnull final Map m) { throw new UnsupportedOperationException(); } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/SingletonSet.java b/common/util/src/main/java/org/opendaylight/yangtools/util/SingletonSet.java index 958c9085e3..feebed56fa 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/SingletonSet.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/SingletonSet.java @@ -29,6 +29,7 @@ public abstract class SingletonSet implements Set, Immutable, Serializable private static final long serialVersionUID = 1L; @Override + @SuppressWarnings("checkstyle:parameterName") public boolean contains(final Object o) { return o == null; } @@ -85,7 +86,7 @@ public abstract class SingletonSet implements Set, Immutable, Serializable } @Nonnull - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "checkstyle:parameterName" }) @Override public final T[] toArray(@Nonnull final T[] a) { if (a.length > 0) { @@ -97,16 +98,19 @@ public abstract class SingletonSet implements Set, Immutable, Serializable } @Override + @SuppressWarnings("checkstyle:parameterName") public final boolean add(final E e) { throw new UnsupportedOperationException(); } @Override + @SuppressWarnings("checkstyle:parameterName") public final boolean remove(final Object o) { throw new UnsupportedOperationException(); } @Override + @SuppressWarnings("checkstyle:parameterName") public final boolean containsAll(@Nonnull final Collection c) { if (c.isEmpty()) { return true; @@ -119,16 +123,19 @@ public abstract class SingletonSet implements Set, Immutable, Serializable } @Override + @SuppressWarnings("checkstyle:parameterName") public final boolean addAll(@Nonnull final Collection c) { throw new UnsupportedOperationException(); } @Override + @SuppressWarnings("checkstyle:parameterName") public final boolean retainAll(@Nonnull final Collection c) { throw new UnsupportedOperationException(); } @Override + @SuppressWarnings("checkstyle:parameterName") public final boolean removeAll(@Nonnull final Collection c) { throw new UnsupportedOperationException(); } @@ -171,6 +178,7 @@ public abstract class SingletonSet implements Set, Immutable, Serializable } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean contains(final Object o) { return element.equals(o); } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/UnmodifiableCollection.java b/common/util/src/main/java/org/opendaylight/yangtools/util/UnmodifiableCollection.java index 96895025b0..2ae19a7a72 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/UnmodifiableCollection.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/UnmodifiableCollection.java @@ -85,6 +85,7 @@ public final class UnmodifiableCollection implements Collection, Serializa } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean contains(final Object o) { return delegate.contains(o); } @@ -95,36 +96,43 @@ public final class UnmodifiableCollection implements Collection, Serializa } @Override + @SuppressWarnings("checkstyle:parameterName") public T[] toArray(@Nonnull final T[] a) { return delegate.toArray(a); } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean containsAll(@Nonnull final Collection c) { return delegate.containsAll(c); } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean add(final E e) { throw new UnsupportedOperationException(); } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean addAll(@Nonnull final Collection c) { throw new UnsupportedOperationException(); } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean remove(final Object o) { throw new UnsupportedOperationException(); } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean removeAll(@Nonnull final Collection c) { throw new UnsupportedOperationException(); } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean retainAll(@Nonnull final Collection c) { throw new UnsupportedOperationException(); } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListeningExecutorService.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListeningExecutorService.java index b23982e310..2106e92a78 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListeningExecutorService.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListeningExecutorService.java @@ -63,9 +63,9 @@ public class AsyncNotifyingListeningExecutorService extends AbstractListeningExe * @param listenableFutureExecutor the executor used to run listener callbacks asynchronously. * If null, no executor is used. */ - public AsyncNotifyingListeningExecutorService( final ExecutorService delegate, - @Nullable final Executor listenableFutureExecutor ) { - this.delegate = Preconditions.checkNotNull( delegate ); + public AsyncNotifyingListeningExecutorService(final ExecutorService delegate, + @Nullable final Executor listenableFutureExecutor) { + this.delegate = Preconditions.checkNotNull(delegate); this.listenableFutureExecutor = listenableFutureExecutor; } @@ -74,8 +74,8 @@ public class AsyncNotifyingListeningExecutorService extends AbstractListeningExe * * @param task the Callable to execute */ - private AsyncNotifyingListenableFutureTask newFutureTask( final Callable task ) { - return AsyncNotifyingListenableFutureTask.create( task, listenableFutureExecutor ); + private AsyncNotifyingListenableFutureTask newFutureTask(final Callable task) { + return AsyncNotifyingListenableFutureTask.create(task, listenableFutureExecutor); } /** @@ -83,8 +83,8 @@ public class AsyncNotifyingListeningExecutorService extends AbstractListeningExe * * @param task the Runnable to execute */ - private AsyncNotifyingListenableFutureTask newFutureTask( final Runnable task, final T result ) { - return AsyncNotifyingListenableFutureTask.create( task, result, listenableFutureExecutor ); + private AsyncNotifyingListenableFutureTask newFutureTask(final Runnable task, final T result) { + return AsyncNotifyingListenableFutureTask.create(task, result, listenableFutureExecutor); } /** @@ -95,8 +95,8 @@ public class AsyncNotifyingListeningExecutorService extends AbstractListeningExe } @Override - public boolean awaitTermination( final long timeout, @Nonnull final TimeUnit unit ) throws InterruptedException { - return delegate.awaitTermination( timeout, unit ); + public boolean awaitTermination(final long timeout, @Nonnull final TimeUnit unit) throws InterruptedException { + return delegate.awaitTermination(timeout, unit); } @Override @@ -121,41 +121,41 @@ public class AsyncNotifyingListeningExecutorService extends AbstractListeningExe } @Override - public void execute( @Nonnull final Runnable command ) { - delegate.execute( command ); + public void execute(@Nonnull final Runnable command) { + delegate.execute(command); } @Nonnull @Override - public ListenableFuture submit( final Callable task ) { - AsyncNotifyingListenableFutureTask futureTask = newFutureTask( task ); - delegate.execute( futureTask ); + public ListenableFuture submit(final Callable task) { + AsyncNotifyingListenableFutureTask futureTask = newFutureTask(task); + delegate.execute(futureTask); return futureTask; } @Nonnull @Override - public ListenableFuture submit( final Runnable task ) { - AsyncNotifyingListenableFutureTask futureTask = newFutureTask( task, null ); - delegate.execute( futureTask ); + public ListenableFuture submit(final Runnable task) { + AsyncNotifyingListenableFutureTask futureTask = newFutureTask(task, null); + delegate.execute(futureTask); return futureTask; } @Nonnull @Override - public ListenableFuture submit( final Runnable task, final T result ) { - AsyncNotifyingListenableFutureTask futureTask = newFutureTask( task, result ); - delegate.execute( futureTask ); + public ListenableFuture submit(final Runnable task, final T result) { + AsyncNotifyingListenableFutureTask futureTask = newFutureTask(task, result); + delegate.execute(futureTask); return futureTask; } - protected ToStringHelper addToStringAttributes( final ToStringHelper toStringHelper ) { + protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { return toStringHelper; } @Override public final String toString() { - return addToStringAttributes( MoreObjects.toStringHelper( this ) - .add( "delegate", delegate ) ).toString(); + return addToStringAttributes(MoreObjects.toStringHelper(this) + .add("delegate", delegate)).toString(); } } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CachedThreadPoolExecutor.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CachedThreadPoolExecutor.java index 2ef1cd8396..5ec958eab8 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CachedThreadPoolExecutor.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CachedThreadPoolExecutor.java @@ -60,26 +60,26 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor { // been reached, the task will be rejected. We specify a RejectedTaskHandler that tries // to offer to the backing queue. If that succeeds, the task will execute as soon as a // thread becomes available. If the offer fails to the backing queue, the task is rejected. - super( 0, maximumPoolSize, IDLE_TIMEOUT_IN_SEC, TimeUnit.SECONDS, - new ExecutorQueue( maximumQueueSize ) ); + super(0, maximumPoolSize, IDLE_TIMEOUT_IN_SEC, TimeUnit.SECONDS, + new ExecutorQueue(maximumQueueSize)); - this.threadPrefix = Preconditions.checkNotNull( threadPrefix ); + this.threadPrefix = Preconditions.checkNotNull(threadPrefix); this.maximumQueueSize = maximumQueueSize; - setThreadFactory( new ThreadFactoryBuilder().setDaemon( true ) - .setNameFormat( this.threadPrefix + "-%d" ).build() ); + setThreadFactory(new ThreadFactoryBuilder().setDaemon(true) + .setNameFormat(this.threadPrefix + "-%d").build()); executorQueue = (ExecutorQueue)super.getQueue(); rejectedTaskHandler = new RejectedTaskHandler( - executorQueue.getBackingQueue(), CountingRejectedExecutionHandler.newAbortPolicy() ); - super.setRejectedExecutionHandler( rejectedTaskHandler ); + executorQueue.getBackingQueue(), CountingRejectedExecutionHandler.newAbortPolicy()); + super.setRejectedExecutionHandler(rejectedTaskHandler); } @Override - public void setRejectedExecutionHandler( final RejectedExecutionHandler handler ) { - Preconditions.checkNotNull( handler ); - rejectedTaskHandler.setDelegateRejectedExecutionHandler( handler ); + public void setRejectedExecutionHandler(final RejectedExecutionHandler handler) { + Preconditions.checkNotNull(handler); + rejectedTaskHandler.setDelegateRejectedExecutionHandler(handler); } @Override @@ -96,23 +96,23 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor { return ((TrackingLinkedBlockingQueue)executorQueue.getBackingQueue()).getLargestQueueSize(); } - protected ToStringHelper addToStringAttributes( final ToStringHelper toStringHelper ) { + protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { return toStringHelper; } @Override public final String toString() { - return addToStringAttributes( MoreObjects.toStringHelper( this ) - .add( "Thread Prefix", threadPrefix ) - .add( "Current Thread Pool Size", getPoolSize() ) - .add( "Largest Thread Pool Size", getLargestPoolSize() ) - .add( "Max Thread Pool Size", getMaximumPoolSize() ) - .add( "Current Queue Size", executorQueue.getBackingQueue().size() ) - .add( "Largest Queue Size", getLargestQueueSize() ) - .add( "Max Queue Size", maximumQueueSize ) - .add( "Active Thread Count", getActiveCount() ) - .add( "Completed Task Count", getCompletedTaskCount() ) - .add( "Total Task Count", getTaskCount() ) ).toString(); + return addToStringAttributes(MoreObjects.toStringHelper(this) + .add("Thread Prefix", threadPrefix) + .add("Current Thread Pool Size", getPoolSize()) + .add("Largest Thread Pool Size", getLargestPoolSize()) + .add("Max Thread Pool Size", getMaximumPoolSize()) + .add("Current Queue Size", executorQueue.getBackingQueue().size()) + .add("Largest Queue Size", getLargestQueueSize()) + .add("Max Queue Size", maximumQueueSize) + .add("Active Thread Count", getActiveCount()) + .add("Completed Task Count", getCompletedTaskCount()) + .add("Total Task Count", getTaskCount())).toString(); } /** @@ -130,8 +130,8 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor { private final LinkedBlockingQueue backingQueue; - ExecutorQueue( final int maxBackingQueueSize ) { - backingQueue = new TrackingLinkedBlockingQueue<>( maxBackingQueueSize ); + ExecutorQueue(final int maxBackingQueueSize) { + backingQueue = new TrackingLinkedBlockingQueue<>(maxBackingQueueSize); } LinkedBlockingQueue getBackingQueue() { @@ -139,9 +139,9 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor { } @Override - public Runnable poll( final long timeout, final TimeUnit unit ) throws InterruptedException { - long totalWaitTime = unit.toMillis( timeout ); - long waitTime = Math.min( totalWaitTime, POLL_WAIT_TIME_IN_MS ); + public Runnable poll(final long timeout, final TimeUnit unit) throws InterruptedException { + long totalWaitTime = unit.toMillis(timeout); + long waitTime = Math.min(totalWaitTime, POLL_WAIT_TIME_IN_MS); Runnable task = null; // We loop here, each time polling the backingQueue first then our queue, instead of @@ -161,14 +161,14 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor { task = backingQueue.poll(); if (task == null) { // No task in backing - call the base class to wait for one to be offered. - task = super.poll( waitTime, TimeUnit.MILLISECONDS ); + task = super.poll(waitTime, TimeUnit.MILLISECONDS); totalWaitTime -= POLL_WAIT_TIME_IN_MS; - if (totalWaitTime <= 0 ) { + if (totalWaitTime <= 0) { break; } - waitTime = Math.min( totalWaitTime, POLL_WAIT_TIME_IN_MS ); + waitTime = Math.min(totalWaitTime, POLL_WAIT_TIME_IN_MS); } } @@ -193,14 +193,14 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor { private final LinkedBlockingQueue backingQueue; private volatile RejectedExecutionHandler delegateRejectedExecutionHandler; - RejectedTaskHandler( final LinkedBlockingQueue backingQueue, - final RejectedExecutionHandler delegateRejectedExecutionHandler ) { + RejectedTaskHandler(final LinkedBlockingQueue backingQueue, + final RejectedExecutionHandler delegateRejectedExecutionHandler) { this.backingQueue = backingQueue; this.delegateRejectedExecutionHandler = delegateRejectedExecutionHandler; } void setDelegateRejectedExecutionHandler( - final RejectedExecutionHandler delegateRejectedExecutionHandler ) { + final RejectedExecutionHandler delegateRejectedExecutionHandler) { this.delegateRejectedExecutionHandler = delegateRejectedExecutionHandler; } @@ -209,13 +209,13 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor { } @Override - public void rejectedExecution( final Runnable task, final ThreadPoolExecutor executor ) { + public void rejectedExecution(final Runnable task, final ThreadPoolExecutor executor) { if (executor.isShutdown()) { - throw new RejectedExecutionException( "Executor has been shutdown." ); + throw new RejectedExecutionException("Executor has been shutdown."); } if (!backingQueue.offer(task)) { - delegateRejectedExecutionHandler.rejectedExecution( task, executor ); + delegateRejectedExecutionHandler.rejectedExecution(task, executor); } } } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CountingRejectedExecutionHandler.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CountingRejectedExecutionHandler.java index 8fd45dc310..a0d59ef451 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CountingRejectedExecutionHandler.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CountingRejectedExecutionHandler.java @@ -29,12 +29,12 @@ public class CountingRejectedExecutionHandler implements RejectedExecutionHandle * * @param delegate the backing RejectedExecutionHandler. */ - public CountingRejectedExecutionHandler( final RejectedExecutionHandler delegate ) { - this.delegate = Preconditions.checkNotNull( delegate ); + public CountingRejectedExecutionHandler(final RejectedExecutionHandler delegate) { + this.delegate = Preconditions.checkNotNull(delegate); } @Override - public void rejectedExecution( final Runnable task, final ThreadPoolExecutor executor ) { + public void rejectedExecution(final Runnable task, final ThreadPoolExecutor executor) { rejectedTaskCounter.increment(); delegate.rejectedExecution(task, executor); } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/DeadlockDetectingListeningExecutorService.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/DeadlockDetectingListeningExecutorService.java index fad71a9352..959b8d418e 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/DeadlockDetectingListeningExecutorService.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/DeadlockDetectingListeningExecutorService.java @@ -80,7 +80,7 @@ public class DeadlockDetectingListeningExecutorService extends AsyncNotifyingLis */ public DeadlockDetectingListeningExecutorService(final ExecutorService delegate, @Nonnull final Supplier deadlockExceptionSupplier, - @Nullable final Executor listenableFutureExecutor ) { + @Nullable final Executor listenableFutureExecutor) { super(delegate, listenableFutureExecutor); this.deadlockExceptionFunction = Preconditions.checkNotNull(deadlockExceptionSupplier); } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ExceptionMapper.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ExceptionMapper.java index b109b190a9..f6c37296d8 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ExceptionMapper.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ExceptionMapper.java @@ -19,7 +19,8 @@ import java.util.concurrent.ExecutionException; * *

* This mapper is intended to be used with - * {@link com.google.common.util.concurrent.Futures#makeChecked(com.google.common.util.concurrent.ListenableFuture, Function)} + * {@link com.google.common.util.concurrent.Futures#makeChecked( + * com.google.common.util.concurrent.ListenableFuture, Function)} *

    *
  • if exception is the specified type or one of its subclasses, it returns * original exception. @@ -71,34 +72,34 @@ public abstract class ExceptionMapper implements Function(maximumQueueSize) ); + super(maximumPoolSize, maximumPoolSize, keepAliveTime, unit, + new TrackingLinkedBlockingQueue<>(maximumQueueSize)); this.threadPrefix = threadPrefix; this.maximumQueueSize = maximumQueueSize; - setThreadFactory( new ThreadFactoryBuilder().setDaemon( true ) - .setNameFormat( threadPrefix + "-%d" ).build() ); + setThreadFactory(new ThreadFactoryBuilder().setDaemon(true) + .setNameFormat(threadPrefix + "-%d").build()); if (keepAliveTime > 0) { // Need to specifically configure core threads to timeout. - allowCoreThreadTimeOut( true ); + allowCoreThreadTimeOut(true); } - setRejectedExecutionHandler( CountingRejectedExecutionHandler.newAbortPolicy() ); + setRejectedExecutionHandler(CountingRejectedExecutionHandler.newAbortPolicy()); } public long getLargestQueueSize() { return ((TrackingLinkedBlockingQueue)getQueue()).getLargestQueueSize(); } - protected ToStringHelper addToStringAttributes( final ToStringHelper toStringHelper ) { + protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { return toStringHelper; } @Override public final String toString() { - return addToStringAttributes( MoreObjects.toStringHelper( this ) - .add( "Thread Prefix", threadPrefix ) - .add( "Current Thread Pool Size", getPoolSize() ) - .add( "Largest Thread Pool Size", getLargestPoolSize() ) - .add( "Max Thread Pool Size", getMaximumPoolSize() ) - .add( "Current Queue Size", getQueue().size() ) - .add( "Largest Queue Size", getLargestQueueSize() ) - .add( "Max Queue Size", maximumQueueSize ) - .add( "Active Thread Count", getActiveCount() ) - .add( "Completed Task Count", getCompletedTaskCount() ) - .add( "Total Task Count", getTaskCount() ) ).toString(); + return addToStringAttributes(MoreObjects.toStringHelper(this) + .add("Thread Prefix", threadPrefix) + .add("Current Thread Pool Size", getPoolSize()) + .add("Largest Thread Pool Size", getLargestPoolSize()) + .add("Max Thread Pool Size", getMaximumPoolSize()) + .add("Current Queue Size", getQueue().size()) + .add("Largest Queue Size", getLargestQueueSize()) + .add("Max Queue Size", maximumQueueSize) + .add("Active Thread Count", getActiveCount()) + .add("Completed Task Count", getCompletedTaskCount()) + .add("Total Task Count", getTaskCount())).toString(); } } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ListenerNotificationQueueStats.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ListenerNotificationQueueStats.java index 7da1e4bddc..50f2ca45a0 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ListenerNotificationQueueStats.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ListenerNotificationQueueStats.java @@ -23,7 +23,7 @@ public class ListenerNotificationQueueStats { private final int currentQueueSize; @ConstructorProperties({ "listenerClassName","currentQueueSize" }) - public ListenerNotificationQueueStats( final String listenerClassName, final int currentQueueSize ) { + public ListenerNotificationQueueStats(final String listenerClassName, final int currentQueueSize) { this.listenerClassName = listenerClassName; this.currentQueueSize = currentQueueSize; } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFuture.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFuture.java index 33000817cf..24001d8cd7 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFuture.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFuture.java @@ -37,9 +37,9 @@ public final class MappingCheckedFuture extends Abstract private final Function mapper; - private MappingCheckedFuture( final ListenableFuture delegate, final Function mapper ) { - super( delegate ); - this.mapper = Preconditions.checkNotNull( mapper ); + private MappingCheckedFuture(final ListenableFuture delegate, final Function mapper) { + super(delegate); + this.mapper = Preconditions.checkNotNull(mapper); } /** @@ -51,17 +51,18 @@ public final class MappingCheckedFuture extends Abstract * @return a new MappingCheckedFuture */ public static MappingCheckedFuture create( - final ListenableFuture delegate, final Function mapper ) { + final ListenableFuture delegate, final Function mapper) { return new MappingCheckedFuture<>(delegate, mapper); } @Override - protected X mapException( @Nonnull final Exception e ) { - return mapper.apply( e ); + @SuppressWarnings("checkstyle:parameterName") + protected X mapException(@Nonnull final Exception e) { + return mapper.apply(e); } - private ExecutionException wrapInExecutionException( final String message, final Exception e ) { - return new ExecutionException( message, mapException( e ) ); + private ExecutionException wrapInExecutionException(final String message, final Exception ex) { + return new ExecutionException(message, mapException(ex)); } @Override @@ -70,26 +71,26 @@ public final class MappingCheckedFuture extends Abstract return super.get(); } catch (final InterruptedException e) { Thread.currentThread().interrupt(); - throw wrapInExecutionException( "Operation was interrupted", e ); + throw wrapInExecutionException("Operation was interrupted", e); } catch (final CancellationException e) { - throw wrapInExecutionException( "Operation was cancelled", e ); + throw wrapInExecutionException("Operation was cancelled", e); } catch (final ExecutionException e) { - throw wrapInExecutionException( e.getMessage(), e ); + throw wrapInExecutionException(e.getMessage(), e); } } @Override - public V get( final long timeout, @Nonnull final TimeUnit unit ) + public V get(final long timeout, @Nonnull final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { try { - return super.get( timeout, unit ); + return super.get(timeout, unit); } catch (final InterruptedException e) { Thread.currentThread().interrupt(); - throw wrapInExecutionException( "Operation was interrupted", e ); + throw wrapInExecutionException("Operation was interrupted", e); } catch (final CancellationException e) { - throw wrapInExecutionException( "Operation was cancelled", e ); + throw wrapInExecutionException("Operation was cancelled", e); } catch (final ExecutionException e) { - throw wrapInExecutionException( e.getMessage(), e ); + throw wrapInExecutionException(e.getMessage(), e); } } } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManager.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManager.java index 5160efe9bf..c47a5884fa 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManager.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManager.java @@ -118,13 +118,14 @@ public class QueuedNotificationManager implements NotificationManager listenerInvoker, final int maxQueueCapacity, final String name) { - this(executor, (BatchedInvoker)(l, c) -> c.forEach(n -> { + this(executor, (BatchedInvoker)(listener, notifications) -> notifications.forEach(n -> { try { - listenerInvoker.invokeListener(l, n); + listenerInvoker.invokeListener(listener, n); } catch (Exception e) { - LOG.error("{}: Error notifying listener {} with {}", name, l, n, e); + LOG.error("{}: Error notifying listener {} with {}", name, listener, n, e); } }), maxQueueCapacity, name); @@ -280,7 +281,7 @@ public class QueuedNotificationManager implements NotificationManager) && listener == ((ListenerKey) obj).listener; + return obj instanceof ListenerKey && listener == ((ListenerKey) obj).listener; } @Override @@ -426,6 +427,7 @@ public class QueuedNotificationManager implements NotificationManager notifications) { LOG.debug("{}: Invoking listener {} with notification: {}", name, listenerKey, notifications); try { diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ReflectiveExceptionMapper.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ReflectiveExceptionMapper.java index b00ed4f304..36f685fafd 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ReflectiveExceptionMapper.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ReflectiveExceptionMapper.java @@ -29,7 +29,8 @@ public final class ReflectiveExceptionMapper extends Except protected X newWithCause(final String message, final Throwable cause) { try { return ctor.newInstance(message, cause); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException e) { throw new IllegalStateException("Failed to instantiate exception " + ctor.getDeclaringClass(), e); } } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/SpecialExecutors.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/SpecialExecutors.java index 929ecc0106..981c948c7e 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/SpecialExecutors.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/SpecialExecutors.java @@ -48,9 +48,9 @@ public final class SpecialExecutors { * the name prefix for threads created by this executor. * @return a new ExecutorService with the specified configuration. */ - public static ExecutorService newBoundedFastThreadPool( int maximumPoolSize, - int maximumQueueSize, String threadPrefix ) { - return new FastThreadPoolExecutor( maximumPoolSize, maximumQueueSize, threadPrefix ); + public static ExecutorService newBoundedFastThreadPool(int maximumPoolSize, + int maximumQueueSize, String threadPrefix) { + return new FastThreadPoolExecutor(maximumPoolSize, maximumQueueSize, threadPrefix); } /** @@ -68,12 +68,12 @@ public final class SpecialExecutors { * the name prefix for threads created by this executor. * @return a new ExecutorService with the specified configuration. */ - public static ExecutorService newBlockingBoundedFastThreadPool( int maximumPoolSize, - int maximumQueueSize, String threadPrefix ) { + public static ExecutorService newBlockingBoundedFastThreadPool(int maximumPoolSize, + int maximumQueueSize, String threadPrefix) { FastThreadPoolExecutor executor = - new FastThreadPoolExecutor( maximumPoolSize, maximumQueueSize, threadPrefix ); - executor.setRejectedExecutionHandler( CountingRejectedExecutionHandler.newCallerRunsPolicy() ); + new FastThreadPoolExecutor(maximumPoolSize, maximumQueueSize, threadPrefix); + executor.setRejectedExecutionHandler(CountingRejectedExecutionHandler.newCallerRunsPolicy()); return executor; } @@ -104,9 +104,9 @@ public final class SpecialExecutors { * the name prefix for threads created by this executor. * @return a new ExecutorService with the specified configuration. */ - public static ExecutorService newBoundedCachedThreadPool( int maximumPoolSize, - int maximumQueueSize, String threadPrefix ) { - return new CachedThreadPoolExecutor( maximumPoolSize, maximumQueueSize, threadPrefix ); + public static ExecutorService newBoundedCachedThreadPool(int maximumPoolSize, + int maximumQueueSize, String threadPrefix) { + return new CachedThreadPoolExecutor(maximumPoolSize, maximumQueueSize, threadPrefix); } /** @@ -124,12 +124,12 @@ public final class SpecialExecutors { * the name prefix for threads created by this executor. * @return a new ExecutorService with the specified configuration. */ - public static ExecutorService newBlockingBoundedCachedThreadPool( int maximumPoolSize, - int maximumQueueSize, String threadPrefix ) { + public static ExecutorService newBlockingBoundedCachedThreadPool(int maximumPoolSize, + int maximumQueueSize, String threadPrefix) { CachedThreadPoolExecutor executor = - new CachedThreadPoolExecutor( maximumPoolSize, maximumQueueSize, threadPrefix ); - executor.setRejectedExecutionHandler( CountingRejectedExecutionHandler.newCallerRunsPolicy() ); + new CachedThreadPoolExecutor(maximumPoolSize, maximumQueueSize, threadPrefix); + executor.setRejectedExecutionHandler(CountingRejectedExecutionHandler.newCallerRunsPolicy()); return executor; } @@ -145,9 +145,9 @@ public final class SpecialExecutors { * the name prefix for the thread created by this executor. * @return a new ExecutorService with the specified configuration. */ - public static ExecutorService newBoundedSingleThreadExecutor( int maximumQueueSize, - String threadPrefix ) { - return new FastThreadPoolExecutor( 1, maximumQueueSize, Long.MAX_VALUE, TimeUnit.SECONDS, - threadPrefix ); + public static ExecutorService newBoundedSingleThreadExecutor(int maximumQueueSize, + String threadPrefix) { + return new FastThreadPoolExecutor(1, maximumQueueSize, Long.MAX_VALUE, TimeUnit.SECONDS, + threadPrefix); } } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueue.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueue.java index dfe31f8747..9d02c1b09d 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueue.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueue.java @@ -36,23 +36,24 @@ public class TrackingLinkedBlockingQueue extends LinkedBlockingQueue { private volatile int largestQueueSize = 0; /** - * @see LinkedBlockingQueue#LinkedBlockingQueue + * See {@link LinkedBlockingQueue#LinkedBlockingQueue()}. */ public TrackingLinkedBlockingQueue() { super(); } /** - * @see LinkedBlockingQueue#LinkedBlockingQueue(Collection) + * See {@link LinkedBlockingQueue#LinkedBlockingQueue(Collection)}. */ - public TrackingLinkedBlockingQueue( final Collection c ) { + @SuppressWarnings("checkstyle:parameterName") + public TrackingLinkedBlockingQueue(final Collection c) { super(c); } /** - * @see LinkedBlockingQueue#LinkedBlockingQueue(int) + * See {@link LinkedBlockingQueue#LinkedBlockingQueue(int)}. */ - public TrackingLinkedBlockingQueue( final int capacity ) { + public TrackingLinkedBlockingQueue(final int capacity) { super(capacity); } @@ -67,8 +68,9 @@ public class TrackingLinkedBlockingQueue extends LinkedBlockingQueue { } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean offer(final E e, final long timeout, final TimeUnit unit) throws InterruptedException { - if (super.offer( e, timeout, unit ) ) { + if (super.offer(e, timeout, unit)) { updateLargestQueueSize(); return true; } @@ -77,8 +79,9 @@ public class TrackingLinkedBlockingQueue extends LinkedBlockingQueue { } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean offer(@Nonnull final E e) { - if (super.offer( e ) ) { + if (super.offer(e)) { updateLargestQueueSize(); return true; } @@ -87,22 +90,25 @@ public class TrackingLinkedBlockingQueue extends LinkedBlockingQueue { } @Override - public void put( final E e ) throws InterruptedException { - super.put( e ); + @SuppressWarnings("checkstyle:parameterName") + public void put(final E e) throws InterruptedException { + super.put(e); updateLargestQueueSize(); } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean add(final E e) { - boolean result = super.add( e ); + boolean result = super.add(e); updateLargestQueueSize(); return result; } @Override + @SuppressWarnings("checkstyle:parameterName") public boolean addAll(final Collection c) { try { - return super.addAll( c ); + return super.addAll(c); } finally { updateLargestQueueSize(); } diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/xml/UntrustedXML.java b/common/util/src/main/java/org/opendaylight/yangtools/util/xml/UntrustedXML.java index 05ef089bdb..8619875c2a 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/xml/UntrustedXML.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/xml/UntrustedXML.java @@ -22,6 +22,8 @@ import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; /** * Set of utility methods for instantiating parser that deal with untrusted XML sources. @@ -31,6 +33,7 @@ import org.xml.sax.SAXException; @Beta public final class UntrustedXML { private static final DocumentBuilderFactory DBF; + static { final DocumentBuilderFactory f = DocumentBuilderFactory.newInstance(); f.setCoalescing(true); @@ -52,6 +55,7 @@ public final class UntrustedXML { } private static final SAXParserFactory SPF; + static { final SAXParserFactory f = SAXParserFactory.newInstance(); f.setNamespaceAware(true); @@ -62,7 +66,7 @@ public final class UntrustedXML { f.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); f.setFeature("http://xml.org/sax/features/external-general-entities", false); f.setFeature("http://xml.org/sax/features/external-parameter-entities", false); - } catch (final Exception e) { + } catch (final SAXNotRecognizedException | SAXNotSupportedException | ParserConfigurationException e) { throw new ExceptionInInitializerError(e); } @@ -70,6 +74,7 @@ public final class UntrustedXML { } private static final XMLInputFactory XIF; + static { final XMLInputFactory f = XMLInputFactory.newInstance(); diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/ConstantArrayCollectionTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/ConstantArrayCollectionTest.java index 11aac6ccf0..c33c9cb705 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/ConstantArrayCollectionTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/ConstantArrayCollectionTest.java @@ -54,7 +54,7 @@ public class ConstantArrayCollectionTest { assertFalse(c.contains("")); assertFalse(c.contains(1)); - assertTrue(c.containsAll(Collections.emptyList())); + assertTrue(c.containsAll(Collections.emptyList())); assertFalse(c.containsAll(Collections.singleton(""))); assertFalse(c.containsAll(Collections.singleton(1))); } diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/DurationStatisticsTrackerTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/DurationStatisticsTrackerTest.java index 7fef4a303f..0cc3eebf68 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/DurationStatisticsTrackerTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/DurationStatisticsTrackerTest.java @@ -9,6 +9,7 @@ package org.opendaylight.yangtools.util; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -69,7 +70,7 @@ public class DurationStatisticsTrackerTest { } private static void verifyDisplayableString(final String name, final String actual, final String expPrefix) { - assertEquals(name + " starts with " + expPrefix + ". Actual: " + actual, - true, actual.startsWith(expPrefix)); + assertTrue(name + " starts with " + expPrefix + ". Actual: " + actual, + actual.startsWith(expPrefix)); } } diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/EvenMoreObjectsTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/EvenMoreObjectsTest.java index 59bcd85217..3bc5e65274 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/EvenMoreObjectsTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/EvenMoreObjectsTest.java @@ -28,16 +28,15 @@ public class EvenMoreObjectsTest { @Test public void nullEqualsNull() { - assertTrue(EvenMoreObjects.equalsHelper(null, null, (one, another) -> true)); + assertTrue(EvenMoreObjects.equalsHelper(null, null, (one, another) -> Boolean.TRUE)); } private static class Thing { - String name; Integer age; @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { return EvenMoreObjects.equalsHelper(this, obj, (one, another) -> Objects.equals(one.name, another.name) && Objects.equals(one.age, another.age)); } @@ -52,12 +51,10 @@ public class EvenMoreObjectsTest { return MoreObjects.toStringHelper(this).add("name", name).add("age", age).toString(); } - Thing(String name, Integer age) { + Thing(final String name, final Integer age) { super(); this.name = name; this.age = age; } - } - } diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/HashCodeBuilderTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/HashCodeBuilderTest.java index 1f7666a2b2..4863357d13 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/HashCodeBuilderTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/HashCodeBuilderTest.java @@ -15,13 +15,13 @@ public class HashCodeBuilderTest { @Test public void testAllMethodsOfHashCodeBuilder() { - final HashCodeBuilder hashCodeBuilder = new HashCodeBuilder<>(); - assertEquals("Default hash code should be '1'.", 1, hashCodeBuilder.build().intValue()); + final HashCodeBuilder builder = new HashCodeBuilder<>(); + assertEquals("Default hash code should be '1'.", 1, builder.build().intValue()); int nextHashCode = HashCodeBuilder.nextHashCode(1, "test"); assertEquals("Next hash code should be '3556529'.", 3556529, nextHashCode); - hashCodeBuilder.addArgument("another test"); - assertEquals("Updated internal hash code should be '700442706'.", -700442706, hashCodeBuilder.build().intValue()); + builder.addArgument("another test"); + assertEquals("Updated internal hash code should be '700442706'.", -700442706, builder.build().intValue()); } } diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/ListenerRegistryTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/ListenerRegistryTest.java index 211129262b..4c2d2ad83a 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/ListenerRegistryTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/ListenerRegistryTest.java @@ -24,7 +24,7 @@ public class ListenerRegistryTest { private TestEventListener testEventListener; private ExtendedTestEventListener extendedTestEventListener; - private ListenerRegistry listenerRegistry; + private ListenerRegistry registry; @Rule public ExpectedException expException = ExpectedException.none(); @@ -33,46 +33,48 @@ public class ListenerRegistryTest { public void init() { testEventListener = new TestEventListener() {}; extendedTestEventListener = new ExtendedTestEventListener() {}; - listenerRegistry = new ListenerRegistry<>(); + registry = new ListenerRegistry<>(); } @Test public void testCreateNewInstance() { - assertNotNull("Intance of listener registry shouldn't be null.", listenerRegistry); + assertNotNull("Intance of listener registry shouldn't be null.", registry); } @Test public void tetGetListenersMethod() { - assertTrue("Listener regisdtry should have any listeners.", Iterables.isEmpty(listenerRegistry.getListeners())); + assertTrue("Listener registry should have any listeners.", Iterables.isEmpty(registry.getListeners())); } @Test public void testRegisterMethod() { - final ListenerRegistration listenerRegistration = listenerRegistry.register(testEventListener); + final ListenerRegistration listenerRegistration = registry.register(testEventListener); assertEquals("Listeners should be the same.", testEventListener, listenerRegistration.getInstance()); expException.expect(IllegalArgumentException.class); expException.expectMessage("Listener should not be null."); - listenerRegistry.register(null); + registry.register(null); } @Test public void testRegisterWithType() { - final ListenerRegistration listenerRegistration = listenerRegistry.registerWithType(extendedTestEventListener); + final ListenerRegistration listenerRegistration = registry.registerWithType( + extendedTestEventListener); assertEquals("Listeners should be the same.", extendedTestEventListener, listenerRegistration.getInstance()); } @Test public void testIteratorMethod() { - final Iterator> listenerIterator = listenerRegistry.iterator(); + final Iterator> listenerIterator = registry.iterator(); assertNotNull("Listener iterator shouldn't be null.", listenerIterator); } @Test public void testCreateMethod() { - final ListenerRegistry emptyListenerRegistry = ListenerRegistry.create(); - assertTrue("List of listeners in listener registry should be empty.", Iterables.isEmpty(emptyListenerRegistry.getListeners())); + final ListenerRegistry emptyRegistry = ListenerRegistry.create(); + assertTrue("List of listeners in listener registry should be empty.", + Iterables.isEmpty(emptyRegistry.getListeners())); } interface TestEventListener extends EventListener { diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/ReadWriteTrieMapTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/ReadWriteTrieMapTest.java index f0d1ec8de9..8af39c471f 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/ReadWriteTrieMapTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/ReadWriteTrieMapTest.java @@ -51,13 +51,16 @@ public class ReadWriteTrieMapTest { final Collection trieMapValues = readWriteTrieMap.values(); assertEquals("Size of values should be '3'.", 3, trieMapValues.size()); - assertTrue("Entry set of readWriteTrieMap and trieMap should by equals.", convertSetEntryToMap(readWriteTrieMap.entrySet()).equals(trieMap)); + assertTrue("Entry set of readWriteTrieMap and trieMap should by equals.", + convertSetEntryToMap(readWriteTrieMap.entrySet()).equals(trieMap)); trieMap.put("2", "two"); final ReadWriteTrieMap readWriteTrieMap2 = new ReadWriteTrieMap<>(trieMap, 4); - assertFalse("Objects readWriteTrieMap and readOnlyTrieMap2 should be different.", readWriteTrieMap.equals(readWriteTrieMap2)); - assertFalse("Hash codes of object readWriteTrieMap and readOnelyTrieMap2 should be different.", readWriteTrieMap.hashCode() == readWriteTrieMap2.hashCode()); + assertFalse("Objects readWriteTrieMap and readOnlyTrieMap2 should be different.", + readWriteTrieMap.equals(readWriteTrieMap2)); + assertFalse("Hash codes of object readWriteTrieMap and readOnelyTrieMap2 should be different.", + readWriteTrieMap.hashCode() == readWriteTrieMap2.hashCode()); final Map readOnlyTrieMap = readWriteTrieMap.toReadOnly(); readWriteTrieMap.clear(); @@ -65,7 +68,7 @@ public class ReadWriteTrieMapTest { assertEquals("Size of readOnlyTrieMap should be '6'.", 6, readOnlyTrieMap.size()); } - public Map convertSetEntryToMap(Set> input) { + public Map convertSetEntryToMap(final Set> input) { Map resultMap = new HashMap<>(); for (Entry entry : input) { resultMap.put(entry.getKey(), entry.getValue()); diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/SharedSingletonMapTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/SharedSingletonMapTest.java index a8bc5b53d6..f47e859797 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/SharedSingletonMapTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/SharedSingletonMapTest.java @@ -84,32 +84,32 @@ public class SharedSingletonMapTest { assertTrue(m.equals(t)); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testEmptyOrderedCopyOf() { SharedSingletonMap.orderedCopyOf(ImmutableMap.of()); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testEmptyUnorderedCopyOf() { SharedSingletonMap.unorderedCopyOf(ImmutableMap.of()); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testClear() { create().clear(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testPut() { create().put(null, null); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testPutAll() { create().putAll(Collections.singletonMap("", "")); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testRemove() { create().remove(null); } diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/SingletonSetTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/SingletonSetTest.java index 3e2ae6ca04..8438554104 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/SingletonSetTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/SingletonSetTest.java @@ -73,37 +73,37 @@ public class SingletonSetTest { assertFalse(it.hasNext()); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testRejectedAdd() { final SingletonSet s = nullSet(); s.add(null); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testRejectedAddAll() { final SingletonSet s = nullSet(); s.addAll(null); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testRejectedClear() { final SingletonSet s = nullSet(); s.clear(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testRejectedRemove() { final SingletonSet s = nullSet(); s.remove(null); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testRejectedRemoveAll() { final SingletonSet s = nullSet(); s.removeAll(null); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testRejectedRetainAll() { final SingletonSet s = nullSet(); s.retainAll(null); diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListeningExecutorServiceTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListeningExecutorServiceTest.java index bfc9303561..bbcb87f148 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListeningExecutorServiceTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListeningExecutorServiceTest.java @@ -8,9 +8,9 @@ package org.opendaylight.yangtools.util.concurrent; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -19,11 +19,11 @@ import static org.opendaylight.yangtools.util.concurrent.CommonTestUtils.SUBMIT_ import static org.opendaylight.yangtools.util.concurrent.CommonTestUtils.SUBMIT_RUNNABLE; import static org.opendaylight.yangtools.util.concurrent.CommonTestUtils.SUBMIT_RUNNABLE_WITH_RESULT; -import com.google.common.collect.Lists; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ThreadFactoryBuilder; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; @@ -47,11 +47,11 @@ public class AsyncNotifyingListeningExecutorServiceTest { @After public void tearDown() { - if (listenerExecutor != null ) { + if (listenerExecutor != null) { listenerExecutor.shutdownNow(); } - if (testExecutor != null ) { + if (testExecutor != null) { testExecutor.shutdownNow(); } } @@ -60,17 +60,17 @@ public class AsyncNotifyingListeningExecutorServiceTest { public void testListenerCallbackWithExecutor() throws InterruptedException { String listenerThreadPrefix = "ListenerThread"; - listenerExecutor = Executors.newFixedThreadPool( 3, - new ThreadFactoryBuilder().setNameFormat( listenerThreadPrefix + "-%d" ).build() ); + listenerExecutor = Executors.newFixedThreadPool(3, + new ThreadFactoryBuilder().setNameFormat(listenerThreadPrefix + "-%d").build()); testExecutor = new AsyncNotifyingListeningExecutorService( Executors.newSingleThreadExecutor( - new ThreadFactoryBuilder().setNameFormat( "SingleThread" ).build() ), - listenerExecutor ); + new ThreadFactoryBuilder().setNameFormat("SingleThread").build()), + listenerExecutor); - testListenerCallback( testExecutor, SUBMIT_CALLABLE, listenerThreadPrefix ); - testListenerCallback( testExecutor, SUBMIT_RUNNABLE, listenerThreadPrefix ); - testListenerCallback( testExecutor, SUBMIT_RUNNABLE_WITH_RESULT, listenerThreadPrefix ); + testListenerCallback(testExecutor, SUBMIT_CALLABLE, listenerThreadPrefix); + testListenerCallback(testExecutor, SUBMIT_RUNNABLE, listenerThreadPrefix); + testListenerCallback(testExecutor, SUBMIT_RUNNABLE_WITH_RESULT, listenerThreadPrefix); } @Test @@ -79,20 +79,20 @@ public class AsyncNotifyingListeningExecutorServiceTest { String listenerThreadPrefix = "SingleThread"; testExecutor = new AsyncNotifyingListeningExecutorService( Executors.newSingleThreadExecutor( - new ThreadFactoryBuilder().setNameFormat( listenerThreadPrefix ).build() ), - null ); + new ThreadFactoryBuilder().setNameFormat(listenerThreadPrefix).build()), + null); - testListenerCallback( testExecutor, SUBMIT_CALLABLE, listenerThreadPrefix ); - testListenerCallback( testExecutor, SUBMIT_RUNNABLE, listenerThreadPrefix ); - testListenerCallback( testExecutor, SUBMIT_RUNNABLE_WITH_RESULT, listenerThreadPrefix ); + testListenerCallback(testExecutor, SUBMIT_CALLABLE, listenerThreadPrefix); + testListenerCallback(testExecutor, SUBMIT_RUNNABLE, listenerThreadPrefix); + testListenerCallback(testExecutor, SUBMIT_RUNNABLE_WITH_RESULT, listenerThreadPrefix); } - static void testListenerCallback( AsyncNotifyingListeningExecutorService executor, - Invoker invoker, final String expListenerThreadPrefix ) throws InterruptedException { + static void testListenerCallback(final AsyncNotifyingListeningExecutorService executor, + final Invoker invoker, final String expListenerThreadPrefix) throws InterruptedException { AtomicReference assertError = new AtomicReference<>(); - CountDownLatch futureNotifiedLatch = new CountDownLatch( 1 ); - CountDownLatch blockTaskLatch = new CountDownLatch( 1 ); + CountDownLatch futureNotifiedLatch = new CountDownLatch(1); + CountDownLatch blockTaskLatch = new CountDownLatch(1); // The blockTaskLatch is used to block the task from completing until we've added // our listener to the Future. Otherwise, if the task completes quickly and the Future is @@ -100,95 +100,92 @@ public class AsyncNotifyingListeningExecutorServiceTest { // will immediately notify synchronously on this thread as Futures#addCallback defaults to // a same thread executor. This would erroneously fail the test. - ListenableFuture future = invoker.invokeExecutor( executor, blockTaskLatch ); - addCallback( future, futureNotifiedLatch, expListenerThreadPrefix, assertError ); + ListenableFuture future = invoker.invokeExecutor(executor, blockTaskLatch); + addCallback(future, futureNotifiedLatch, expListenerThreadPrefix, assertError); // Now that we've added our listener, signal the latch to let the task complete. blockTaskLatch.countDown(); - assertTrue( "ListenableFuture callback was not notified of onSuccess", - futureNotifiedLatch.await( 5, TimeUnit.SECONDS ) ); + assertTrue("ListenableFuture callback was not notified of onSuccess", + futureNotifiedLatch.await(5, TimeUnit.SECONDS)); - if (assertError.get() != null ) { + if (assertError.get() != null) { throw assertError.get(); } // Add another listener - since the Future is already complete, we expect the listener to be // notified inline on this thread when it's added. - futureNotifiedLatch = new CountDownLatch( 1 ); - addCallback( future, futureNotifiedLatch, Thread.currentThread().getName(), assertError ); + futureNotifiedLatch = new CountDownLatch(1); + addCallback(future, futureNotifiedLatch, Thread.currentThread().getName(), assertError); - assertTrue( "ListenableFuture callback was not notified of onSuccess", - futureNotifiedLatch.await( 5, TimeUnit.SECONDS ) ); + assertTrue("ListenableFuture callback was not notified of onSuccess", + futureNotifiedLatch.await(5, TimeUnit.SECONDS)); - if (assertError.get() != null ) { + if (assertError.get() != null) { throw assertError.get(); } } - static void addCallback( ListenableFuture future, - final CountDownLatch futureNotifiedLatch, - final String expListenerThreadPrefix, - final AtomicReference assertError ) { + static void addCallback(final ListenableFuture future, final CountDownLatch futureNotifiedLatch, + final String expListenerThreadPrefix, final AtomicReference assertError) { - Futures.addCallback( future, new FutureCallback() { + Futures.addCallback(future, new FutureCallback() { @Override - public void onSuccess( Object result ) { - + public void onSuccess(final Object result) { try { String theadName = Thread.currentThread().getName(); - assertTrue( "ListenableFuture callback was not notified on the listener executor." - + " Expected thread name prefix \"" + expListenerThreadPrefix + - "\". Actual thread name \"" + theadName + "\"", - theadName.startsWith( expListenerThreadPrefix ) ); - } catch( AssertionError e ) { - assertError.set( e ); + assertTrue("ListenableFuture callback was not notified on the listener executor." + + " Expected thread name prefix \"" + expListenerThreadPrefix + + "\". Actual thread name \"" + theadName + "\"", + theadName.startsWith(expListenerThreadPrefix)); + } catch (AssertionError e) { + assertError.set(e); } finally { futureNotifiedLatch.countDown(); } } @Override - public void onFailure( @Nonnull Throwable t ) { + @SuppressWarnings("checkstyle:parameterName") + public void onFailure(@Nonnull final Throwable t) { // Shouldn't happen - t.printStackTrace(); + fail("Unexpected failure " + t); } - } ); + }); } @Test public void testDelegatedMethods() throws InterruptedException { - Runnable task = () -> { - }; + Runnable task = () -> { }; - List taskList = Lists.newArrayList(); + List taskList = new ArrayList<>(); - ExecutorService mockDelegate = mock( ExecutorService.class ); - doNothing().when( mockDelegate ).execute( task ); - doNothing().when( mockDelegate ).shutdown(); - doReturn( taskList ).when( mockDelegate ).shutdownNow(); - doReturn( true ).when( mockDelegate ).awaitTermination( 3, TimeUnit.SECONDS ); - doReturn( true ).when( mockDelegate ).isShutdown(); - doReturn( true ).when( mockDelegate ).isTerminated(); + ExecutorService mockDelegate = mock(ExecutorService.class); + doNothing().when(mockDelegate).execute(task); + doNothing().when(mockDelegate).shutdown(); + doReturn(taskList).when(mockDelegate).shutdownNow(); + doReturn(Boolean.TRUE).when(mockDelegate).awaitTermination(3, TimeUnit.SECONDS); + doReturn(Boolean.TRUE).when(mockDelegate).isShutdown(); + doReturn(Boolean.TRUE).when(mockDelegate).isTerminated(); AsyncNotifyingListeningExecutorService executor = new AsyncNotifyingListeningExecutorService( - mockDelegate, null ); + mockDelegate, null); - executor.execute( task ); + executor.execute(task); executor.shutdown(); - assertEquals( "awaitTermination", true, executor.awaitTermination( 3, TimeUnit.SECONDS ) ); - assertSame( "shutdownNow", taskList, executor.shutdownNow() ); - assertEquals( "isShutdown", true, executor.isShutdown() ); - assertEquals( "isTerminated", true, executor.isTerminated() ); - - verify( mockDelegate ).execute( task ); - verify( mockDelegate ).shutdown(); - verify( mockDelegate ).awaitTermination( 3, TimeUnit.SECONDS ); - verify( mockDelegate ).shutdownNow(); - verify( mockDelegate ).isShutdown(); - verify( mockDelegate ).isTerminated(); + assertTrue("awaitTermination", executor.awaitTermination(3, TimeUnit.SECONDS)); + assertSame("shutdownNow", taskList, executor.shutdownNow()); + assertTrue("isShutdown", executor.isShutdown()); + assertTrue("isTerminated", executor.isTerminated()); + + verify(mockDelegate).execute(task); + verify(mockDelegate).shutdown(); + verify(mockDelegate).awaitTermination(3, TimeUnit.SECONDS); + verify(mockDelegate).shutdownNow(); + verify(mockDelegate).isShutdown(); + verify(mockDelegate).isTerminated(); } } diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/CommonTestUtils.java b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/CommonTestUtils.java index 7404c8c384..9ee60f7ad0 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/CommonTestUtils.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/CommonTestUtils.java @@ -11,7 +11,6 @@ package org.opendaylight.yangtools.util.concurrent; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.Uninterruptibles; -import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; /** @@ -20,31 +19,27 @@ import java.util.concurrent.CountDownLatch; * @author Thomas Pantelis */ public class CommonTestUtils { - + @FunctionalInterface public interface Invoker { - ListenableFuture invokeExecutor( ListeningExecutorService executor, - CountDownLatch blockingLatch ); + ListenableFuture invokeExecutor(ListeningExecutorService executor, CountDownLatch blockingLatch); } - public static final Invoker SUBMIT_CALLABLE = (executor, blockingLatch) -> executor.submit(new Callable() { - @Override - public Void call() throws Exception { - if (blockingLatch != null ) { - Uninterruptibles.awaitUninterruptibly( blockingLatch ); - } - return null; + public static final Invoker SUBMIT_CALLABLE = (executor, blockingLatch) -> executor.submit(() -> { + if (blockingLatch != null) { + Uninterruptibles.awaitUninterruptibly(blockingLatch); } - } ); + return null; + }); public static final Invoker SUBMIT_RUNNABLE = (executor, blockingLatch) -> executor.submit(() -> { - if (blockingLatch != null ) { - Uninterruptibles.awaitUninterruptibly( blockingLatch ); + if (blockingLatch != null) { + Uninterruptibles.awaitUninterruptibly(blockingLatch); } }); public static final Invoker SUBMIT_RUNNABLE_WITH_RESULT = (executor, blockingLatch) -> executor.submit(() -> { - if (blockingLatch != null ) { - Uninterruptibles.awaitUninterruptibly( blockingLatch ); + if (blockingLatch != null) { + Uninterruptibles.awaitUninterruptibly(blockingLatch); } - }, "foo" ); + }, "foo"); } diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/CountingRejectedExecutionHandlerTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/CountingRejectedExecutionHandlerTest.java index 6a86840b96..e6dd9f3f5e 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/CountingRejectedExecutionHandlerTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/CountingRejectedExecutionHandlerTest.java @@ -9,6 +9,7 @@ package org.opendaylight.yangtools.util.concurrent; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.concurrent.CountDownLatch; @@ -40,59 +41,57 @@ public class CountingRejectedExecutionHandlerTest { @Test public void testCallerRunsPolicyHandler() throws InterruptedException { - int nTasks = 5; - CountDownLatch tasksRunLatch = new CountDownLatch( 1 ); - CountDownLatch blockLatch = new CountDownLatch( 1 ); + CountDownLatch tasksRunLatch = new CountDownLatch(1); + CountDownLatch blockLatch = new CountDownLatch(1); - executor = new ThreadPoolExecutor( 1, 1, 0, TimeUnit.SECONDS, - ExecutorServiceUtil.offerFailingBlockingQueue(new LinkedBlockingQueue<>() ) ); + executor = new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS, + ExecutorServiceUtil.offerFailingBlockingQueue(new LinkedBlockingQueue<>())); - CountingRejectedExecutionHandler countingHandler = - CountingRejectedExecutionHandler.newCallerRunsPolicy(); - executor.setRejectedExecutionHandler( countingHandler ); + CountingRejectedExecutionHandler countingHandler = CountingRejectedExecutionHandler.newCallerRunsPolicy(); + executor.setRejectedExecutionHandler(countingHandler); - executor.execute( new Task( tasksRunLatch, blockLatch ) ); + executor.execute(new Task(tasksRunLatch, blockLatch)); - for (int i = 0; i < nTasks - 1; i++) { - executor.execute( new Task( null, null, null, null, 0 ) ); + int tasks = 5; + for (int i = 0; i < tasks - 1; i++) { + executor.execute(new Task(null, null, null, null, 0)); } - assertEquals( "getRejectedTaskCount", nTasks - 1, countingHandler.getRejectedTaskCount() ); + assertEquals("getRejectedTaskCount", tasks - 1, countingHandler.getRejectedTaskCount()); blockLatch.countDown(); - assertEquals( "Tasks complete", true, tasksRunLatch.await( 5, TimeUnit.SECONDS ) ); + assertTrue("Tasks complete", tasksRunLatch.await(5, TimeUnit.SECONDS)); } @Test public void testAbortPolicyHandler() throws InterruptedException { - int nTasks = 5; - CountDownLatch tasksRunLatch = new CountDownLatch( 1 ); - CountDownLatch blockLatch = new CountDownLatch( 1 ); + CountDownLatch tasksRunLatch = new CountDownLatch(1); + CountDownLatch blockLatch = new CountDownLatch(1); - executor = new ThreadPoolExecutor( 1, 1, 0, TimeUnit.SECONDS, - ExecutorServiceUtil.offerFailingBlockingQueue(new LinkedBlockingQueue<>() ) ); + executor = new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS, + ExecutorServiceUtil.offerFailingBlockingQueue(new LinkedBlockingQueue<>())); - CountingRejectedExecutionHandler countingHandler = - CountingRejectedExecutionHandler.newAbortPolicy(); - executor.setRejectedExecutionHandler( countingHandler ); + CountingRejectedExecutionHandler countingHandler = CountingRejectedExecutionHandler.newAbortPolicy(); + executor.setRejectedExecutionHandler(countingHandler); - executor.execute( new Task( tasksRunLatch, blockLatch ) ); + executor.execute(new Task(tasksRunLatch, blockLatch)); - for (int i = 0; i < nTasks - 1; i++) { + int tasks = 5; + for (int i = 0; i < tasks - 1; i++) { try { - executor.execute( new Task( null, null, null, null, 0 ) ); - fail( "Expected RejectedExecutionException" ); - } catch( RejectedExecutionException e ) { + executor.execute(new Task(null, null, null, null, 0)); + fail("Expected RejectedExecutionException"); + } catch (RejectedExecutionException e) { // Expected } } - assertEquals( "getRejectedTaskCount", nTasks - 1, countingHandler.getRejectedTaskCount() ); + assertEquals("getRejectedTaskCount", tasks - 1, countingHandler.getRejectedTaskCount()); blockLatch.countDown(); - assertEquals( "Tasks complete", true, tasksRunLatch.await( 5, TimeUnit.SECONDS ) ); + assertTrue("Tasks complete", tasksRunLatch.await(5, TimeUnit.SECONDS)); } } diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/DeadlockDetectingListeningExecutorServiceTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/DeadlockDetectingListeningExecutorServiceTest.java index 83a5134bf7..c1f760375b 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/DeadlockDetectingListeningExecutorServiceTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/DeadlockDetectingListeningExecutorServiceTest.java @@ -84,12 +84,11 @@ public class DeadlockDetectingListeningExecutorServiceTest { ListenableFuture future = executor.submit(() -> "foo"); - assertEquals( "Future result", "foo", future.get( 5, TimeUnit.SECONDS)); + assertEquals("Future result", "foo", future.get(5, TimeUnit.SECONDS)); // Test submit with Runnable. - executor.submit(() -> { - }).get(); + executor.submit(() -> { }).get(); // Test submit with Runnable and value. @@ -99,6 +98,7 @@ public class DeadlockDetectingListeningExecutorServiceTest { } @Test + @SuppressWarnings("checkstyle:illegalThrows") public void testNonBlockingSubmitOnExecutorThread() throws Throwable { executor = newExecutor(); @@ -110,6 +110,7 @@ public class DeadlockDetectingListeningExecutorServiceTest { testNonBlockingSubmitOnExecutorThread(EXECUTE, SUBMIT_CALLABLE); } + @SuppressWarnings("checkstyle:illegalThrows") void testNonBlockingSubmitOnExecutorThread(final InitialInvoker initialInvoker, final Invoker invoker) throws Throwable { @@ -123,6 +124,7 @@ public class DeadlockDetectingListeningExecutorServiceTest { } @Override + @SuppressWarnings("checkstyle:parameterName") public void onFailure(@Nonnull final Throwable t) { caughtEx.set(t); futureCompletedLatch.countDown(); @@ -140,7 +142,7 @@ public class DeadlockDetectingListeningExecutorServiceTest { } @Test - public void testBlockingSubmitOnExecutorThread() throws Exception { + public void testBlockingSubmitOnExecutorThread() throws InterruptedException { executor = newExecutor(); @@ -151,8 +153,9 @@ public class DeadlockDetectingListeningExecutorServiceTest { testBlockingSubmitOnExecutorThread(EXECUTE, SUBMIT_CALLABLE); } + @SuppressWarnings("checkstyle:illegalCatch") void testBlockingSubmitOnExecutorThread(final InitialInvoker initialInvoker, final Invoker invoker) - throws Exception { + throws InterruptedException { final AtomicReference caughtEx = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); @@ -161,9 +164,9 @@ public class DeadlockDetectingListeningExecutorServiceTest { try { invoker.invokeExecutor(executor, null).get(); - } catch(ExecutionException e) { + } catch (ExecutionException e) { caughtEx.set(e.getCause()); - } catch(Throwable e) { + } catch (Throwable e) { caughtEx.set(e); } finally { latch.countDown(); @@ -172,7 +175,7 @@ public class DeadlockDetectingListeningExecutorServiceTest { initialInvoker.invokeExecutor(executor, task); - assertTrue("Task did not complete - executor likely deadlocked", latch.await( 5, TimeUnit.SECONDS)); + assertTrue("Task did not complete - executor likely deadlocked", latch.await(5, TimeUnit.SECONDS)); assertNotNull("Expected exception thrown", caughtEx.get()); assertEquals("Caught exception type", TestDeadlockException.class, caughtEx.get().getClass()); } diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFutureTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFutureTest.java index deeafc1c1b..068f82519f 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFutureTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFutureTest.java @@ -8,11 +8,11 @@ package org.opendaylight.yangtools.util.concurrent; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.util.concurrent.CheckedFuture; @@ -32,35 +32,37 @@ import org.junit.Test; public class MappingCheckedFutureTest { interface FutureInvoker { - void invokeGet( CheckedFuture future ) throws Exception; - Throwable extractWrappedTestEx( Exception from ); + void invokeGet(CheckedFuture future) throws Exception; + + Throwable extractWrappedTestEx(Exception from); } - @SuppressWarnings("serial") static class TestException extends Exception { - TestException( final String message, final Throwable cause ) { - super( message, cause ); + private static final long serialVersionUID = 1L; + + TestException(final String message, final Throwable cause) { + super(message, cause); } } - static final ExceptionMapper MAPPER = new ExceptionMapper( - "Test", TestException.class ) { + static final ExceptionMapper MAPPER = new ExceptionMapper( + "Test", TestException.class) { @Override - protected TestException newWithCause( final String message, final Throwable cause ) { - return new TestException( message, cause ); + protected TestException newWithCause(final String message, final Throwable cause) { + return new TestException(message, cause); } }; static final FutureInvoker GET = new FutureInvoker() { @Override - public void invokeGet( final CheckedFuture future ) throws Exception { + public void invokeGet(final CheckedFuture future) throws Exception { future.get(); } @Override - public Throwable extractWrappedTestEx( final Exception from ) { - if (from instanceof ExecutionException ) { + public Throwable extractWrappedTestEx(final Exception from) { + if (from instanceof ExecutionException) { return from.getCause(); } @@ -70,13 +72,13 @@ public class MappingCheckedFutureTest { static final FutureInvoker TIMED_GET = new FutureInvoker() { @Override - public void invokeGet( final CheckedFuture future ) throws Exception { - future.get( 1, TimeUnit.HOURS ); + public void invokeGet(final CheckedFuture future) throws Exception { + future.get(1, TimeUnit.HOURS); } @Override - public Throwable extractWrappedTestEx( final Exception from ) { - if (from instanceof ExecutionException ) { + public Throwable extractWrappedTestEx(final Exception from) { + if (from instanceof ExecutionException) { return from.getCause(); } @@ -86,139 +88,128 @@ public class MappingCheckedFutureTest { static final FutureInvoker CHECKED_GET = new FutureInvoker() { @Override - public void invokeGet( final CheckedFuture future ) throws Exception { + public void invokeGet(final CheckedFuture future) throws Exception { future.checkedGet(); } @Override - public Throwable extractWrappedTestEx( final Exception from ) { + public Throwable extractWrappedTestEx(final Exception from) { return from; } }; static final FutureInvoker TIMED_CHECKED_GET = new FutureInvoker() { @Override - public void invokeGet( final CheckedFuture future ) throws Exception { - future.checkedGet( 50, TimeUnit.MILLISECONDS ); + public void invokeGet(final CheckedFuture future) throws Exception { + future.checkedGet(50, TimeUnit.MILLISECONDS); } @Override - public Throwable extractWrappedTestEx( final Exception from ) { + public Throwable extractWrappedTestEx(final Exception from) { return from; } }; @Test public void testGet() throws Exception { - SettableFuture delegate = SettableFuture.create(); - MappingCheckedFuture future = MappingCheckedFuture.create( delegate, MAPPER ); - delegate.set( "test" ); - assertEquals( "get", "test", future.get() ); + MappingCheckedFuture future = MappingCheckedFuture.create(delegate, MAPPER); + delegate.set("test"); + assertEquals("get", "test", future.get()); } @Test public void testGetWithExceptions() throws Exception { - - testExecutionException( GET, new RuntimeException() ); - testExecutionException( GET, new TestException( "mock", null ) ); - testCancellationException( GET ); - testInterruptedException( GET ); + testExecutionException(GET, new RuntimeException()); + testExecutionException(GET, new TestException("mock", null)); + testCancellationException(GET); + testInterruptedException(GET); } @Test public void testTimedGet() throws Exception { - SettableFuture delegate = SettableFuture.create(); - MappingCheckedFuture future = MappingCheckedFuture.create( delegate, MAPPER ); - delegate.set( "test" ); - assertEquals( "get", "test", future.get( 50, TimeUnit.MILLISECONDS ) ); + MappingCheckedFuture future = MappingCheckedFuture.create(delegate, MAPPER); + delegate.set("test"); + assertEquals("get", "test", future.get(50, TimeUnit.MILLISECONDS)); } @Test public void testTimedGetWithExceptions() throws Exception { - - testExecutionException( TIMED_GET, new RuntimeException() ); - testCancellationException( TIMED_GET ); - testInterruptedException( TIMED_GET ); + testExecutionException(TIMED_GET, new RuntimeException()); + testCancellationException(TIMED_GET); + testInterruptedException(TIMED_GET); } @Test public void testCheckedGetWithExceptions() throws Exception { - - testExecutionException( CHECKED_GET, new RuntimeException() ); - testCancellationException( CHECKED_GET ); - testInterruptedException( CHECKED_GET ); + testExecutionException(CHECKED_GET, new RuntimeException()); + testCancellationException(CHECKED_GET); + testInterruptedException(CHECKED_GET); } @Test public void testTimedCheckedWithExceptions() throws Exception { - - testExecutionException( TIMED_CHECKED_GET, new RuntimeException() ); - testCancellationException( TIMED_CHECKED_GET ); - testInterruptedException( TIMED_CHECKED_GET ); + testExecutionException(TIMED_CHECKED_GET, new RuntimeException()); + testCancellationException(TIMED_CHECKED_GET); + testInterruptedException(TIMED_CHECKED_GET); } - private static void testExecutionException( final FutureInvoker invoker, final Throwable cause ) { - + @SuppressWarnings("checkstyle:illegalCatch") + private static void testExecutionException(final FutureInvoker invoker, final Throwable cause) { SettableFuture delegate = SettableFuture.create(); - MappingCheckedFuture mappingFuture = - MappingCheckedFuture.create( delegate, MAPPER ); + MappingCheckedFuture mappingFuture = MappingCheckedFuture.create(delegate, MAPPER); - delegate.setException( cause ); + delegate.setException(cause); try { - invoker.invokeGet( mappingFuture ); - fail( "Expected exception thrown" ); - } catch( Exception e ) { - Throwable expectedTestEx = invoker.extractWrappedTestEx( e ); - assertNotNull( "Expected returned exception is null", expectedTestEx ); - assertEquals( "Exception type", TestException.class, expectedTestEx.getClass() ); - - if (cause instanceof TestException ) { - assertNull( "Expected null cause", expectedTestEx.getCause() ); + invoker.invokeGet(mappingFuture); + fail("Expected exception thrown"); + } catch (Exception e) { + Throwable expectedTestEx = invoker.extractWrappedTestEx(e); + assertNotNull("Expected returned exception is null", expectedTestEx); + assertEquals("Exception type", TestException.class, expectedTestEx.getClass()); + + if (cause instanceof TestException) { + assertNull("Expected null cause", expectedTestEx.getCause()); } else { - assertSame( "TestException cause", cause, expectedTestEx.getCause() ); + assertSame("TestException cause", cause, expectedTestEx.getCause()); } } } - private static void testCancellationException( final FutureInvoker invoker ) { - + @SuppressWarnings("checkstyle:illegalCatch") + private static void testCancellationException(final FutureInvoker invoker) { SettableFuture delegate = SettableFuture.create(); - MappingCheckedFuture mappingFuture = - MappingCheckedFuture.create( delegate, MAPPER ); + MappingCheckedFuture mappingFuture = MappingCheckedFuture.create(delegate, MAPPER); - mappingFuture.cancel( false ); + mappingFuture.cancel(false); try { - invoker.invokeGet( mappingFuture ); - fail( "Expected exception thrown" ); - } catch( Exception e ) { - Throwable expectedTestEx = invoker.extractWrappedTestEx( e ); - assertNotNull( "Expected returned exception is null", expectedTestEx ); - assertEquals( "Exception type", TestException.class, expectedTestEx.getClass() ); - assertEquals( "TestException cause type", CancellationException.class, - expectedTestEx.getCause().getClass() ); + invoker.invokeGet(mappingFuture); + fail("Expected exception thrown"); + } catch (Exception e) { + Throwable expectedTestEx = invoker.extractWrappedTestEx(e); + assertNotNull("Expected returned exception is null", expectedTestEx); + assertEquals("Exception type", TestException.class, expectedTestEx.getClass()); + assertEquals("TestException cause type", CancellationException.class, expectedTestEx.getCause().getClass()); } } - private static void testInterruptedException( final FutureInvoker invoker ) throws Exception { - + @SuppressWarnings("checkstyle:illegalCatch") + private static void testInterruptedException(final FutureInvoker invoker) throws Exception { SettableFuture delegate = SettableFuture.create(); - final MappingCheckedFuture mappingFuture = - MappingCheckedFuture.create( delegate, MAPPER ); + final MappingCheckedFuture mappingFuture = MappingCheckedFuture.create(delegate, MAPPER); final AtomicReference assertError = new AtomicReference<>(); - final CountDownLatch doneLatch = new CountDownLatch( 1 ); + final CountDownLatch doneLatch = new CountDownLatch(1); Thread thread = new Thread() { - @Override public void run() { try { doInvoke(); - } catch( AssertionError e ) { - assertError.set( e ); + } catch (AssertionError e) { + assertError.set(e); } finally { doneLatch.countDown(); } @@ -226,23 +217,23 @@ public class MappingCheckedFutureTest { void doInvoke() { try { - invoker.invokeGet( mappingFuture ); - fail( "Expected exception thrown" ); - } catch( Exception e ) { - Throwable expectedTestEx = invoker.extractWrappedTestEx( e ); - assertNotNull( "Expected returned exception is null", expectedTestEx ); - assertEquals( "Exception type", TestException.class, expectedTestEx.getClass() ); - assertEquals( "TestException cause type", InterruptedException.class, - expectedTestEx.getCause().getClass() ); + invoker.invokeGet(mappingFuture); + fail("Expected exception thrown"); + } catch (Exception e) { + Throwable expectedTestEx = invoker.extractWrappedTestEx(e); + assertNotNull("Expected returned exception is null", expectedTestEx); + assertEquals("Exception type", TestException.class, expectedTestEx.getClass()); + assertEquals("TestException cause type", InterruptedException.class, + expectedTestEx.getCause().getClass()); } } }; thread.start(); thread.interrupt(); - assertEquals( "get call completed", true, doneLatch.await( 5, TimeUnit.SECONDS ) ); + assertTrue("get call completed", doneLatch.await(5, TimeUnit.SECONDS)); - if (assertError.get() != null ) { + if (assertError.get() != null) { throw assertError.get(); } } diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManagerTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManagerTest.java index 69fa995125..8d6c9d473f 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManagerTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManagerTest.java @@ -9,16 +9,15 @@ package org.opendaylight.yangtools.util.concurrent; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import com.google.common.base.Stopwatch; import com.google.common.util.concurrent.Uninterruptibles; -import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -29,6 +28,7 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Test; +import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager.BatchedInvoker; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,15 +62,15 @@ public class QueuedNotificationManagerTest { actual.clear(); } - void onNotification(final N data) { + void onNotification(final Collection data) { try { if (sleepTime > 0) { - Uninterruptibles.sleepUninterruptibly( sleepTime, TimeUnit.MILLISECONDS); + Uninterruptibles.sleepUninterruptibly(sleepTime, TimeUnit.MILLISECONDS); } if (cacheNotifications) { - actual.add(data); + actual.addAll(data); } RuntimeException localRuntimeEx = runtimeEx; @@ -86,12 +86,12 @@ public class QueuedNotificationManagerTest { } } finally { - latch.countDown(); + data.forEach(action -> latch.countDown()); } } void verifyNotifications() { - boolean done = Uninterruptibles.awaitUninterruptibly(latch, 10, TimeUnit.SECONDS); + boolean done = Uninterruptibles.awaitUninterruptibly(latch, 5, TimeUnit.SECONDS); if (!done) { long actualCount = latch.getCount(); fail(name + ": Received " + (expCount - actualCount) + " notifications. Expected " + expCount); @@ -129,10 +129,10 @@ public class QueuedNotificationManagerTest { } } - static class TestNotifier implements QueuedNotificationManager.Invoker, N> { + static class TestNotifier implements BatchedInvoker, N> { @Override - public void invokeListener(final TestListener listener, final N notification) { - listener.onNotification(notification); + public void invokeListener(final TestListener listener, final Collection notifications) { + listener.onNotification(notifications); } } @@ -146,17 +146,16 @@ public class QueuedNotificationManagerTest { } } - @Test(timeout=10000) + @Test(timeout = 10000) public void testNotificationsWithSingleListener() { - queueExecutor = Executors.newFixedThreadPool( 2 ); - NotificationManager, Integer> manager = new QueuedNotificationManager<>(queueExecutor, - new TestNotifier<>(), 10, "TestMgr" ); + queueExecutor = Executors.newFixedThreadPool(2); + NotificationManager, Integer> manager = QueuedNotificationManager.create(queueExecutor, + new TestNotifier<>(), 10, "TestMgr"); - int initialCount = 6; - int nNotifications = 100; + int count = 100; - TestListener listener = new TestListener<>(nNotifications, 1); + TestListener listener = new TestListener<>(count, 1); listener.sleepTime = 20; manager.submitNotifications(listener, Arrays.asList(1, 2)); @@ -172,29 +171,30 @@ public class QueuedNotificationManagerTest { listener.sleepTime = 0; - List expNotifications = new ArrayList<>(nNotifications); + List expNotifications = new ArrayList<>(count); expNotifications.addAll(Arrays.asList(1, 2, 3, 4, 5, 6)); - for (int i = 1; i <= nNotifications - initialCount; i++) { - Integer v = Integer.valueOf(initialCount + i); - expNotifications.add(v); - manager.submitNotification(listener, v); + int initialCount = 6; + for (int i = 1; i <= count - initialCount; i++) { + Integer val = Integer.valueOf(initialCount + i); + expNotifications.add(val); + manager.submitNotification(listener, val); } - listener.verifyNotifications( expNotifications ); + listener.verifyNotifications(expNotifications); } @Test public void testNotificationsWithMultipleListeners() throws InterruptedException { - int nListeners = 10; - queueExecutor = Executors.newFixedThreadPool(nListeners); - final ExecutorService stagingExecutor = Executors.newFixedThreadPool(nListeners); - final NotificationManager, Integer> manager = new QueuedNotificationManager<>( - queueExecutor, new TestNotifier<>(), 5000, "TestMgr" ); + int count = 10; + queueExecutor = Executors.newFixedThreadPool(count); + final ExecutorService stagingExecutor = Executors.newFixedThreadPool(count); + final NotificationManager, Integer> manager = QueuedNotificationManager.create( + queueExecutor, new TestNotifier<>(), 5000, "TestMgr"); final int nNotifications = 100000; - LOG.info("Testing {} listeners with {} notifications each...", nListeners, nNotifications); + LOG.info("Testing {} listeners with {} notifications each...", count, nNotifications); final Integer[] notifications = new Integer[nNotifications]; for (int i = 1; i <= nNotifications; i++) { @@ -205,7 +205,7 @@ public class QueuedNotificationManagerTest { List> listeners = new ArrayList<>(); List threads = new ArrayList<>(); - for (int i = 1; i <= nListeners; i++) { + for (int i = 1; i <= count; i++) { final TestListener listener = i == 2 ? new TestListener2<>(nNotifications, i) : i == 3 ? new TestListener3<>(nNotifications, i) : @@ -243,44 +243,44 @@ public class QueuedNotificationManagerTest { } } - @Test(timeout=10000) + @Test(timeout = 10000) public void testNotificationsWithListenerRuntimeEx() { queueExecutor = Executors.newFixedThreadPool(1); - NotificationManager, Integer> manager = - new QueuedNotificationManager<>( queueExecutor, new TestNotifier<>(), - 10, "TestMgr" ); - + NotificationManager, Integer> manager = QueuedNotificationManager.create(queueExecutor, + new TestNotifier<>(), 10, "TestMgr"); TestListener listener = new TestListener<>(2, 1); - final RuntimeException mockedRuntimeException = mock(RuntimeException.class); - doNothing().when(mockedRuntimeException).printStackTrace(any(PrintStream.class)); + final RuntimeException mockedRuntimeException = new RuntimeException("mock"); listener.runtimeEx = mockedRuntimeException; manager.submitNotification(listener, 1); manager.submitNotification(listener, 2); listener.verifyNotifications(); + List tasks = queueExecutor.shutdownNow(); + assertTrue(tasks.isEmpty()); } - @Test(timeout=10000) + @Test(timeout = 10000) public void testNotificationsWithListenerJVMError() { final CountDownLatch errorCaughtLatch = new CountDownLatch(1); queueExecutor = new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS, new LinkedBlockingQueue<>()) { - @Override - public void execute(final Runnable command) { - super.execute(() -> { - try { - command.run(); - } catch (Error e) { - errorCaughtLatch.countDown(); - } - }); - } + @Override + @SuppressWarnings("checkstyle:illegalCatch") + public void execute(final Runnable command) { + super.execute(() -> { + try { + command.run(); + } catch (Error e) { + errorCaughtLatch.countDown(); + } + }); + } }; - NotificationManager, Integer> manager = new QueuedNotificationManager<>(queueExecutor, + NotificationManager, Integer> manager = QueuedNotificationManager.create(queueExecutor, new TestNotifier<>(), 10, "TestMgr"); TestListener listener = new TestListener<>(2, 1); @@ -288,11 +288,12 @@ public class QueuedNotificationManagerTest { manager.submitNotification(listener, 1); - assertEquals("JVM Error caught", true, Uninterruptibles.awaitUninterruptibly( - errorCaughtLatch, 5, TimeUnit.SECONDS)); + assertTrue("JVM Error caught", Uninterruptibles.awaitUninterruptibly(errorCaughtLatch, 5, TimeUnit.SECONDS)); manager.submitNotification(listener, 2); listener.verifyNotifications(); + List tasks = queueExecutor.shutdownNow(); + assertTrue(tasks.isEmpty()); } } diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/ReflectiveExceptionMapperTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/ReflectiveExceptionMapperTest.java index c10215d1b7..7d5a9f06f7 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/ReflectiveExceptionMapperTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/ReflectiveExceptionMapperTest.java @@ -12,11 +12,11 @@ import static org.junit.Assert.assertEquals; import java.util.concurrent.ExecutionException; import org.junit.Test; -public final class ReflectiveExceptionMapperTest { +public class ReflectiveExceptionMapperTest { static final class NoArgumentCtorException extends Exception { private static final long serialVersionUID = 1L; - public NoArgumentCtorException() { + NoArgumentCtorException() { super(); } } @@ -32,12 +32,12 @@ public final class ReflectiveExceptionMapperTest { static final class FailingCtorException extends Exception { private static final long serialVersionUID = 1L; - public FailingCtorException(final String message, final Throwable cause) { + FailingCtorException(final String message, final Throwable cause) { throw new IllegalArgumentException("just for test"); } } - static final class GoodException extends Exception { + public static final class GoodException extends Exception { private static final long serialVersionUID = 1L; public GoodException(final String message, final Throwable cause) { @@ -46,24 +46,25 @@ public final class ReflectiveExceptionMapperTest { } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testNoArgumentsContructor() { ReflectiveExceptionMapper.create("no arguments", NoArgumentCtorException.class); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testPrivateContructor() { ReflectiveExceptionMapper.create("private constructor", PrivateCtorException.class); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testFailingContructor() { ReflectiveExceptionMapper.create("failing constructor", FailingCtorException.class); } @Test public void testInstantiation() { - ReflectiveExceptionMapper mapper = ReflectiveExceptionMapper.create("instantiation", GoodException.class); + ReflectiveExceptionMapper mapper = ReflectiveExceptionMapper.create("instantiation", + GoodException.class); final Throwable cause = new Throwable("some test message"); diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/ThreadPoolExecutorTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/ThreadPoolExecutorTest.java index 44f90f9884..05c4abd0f0 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/ThreadPoolExecutorTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/ThreadPoolExecutorTest.java @@ -7,7 +7,7 @@ */ package org.opendaylight.yangtools.util.concurrent; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.base.Stopwatch; @@ -22,6 +22,8 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; import org.junit.After; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Tests various ThreadPoolExecutor implementations. @@ -29,6 +31,7 @@ import org.junit.Test; * @author Thomas Pantelis */ public class ThreadPoolExecutorTest { + private static final Logger LOG = LoggerFactory.getLogger(ThreadPoolExecutorTest.class); private ExecutorService executor; @@ -40,68 +43,54 @@ public class ThreadPoolExecutorTest { } @Test - public void testFastThreadPoolExecution() throws Exception { - - testThreadPoolExecution( - SpecialExecutors.newBoundedFastThreadPool( 50, 100000, "TestPool" ), - 100000, "TestPool", 0 ); + public void testFastThreadPoolExecution() throws InterruptedException { + testThreadPoolExecution(SpecialExecutors.newBoundedFastThreadPool(50, 100000, "TestPool"), 100000, "TestPool", + 0); } @Test(expected = RejectedExecutionException.class) - public void testFastThreadPoolRejectingTask() throws Exception { - - executor = SpecialExecutors.newBoundedFastThreadPool( 1, 1, "TestPool" ); + public void testFastThreadPoolRejectingTask() throws InterruptedException { + executor = SpecialExecutors.newBoundedFastThreadPool(1, 1, "TestPool"); for (int i = 0; i < 5; i++) { - executor.execute( new Task( null, null, null, null, - TimeUnit.MICROSECONDS.convert( 5, TimeUnit.SECONDS ) ) ); + executor.execute(new Task(null, null, null, null, TimeUnit.MICROSECONDS.convert(5, TimeUnit.SECONDS))); } } @Test - public void testBlockingFastThreadPoolExecution() throws Exception { - + public void testBlockingFastThreadPoolExecution() throws InterruptedException { // With a queue capacity of 1, it should block at some point. - testThreadPoolExecution( - SpecialExecutors.newBlockingBoundedFastThreadPool( 2, 1, "TestPool" ), - 1000, null, 10 ); + testThreadPoolExecution(SpecialExecutors.newBlockingBoundedFastThreadPool(2, 1, "TestPool"), 1000, null, 10); } @Test - public void testCachedThreadPoolExecution() throws Exception { - - testThreadPoolExecution( - SpecialExecutors.newBoundedCachedThreadPool( 10, 100000, "TestPool" ), - 100000, "TestPool", 0 ); + public void testCachedThreadPoolExecution() throws InterruptedException { + testThreadPoolExecution(SpecialExecutors.newBoundedCachedThreadPool(10, 100000, "TestPool"), + 100000, "TestPool", 0); } @Test(expected = RejectedExecutionException.class) - public void testCachedThreadRejectingTask() throws Exception { - - ExecutorService executor = SpecialExecutors.newBoundedCachedThreadPool( 1, 1, "TestPool" ); + public void testCachedThreadRejectingTask() throws InterruptedException { + ExecutorService executor = SpecialExecutors.newBoundedCachedThreadPool(1, 1, "TestPool"); for (int i = 0; i < 5; i++) { - executor.execute( new Task( null, null, null, null, - TimeUnit.MICROSECONDS.convert( 5, TimeUnit.SECONDS ) ) ); + executor.execute(new Task(null, null, null, null, TimeUnit.MICROSECONDS.convert(5, TimeUnit.SECONDS))); } } @Test - public void testBlockingCachedThreadPoolExecution() throws Exception { - - testThreadPoolExecution( - SpecialExecutors.newBlockingBoundedCachedThreadPool( 2, 1, "TestPool" ), - 1000, null, 10 ); + public void testBlockingCachedThreadPoolExecution() throws InterruptedException { + testThreadPoolExecution(SpecialExecutors.newBlockingBoundedCachedThreadPool(2, 1, "TestPool"), 1000, null, 10); } - void testThreadPoolExecution( final ExecutorService executor, - final int numTasksToRun, final String expThreadPrefix, final long taskDelay ) throws Exception { + void testThreadPoolExecution(final ExecutorService executor, final int numTasksToRun, final String expThreadPrefix, + final long taskDelay) throws InterruptedException { this.executor = executor; - System.out.println("\nTesting " + executor.getClass().getSimpleName() + " with " + numTasksToRun + " tasks."); + LOG.debug("Testing {} with {} tasks.", executor.getClass().getSimpleName(), numTasksToRun); - final CountDownLatch tasksRunLatch = new CountDownLatch( numTasksToRun ); + final CountDownLatch tasksRunLatch = new CountDownLatch(numTasksToRun); final ConcurrentMap taskCountPerThread = new ConcurrentHashMap<>(); final AtomicReference threadError = new AtomicReference<>(); @@ -112,35 +101,34 @@ public class ThreadPoolExecutorTest { public void run() { for (int i = 0; i < numTasksToRun; i++) { // if (i%100 == 0) { -// Uninterruptibles.sleepUninterruptibly( 20, TimeUnit.MICROSECONDS ); +// Uninterruptibles.sleepUninterruptibly(20, TimeUnit.MICROSECONDS); // } - executor.execute( new Task( tasksRunLatch, taskCountPerThread, - threadError, expThreadPrefix, taskDelay ) ); + executor.execute(new Task(tasksRunLatch, taskCountPerThread, threadError, expThreadPrefix, + taskDelay)); } } }.start(); - boolean done = tasksRunLatch.await( 15, TimeUnit.SECONDS ); + boolean done = tasksRunLatch.await(15, TimeUnit.SECONDS); stopWatch.stop(); if (!done) { - fail((numTasksToRun - tasksRunLatch.getCount()) + " tasks out of " + numTasksToRun + " executed"); + fail(numTasksToRun - tasksRunLatch.getCount() + " tasks out of " + numTasksToRun + " executed"); } if (threadError.get() != null) { throw threadError.get(); } - System.out.println( taskCountPerThread.size() + " threads used:" ); + LOG.debug("{} threads used:", taskCountPerThread.size()); for (Map.Entry e : taskCountPerThread.entrySet()) { - System.out.println( " " + e.getKey().getName() + " - " + e.getValue() + " tasks" ); + LOG.debug(" {} - {} tasks", e.getKey().getName(), e.getValue()); } - System.out.println( "\n" + executor ); - System.out.println( "\nElapsed time: " + stopWatch ); - System.out.println(); + LOG.debug("{}", executor); + LOG.debug("Elapsed time: {}", stopWatch); } static class Task implements Runnable { @@ -151,8 +139,8 @@ public class ThreadPoolExecutorTest { final String expThreadPrefix; final long delay; - Task( CountDownLatch tasksRunLatch, ConcurrentMap taskCountPerThread, - AtomicReference threadError, String expThreadPrefix, long delay ) { + Task(final CountDownLatch tasksRunLatch, final ConcurrentMap taskCountPerThread, + final AtomicReference threadError, final String expThreadPrefix, final long delay) { this.tasksRunLatch = tasksRunLatch; this.taskCountPerThread = taskCountPerThread; this.threadError = threadError; @@ -161,7 +149,7 @@ public class ThreadPoolExecutorTest { blockLatch = null; } - Task( CountDownLatch tasksRunLatch, CountDownLatch blockLatch ) { + Task(final CountDownLatch tasksRunLatch, final CountDownLatch blockLatch) { this.tasksRunLatch = tasksRunLatch; this.blockLatch = blockLatch; this.taskCountPerThread = null; @@ -175,23 +163,24 @@ public class ThreadPoolExecutorTest { try { try { if (delay > 0) { - TimeUnit.MICROSECONDS.sleep( delay ); + TimeUnit.MICROSECONDS.sleep(delay); } else if (blockLatch != null) { blockLatch.await(); } } catch (InterruptedException e) { + // Ignored } if (expThreadPrefix != null) { - assertEquals( "Thread name starts with " + expThreadPrefix, true, - Thread.currentThread().getName().startsWith( expThreadPrefix ) ); + assertTrue("Thread name starts with " + expThreadPrefix, + Thread.currentThread().getName().startsWith(expThreadPrefix)); } if (taskCountPerThread != null) { - AtomicLong count = taskCountPerThread.get( Thread.currentThread() ); + AtomicLong count = taskCountPerThread.get(Thread.currentThread()); if (count == null) { - count = new AtomicLong( 0 ); - AtomicLong prev = taskCountPerThread.putIfAbsent( Thread.currentThread(), count ); + count = new AtomicLong(0); + AtomicLong prev = taskCountPerThread.putIfAbsent(Thread.currentThread(), count); if (prev != null) { count = prev; } @@ -202,7 +191,7 @@ public class ThreadPoolExecutorTest { } catch (AssertionError e) { if (threadError != null) { - threadError.set( e ); + threadError.set(e); } } finally { if (tasksRunLatch != null) { diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueueTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueueTest.java index 6b685bc842..17c66d7a24 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueueTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/TrackingLinkedBlockingQueueTest.java @@ -9,6 +9,8 @@ package org.opendaylight.yangtools.util.concurrent; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.Arrays; @@ -24,79 +26,75 @@ public class TrackingLinkedBlockingQueueTest { @Test public void testOffer() throws InterruptedException { + TrackingLinkedBlockingQueue queue = new TrackingLinkedBlockingQueue<>(2); - TrackingLinkedBlockingQueue queue = new TrackingLinkedBlockingQueue<>( 2 ); + assertTrue("offer", queue.offer("1")); + assertEquals("getLargestQueueSize", 1, queue.getLargestQueueSize()); + assertEquals("size", 1, queue.size()); - assertEquals( "offer", true, queue.offer( "1" ) ); - assertEquals( "getLargestQueueSize", 1, queue.getLargestQueueSize() ); - assertEquals( "size", 1, queue.size() ); + assertTrue("offer", queue.offer("2", 1, TimeUnit.MILLISECONDS)); + assertEquals("getLargestQueueSize", 2, queue.getLargestQueueSize()); + assertEquals("size", 2, queue.size()); - assertEquals( "offer", true, queue.offer( "2", 1, TimeUnit.MILLISECONDS ) ); - assertEquals( "getLargestQueueSize", 2, queue.getLargestQueueSize() ); - assertEquals( "size", 2, queue.size() ); + assertFalse("offer", queue.offer("3")); + assertEquals("getLargestQueueSize", 2, queue.getLargestQueueSize()); + assertEquals("size", 2, queue.size()); - assertEquals( "offer", false, queue.offer( "3" ) ); - assertEquals( "getLargestQueueSize", 2, queue.getLargestQueueSize() ); - assertEquals( "size", 2, queue.size() ); - - assertEquals( "offer", false, queue.offer( "4", 1, TimeUnit.MILLISECONDS ) ); - assertEquals( "getLargestQueueSize", 2, queue.getLargestQueueSize() ); - assertEquals( "size", 2, queue.size() ); + assertFalse("offer", queue.offer("4", 1, TimeUnit.MILLISECONDS)); + assertEquals("getLargestQueueSize", 2, queue.getLargestQueueSize()); + assertEquals("size", 2, queue.size()); } @Test public void testPut() throws InterruptedException { - TrackingLinkedBlockingQueue queue = new TrackingLinkedBlockingQueue<>(); - queue.put( "1" ); - assertEquals( "getLargestQueueSize", 1, queue.getLargestQueueSize() ); - assertEquals( "size", 1, queue.size() ); + queue.put("1"); + assertEquals("getLargestQueueSize", 1, queue.getLargestQueueSize()); + assertEquals("size", 1, queue.size()); - queue.put( "2" ); - assertEquals( "getLargestQueueSize", 2, queue.getLargestQueueSize() ); - assertEquals( "size", 2, queue.size() ); + queue.put("2"); + assertEquals("getLargestQueueSize", 2, queue.getLargestQueueSize()); + assertEquals("size", 2, queue.size()); } @Test public void testAdd() { + TrackingLinkedBlockingQueue queue = new TrackingLinkedBlockingQueue<>(2); - TrackingLinkedBlockingQueue queue = new TrackingLinkedBlockingQueue<>( 2 ); + assertTrue("add", queue.add("1")); + assertEquals("getLargestQueueSize", 1, queue.getLargestQueueSize()); + assertEquals("size", 1, queue.size()); - assertEquals( "add", true, queue.add( "1" ) ); - assertEquals( "getLargestQueueSize", 1, queue.getLargestQueueSize() ); - assertEquals( "size", 1, queue.size() ); - - assertEquals( "add", true, queue.add( "2" ) ); - assertEquals( "getLargestQueueSize", 2, queue.getLargestQueueSize() ); - assertEquals( "size", 2, queue.size() ); + assertTrue("add", queue.add("2")); + assertEquals("getLargestQueueSize", 2, queue.getLargestQueueSize()); + assertEquals("size", 2, queue.size()); try { - queue.add( "3" ); - fail( "Expected IllegalStateException" ); - } catch( IllegalStateException e ) { + queue.add("3"); + fail("Expected IllegalStateException"); + } catch (IllegalStateException e) { // Expected - assertEquals( "getLargestQueueSize", 2, queue.getLargestQueueSize() ); - assertEquals( "size", 2, queue.size() ); + assertEquals("getLargestQueueSize", 2, queue.getLargestQueueSize()); + assertEquals("size", 2, queue.size()); } } @Test public void testAddAll() { + TrackingLinkedBlockingQueue queue = new TrackingLinkedBlockingQueue<>(3); - TrackingLinkedBlockingQueue queue = new TrackingLinkedBlockingQueue<>( 3 ); - - queue.addAll( Arrays.asList( "1", "2" ) ); - assertEquals( "getLargestQueueSize", 2, queue.getLargestQueueSize() ); - assertEquals( "size", 2, queue.size() ); + queue.addAll(Arrays.asList("1", "2")); + assertEquals("getLargestQueueSize", 2, queue.getLargestQueueSize()); + assertEquals("size", 2, queue.size()); try { - queue.addAll( Arrays.asList( "3", "4" ) ); - fail( "Expected IllegalStateException" ); - } catch( IllegalStateException e ) { + queue.addAll(Arrays.asList("3", "4")); + fail("Expected IllegalStateException"); + } catch (IllegalStateException e) { // Expected - assertEquals( "getLargestQueueSize", 3, queue.getLargestQueueSize() ); - assertEquals( "size", 3, queue.size() ); + assertEquals("getLargestQueueSize", 3, queue.getLargestQueueSize()); + assertEquals("size", 3, queue.size()); } } } diff --git a/yang/yang-common/pom.xml b/yang/yang-common/pom.xml index bfbb2c6d9f..80d7e469e5 100644 --- a/yang/yang-common/pom.xml +++ b/yang/yang-common/pom.xml @@ -62,6 +62,18 @@ + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + checkstyle.violationSeverity=error + + + + +