diff --git a/src/main/java/teetime/framework/AbstractIntraThreadPipe.java b/src/main/java/teetime/framework/AbstractIntraThreadPipe.java index 92fe284b21c74a10efe6b84be454639acbd59348..b3e47b9cf8e333a5f26cc55d70d7b7234b310e88 100644 --- a/src/main/java/teetime/framework/AbstractIntraThreadPipe.java +++ b/src/main/java/teetime/framework/AbstractIntraThreadPipe.java @@ -31,8 +31,8 @@ public abstract class AbstractIntraThreadPipe extends AbstractPipe { } @Override + // getTargetPort is always non-null since the framework adds dummy ports if necessary public final void sendSignal(final ISignal signal) { - // getTargetPort is always non-null since the framework adds dummy ports if necessary this.cachedTargetStage.onSignal(signal, this.getTargetPort()); } diff --git a/src/main/java/teetime/framework/Analysis.java b/src/main/java/teetime/framework/Analysis.java index ea357146a290b441c56b5b2a3764e1a5b41c8b74..78375efac944c52a8983dac250f9ea3dd524154c 100644 --- a/src/main/java/teetime/framework/Analysis.java +++ b/src/main/java/teetime/framework/Analysis.java @@ -96,8 +96,8 @@ public final class Analysis<T extends AnalysisConfiguration> implements Uncaught init(); } + // BETTER validate concurrently private void validateStages() { - // BETTER validate concurrently final List<Stage> threadableStageJobs = this.configuration.getThreadableStageJobs(); for (Stage stage : threadableStageJobs) { // // portConnectionValidator.validate(stage); @@ -186,7 +186,6 @@ public final class Analysis<T extends AnalysisConfiguration> implements Uncaught * @since 1.1 */ public void waitForTermination() { - try { for (Thread thread : this.finiteProducerThreads) { thread.join(); diff --git a/src/main/java/teetime/framework/Traversor.java b/src/main/java/teetime/framework/Traversor.java index 82ac218e31b10d93a25de53ead1f845b94a333c5..39ebed6e43ec796831c79c04b300ea5286dd7c62 100644 --- a/src/main/java/teetime/framework/Traversor.java +++ b/src/main/java/teetime/framework/Traversor.java @@ -24,14 +24,14 @@ import teetime.framework.pipe.IPipe; public class Traversor { private final IPipeVisitor pipeVisitor; - private final Set<Stage> visitedStage = new HashSet<Stage>(); + private final Set<Stage> visitedStages = new HashSet<Stage>(); public Traversor(final IPipeVisitor pipeVisitor) { this.pipeVisitor = pipeVisitor; } public void traverse(final Stage stage) { - if (!visitedStage.add(stage)) { + if (!visitedStages.add(stage)) { return; } @@ -46,6 +46,6 @@ public class Traversor { } public Set<Stage> getVisitedStage() { - return visitedStage; + return visitedStages; } } diff --git a/src/main/java/teetime/framework/pipe/PipeFactoryLoader.java b/src/main/java/teetime/framework/pipe/PipeFactoryLoader.java index 1c75785c41ee6999a11f09aaef36dc240850b2b3..b2673d4d0df8a7510b9e029ffc3d57bd4018fb28 100644 --- a/src/main/java/teetime/framework/pipe/PipeFactoryLoader.java +++ b/src/main/java/teetime/framework/pipe/PipeFactoryLoader.java @@ -70,7 +70,6 @@ public final class PipeFactoryLoader { } public static List<IPipeFactory> loadPipeFactoriesFromClasspath(final String configFileName) { - List<URL> files = null; try { diff --git a/src/main/java/teetime/framework/pipe/SpScPipe.java b/src/main/java/teetime/framework/pipe/SpScPipe.java index 4c1e52ae7edb9fce65bfe349314afb5b379e4f34..7d68aafb9af1ffdefcb242f1eb1d042bcfe493d3 100644 --- a/src/main/java/teetime/framework/pipe/SpScPipe.java +++ b/src/main/java/teetime/framework/pipe/SpScPipe.java @@ -41,9 +41,9 @@ final class SpScPipe extends AbstractInterThreadPipe implements IMonitorablePipe return pipe; } + // BETTER introduce a QueueIsFullStrategy @Override public boolean add(final Object element) { - // BETTER introduce a QueueIsFullStrategy while (!this.queue.offer(element)) { // Thread.yield(); if (this.cachedTargetStage.getCurrentState() == StageState.TERMINATED) { diff --git a/src/main/java/teetime/framework/pipe/UnorderedGrowablePipe.java b/src/main/java/teetime/framework/pipe/UnorderedGrowablePipe.java index 9baa545f3a0788ac384df2cd4ae5768cced97d55..e9ef0e9688b5969d1d43780b363059673bf2c621 100644 --- a/src/main/java/teetime/framework/pipe/UnorderedGrowablePipe.java +++ b/src/main/java/teetime/framework/pipe/UnorderedGrowablePipe.java @@ -49,9 +49,6 @@ final class UnorderedGrowablePipe extends AbstractIntraThreadPipe { @Override public Object removeLast() { - // if (this.lastFreeIndex == 0) { - // return null; - // } final Object element = this.elements[--this.lastFreeIndex]; this.elements[this.lastFreeIndex] = null; // T element = this.elements.get(--this.lastFreeIndex); diff --git a/src/main/java/teetime/stage/CipherStage.java b/src/main/java/teetime/stage/CipherStage.java index 78d2ef2ade608c214bf9be7e06a643c22f6aebba..143e907698d26deb73996244325bd704147c8ae5 100644 --- a/src/main/java/teetime/stage/CipherStage.java +++ b/src/main/java/teetime/stage/CipherStage.java @@ -82,8 +82,8 @@ public final class CipherStage extends AbstractConsumerStage<byte[]> { @Override protected void execute(final byte[] element) { try { - byte[] output = this.cipher.doFinal(element); - this.outputPort.send(output); + byte[] outputBytes = this.cipher.doFinal(element); + this.outputPort.send(outputBytes); } catch (IllegalBlockSizeException e) { throw new IllegalStateException(e); } catch (BadPaddingException e) { diff --git a/src/main/java/teetime/stage/ZipByteArray.java b/src/main/java/teetime/stage/ZipByteArray.java index b59e4e26c14e4d81e6bb627eec88b53ebb2b5eb9..0d92875d46095c03899d7ade6a3994886abf52e1 100644 --- a/src/main/java/teetime/stage/ZipByteArray.java +++ b/src/main/java/teetime/stage/ZipByteArray.java @@ -45,17 +45,17 @@ public final class ZipByteArray extends AbstractConsumerStage<byte[]> { @Override protected void execute(final byte[] element) { - byte[] cache = null; + byte[] streamBytes = null; try { if (mode == ZipMode.COMP) { - cache = compress(element); + streamBytes = compress(element); } else { - cache = decompress(element); + streamBytes = decompress(element); } } catch (Exception e) { e.printStackTrace(); } - outputPort.send(cache); + outputPort.send(streamBytes); } private byte[] compress(final byte[] data) throws IOException { @@ -65,17 +65,17 @@ public final class ZipByteArray extends AbstractConsumerStage<byte[]> { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); deflater.finish(); - byte[] buffer = new byte[1024]; + byte[] buffer = new byte[1024]; // NOPMD while (!deflater.finished()) { int count = deflater.deflate(buffer); // returns the generated code... index outputStream.write(buffer, 0, count); } outputStream.close(); - byte[] output = outputStream.toByteArray(); + byte[] outputBytes = outputStream.toByteArray(); deflater.end(); - return output; + return outputBytes; } private byte[] decompress(final byte[] data) throws IOException, DataFormatException { @@ -83,17 +83,17 @@ public final class ZipByteArray extends AbstractConsumerStage<byte[]> { inflater.setInput(data); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); - byte[] buffer = new byte[1024]; + byte[] buffer = new byte[1024]; // NOPMD while (!inflater.finished()) { int count = inflater.inflate(buffer); outputStream.write(buffer, 0, count); } outputStream.close(); - byte[] output = outputStream.toByteArray(); + byte[] outputBytes = outputStream.toByteArray(); inflater.end(); - return output; + return outputBytes; } public OutputPort<? extends byte[]> getOutputPort() { diff --git a/src/main/java/teetime/stage/io/ByteArrayFileWriter.java b/src/main/java/teetime/stage/io/ByteArrayFileWriter.java index 93375cd7d877cbbcbb516d7f6570776b83074efe..abebaeab55c8fd83757ec4a7903a6e5be60eeee1 100644 --- a/src/main/java/teetime/stage/io/ByteArrayFileWriter.java +++ b/src/main/java/teetime/stage/io/ByteArrayFileWriter.java @@ -40,7 +40,6 @@ public final class ByteArrayFileWriter extends AbstractConsumerStage<byte[]> { @Override protected void execute(final byte[] element) { - try { fo.write(element); } catch (Exception e) { diff --git a/src/main/java/teetime/stage/io/File2ByteArray.java b/src/main/java/teetime/stage/io/File2ByteArray.java index 387a999746f6df0247be3e7ffd65775fedfa8cf1..caa51fb5f5b608ee6d3525e7d323469ee82e5eae 100644 --- a/src/main/java/teetime/stage/io/File2ByteArray.java +++ b/src/main/java/teetime/stage/io/File2ByteArray.java @@ -30,8 +30,8 @@ public final class File2ByteArray extends AbstractConsumerStage<File> { @Override protected void execute(final File element) { try { - byte[] cache = Files.toByteArray(element); - outputPort.send(cache); + byte[] fileBytes = Files.toByteArray(element); + outputPort.send(fileBytes); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/src/main/java/teetime/stage/string/buffer/StringBufferFilter.java b/src/main/java/teetime/stage/string/buffer/StringBufferFilter.java deleted file mode 100644 index cd187eff2679e60fff5a7312b88c35b585d24064..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/string/buffer/StringBufferFilter.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.stage.string.buffer; - -import java.util.Collection; -import java.util.LinkedList; - -import teetime.framework.AbstractConsumerStage; -import teetime.framework.OutputPort; -import teetime.stage.string.buffer.handler.AbstractDataTypeHandler; -import teetime.stage.string.buffer.util.KiekerHashMap; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public final class StringBufferFilter<T> extends AbstractConsumerStage<T> { - - private final OutputPort<T> outputPort = this.createOutputPort(); - - // BETTER use a non shared data structure to avoid synchronization between threads - private KiekerHashMap kiekerHashMap = new KiekerHashMap(); - - private Collection<AbstractDataTypeHandler<?>> dataTypeHandlers = new LinkedList<AbstractDataTypeHandler<?>>(); - - @Override - protected void execute(final T element) { - final T returnedElement = this.handle(element); - outputPort.send(returnedElement); - } - - @Override - public void onStarting() throws Exception { - super.onStarting(); - for (final AbstractDataTypeHandler<?> handler : this.dataTypeHandlers) { - handler.setLogger(this.logger); - handler.setStringRepository(this.kiekerHashMap); - } - } - - private T handle(final T object) { - for (final AbstractDataTypeHandler<?> handler : this.dataTypeHandlers) { - if (handler.canHandle(object)) { - @SuppressWarnings("unchecked") - final T returnedObject = ((AbstractDataTypeHandler<T>) handler).handle(object); - return returnedObject; - } - } - return object; // else relay given object - } - - public KiekerHashMap getKiekerHashMap() { - return this.kiekerHashMap; - } - - public void setKiekerHashMap(final KiekerHashMap kiekerHashMap) { - this.kiekerHashMap = kiekerHashMap; - } - - public Collection<AbstractDataTypeHandler<?>> getDataTypeHandlers() { - return this.dataTypeHandlers; - } - - public void setDataTypeHandlers(final Collection<AbstractDataTypeHandler<?>> dataTypeHandlers) { - this.dataTypeHandlers = dataTypeHandlers; - } - - public OutputPort<T> getOutputPort() { - return outputPort; - } - -} diff --git a/src/main/java/teetime/stage/string/buffer/handler/AbstractDataTypeHandler.java b/src/main/java/teetime/stage/string/buffer/handler/AbstractDataTypeHandler.java deleted file mode 100644 index 6f4540cdfd1040c94e2971142543a29d4f4a2a59..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/string/buffer/handler/AbstractDataTypeHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.stage.string.buffer.handler; - -import org.slf4j.Logger; - -import teetime.stage.string.buffer.util.KiekerHashMap; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public abstract class AbstractDataTypeHandler<T> { - - protected Logger logger; - protected KiekerHashMap stringRepository; - - /** - * @since 1.10 - */ - public abstract boolean canHandle(Object object); - - /** - * @since 1.10 - */ - public abstract T handle(T object); - - /** - * @since 1.10 - */ - public void setLogger(final Logger logger) { - this.logger = logger; - } - - /** - * @since 1.10 - */ - public void setStringRepository(final KiekerHashMap stringRepository) { - this.stringRepository = stringRepository; - } - -} diff --git a/src/main/java/teetime/stage/string/buffer/handler/StringHandler.java b/src/main/java/teetime/stage/string/buffer/handler/StringHandler.java deleted file mode 100644 index bef40e5d09b74761661ad93725f3342d902c0edc..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/string/buffer/handler/StringHandler.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.stage.string.buffer.handler; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class StringHandler extends AbstractDataTypeHandler<String> { - - @Override - public boolean canHandle(final Object object) { - return object instanceof String; - } - - @Override - public String handle(final String object) { - return this.stringRepository.get(object); - } - -} diff --git a/src/main/java/teetime/stage/string/buffer/util/KiekerHashMap.java b/src/main/java/teetime/stage/string/buffer/util/KiekerHashMap.java deleted file mode 100644 index 1806abe5718cf67b3c6bf714ea30c741b82348db..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/stage/string/buffer/util/KiekerHashMap.java +++ /dev/null @@ -1,291 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.stage.string.buffer.util; - -import java.lang.ref.SoftReference; -import java.util.concurrent.locks.ReentrantLock; - -/** - * @author Christian Wulf - * - * @since 1.10 - */ -public class KiekerHashMap { - - private static final int INITIAL_CAPACITY = 16; - private static final double LOAD_FACTOR = 0.75d; - private static final int CONCURRENCY_LEVEL = 16; - private static final int MAXIMUM_CAPACITY = 1 << 30; - - /** - * Mask value for indexing into segments. The upper bits of a key's hash code are used to choose the segment. - */ - private final int segmentMask; - - /** - * Shift value for indexing within segments. - */ - private final int segmentShift; - - /** - * The segments, each of which is a specialized hash table. - */ - private final Segment[] segments; - - /** - * @since 1.10 - */ - public KiekerHashMap() { - // Find power-of-two sizes best matching arguments - int sshift = 0; - int ssize = 1; - while (ssize < CONCURRENCY_LEVEL) { - ++sshift; - ssize <<= 1; - } - this.segmentShift = 32 - sshift; - this.segmentMask = ssize - 1; - this.segments = new Segment[ssize]; - int c = INITIAL_CAPACITY / ssize; - if ((c * ssize) < INITIAL_CAPACITY) { - ++c; - } - int cap = 1; - while (cap < c) { - cap <<= 1; - } - for (int i = 0; i < this.segments.length; ++i) { - this.segments[i] = new Segment(cap, LOAD_FACTOR); - } - } - - /** - * Applies a supplemental hash function to a given hashCode, which defends against poor quality hash functions. This is critical because ConcurrentHashMap uses - * power-of-two length hash tables, that otherwise encounter collisions for hashCodes that do not differ in lower or upper bits. - */ - private static final int hash(final String value) { - // Spread bits to regularize both segment and index locations, using variant of single-word Wang/Jenkins hash. - int h = value.hashCode(); - h += (h << 15) ^ 0xffffcd7d; - h ^= h >>> 10; - h += h << 3; - h ^= h >>> 6; - h += (h << 2) + (h << 14); - return h ^ (h >>> 16); - } - - public final String get(final String value) { - final int hash = KiekerHashMap.hash(value); - Segment segment = this.segments[(hash >>> this.segmentShift) & this.segmentMask]; - return segment.get(value, hash); - } - - // ---------------- Inner Classes -------------- - - /** - * StringBuffer entry. - */ - private static final class HashEntry extends SoftReference<String> { - final int hash; - final HashEntry next; - - protected HashEntry(final String value, final int hash, final HashEntry next) { - super(value); - this.hash = hash; - this.next = next; - } - } - - /** - * Segments are specialized versions of hash tables. This subclasses from ReentrantLock opportunistically, just to simplify some locking and avoid separate - * construction. - * - * Segments maintain a table of entry lists that are ALWAYS kept in a consistent state, so can be read without locking. Next fields of nodes are immutable - * (final). All list additions are performed at the front of each bin. This makes it easy to check changes, and also fast to traverse. When nodes would - * otherwise be changed, new nodes are created to replace them. This works well for hash tables since the bin lists tend to be short. (The average length is - * less than two for the default load factor threshold.) - * - * Read operations can thus proceed without locking, but rely on selected uses of volatiles to ensure that completed write operations performed by other - * threads are noticed. For most purposes, the "count" field, tracking the number of elements, serves as that volatile variable ensuring visibility. This is - * convenient because this field needs to be read in many read operations anyway: - * - * - All (unsynchronized) read operations must first read the "count" field, and should not look at table entries if it is 0. - * - * - All (synchronized) write operations should write to the "count" field after structurally changing any bin. The operations must not take any action that - * could even momentarily cause a concurrent read operation to see inconsistent data. This is made easier by the nature of the read operations in Map. For - * example, no operation can reveal that the table has grown but the threshold has not yet been updated, so there are no atomicity requirements for this with - * respect to reads. - * - * As a guide, all critical volatile reads and writes to the count field are marked in code comments. - */ - private static final class Segment extends ReentrantLock { - - private static final long serialVersionUID = 1L; - - /** - * The number of elements in this segment's region. - */ - private volatile int count; - - /** - * The per-segment table. - */ - private HashEntry[] table; - - /** - * The table is rehashed when its size exceeds this threshold. (The value of this field is always <tt>(int)(capacity * loadFactor)</tt>.) - */ - private int threshold; - - protected Segment(final int initialCapacity, final double lf) { - this.table = new HashEntry[initialCapacity]; - this.threshold = (int) (initialCapacity * lf); - this.count = 0; - } - - protected final String get(final String value, final int hash) { - HashEntry e = null; - String cachedString; - if (this.count != 0) { // volatile read! search for entry without locking - final HashEntry[] tab = this.table; - final int index = hash & (tab.length - 1); - final HashEntry first = tab[index]; - e = first; - while (e != null) { - if (e.hash == hash) { - cachedString = e.get(); - if (value.equals(cachedString)) { - return cachedString; - } - } - e = e.next; - } - } - this.lock(); - try { - final int c = this.count + 1; - if (c >= this.threshold) { - this.cleanup(); - if (c >= this.threshold) { // if still full - this.rehash(); - } - this.count = c; // write volatile - } - final HashEntry[] tab = this.table; - final int index = hash & (tab.length - 1); - final HashEntry first = tab[index]; // the bin the value may be inside - e = first; - while (e != null) { - if (e.hash == hash) { - cachedString = e.get(); - if (value.equals(cachedString)) { - return cachedString; - } - } - e = e.next; - } - tab[index] = new HashEntry(value, hash, first); - this.count = c; // write-volatile - return value; // return now cached string - } finally { - this.unlock(); - } - } - - private final void cleanup() { - int c = this.count; - final HashEntry[] tab = this.table; - for (int index = 0; index < tab.length; index++) { - // find first remaining entry - HashEntry e = tab[index]; - while ((e != null) && (e.get() == null)) { - e = e.next; - c--; - } - if (e == null) { - tab[index] = null; - } else { - // find more existing entries and enqueue before this one - HashEntry first = new HashEntry(e.get(), e.hash, null); - e = e.next; - while (e != null) { - final String s = e.get(); - if (s != null) { - first = new HashEntry(s, e.hash, first); - } else { - c--; - } - e = e.next; - } - tab[index] = first; - } - } - c--; - this.count = c; // write-volatile - } - - /** - * Reclassify nodes in each list to new Map. Because we are using power-of-two expansion, the elements from each bin must either stay at same index, or - * move with a power of two offset. We eliminate unnecessary node creation by catching cases where old nodes can be reused because their next fields - * won't change. Statistically, at the default threshold, only about one-sixth of them need cloning when a table doubles. The nodes they replace will be - * garbage collectable as soon as they are no longer referenced by any reader thread that may be in the midst of traversing table right now. - */ - private final void rehash() { - final HashEntry[] oldTable = this.table; - final int oldCapacity = oldTable.length; - if (oldCapacity >= MAXIMUM_CAPACITY) { - return; - } - final HashEntry[] newTable = new HashEntry[oldCapacity << 1]; - this.threshold = (int) (newTable.length * LOAD_FACTOR); - final int sizeMask = newTable.length - 1; - for (int i = 0; i < oldCapacity; i++) { - // We need to guarantee that any existing reads of old Map can proceed. So we cannot yet null out each bin. - final HashEntry e = oldTable[i]; - - if (e != null) { - final HashEntry next = e.next; - final int idx = e.hash & sizeMask; - - // Single node on list - if (next == null) { - newTable[idx] = e; - } else { - // Reuse trailing consecutive sequence at same slot - HashEntry lastRun = e; - int lastIdx = idx; - for (HashEntry last = next; last != null; last = last.next) { // find end of bin - final int k = last.hash & sizeMask; - if (k != lastIdx) { // NOCS (nested if) - lastIdx = k; - lastRun = last; - } - } - newTable[lastIdx] = lastRun; - - // Clone all remaining nodes - for (HashEntry p = e; p != lastRun; p = p.next) { - final int k = p.hash & sizeMask; - final HashEntry n = newTable[k]; - newTable[k] = new HashEntry(p.get(), p.hash, n); - } - } - } - } - this.table = newTable; - } - } -} diff --git a/src/main/java/teetime/util/CyclicListIterator.java b/src/main/java/teetime/util/CyclicListIterator.java index 1579d5d3c7f2966800fa2e9bd791e046037fb73c..7f7ca993af80ebea4c166ec0887b06c4cc84b869 100644 --- a/src/main/java/teetime/util/CyclicListIterator.java +++ b/src/main/java/teetime/util/CyclicListIterator.java @@ -44,6 +44,10 @@ public final class CyclicListIterator<T> implements Iterator<T> { @Override public T next() { + this.currentIndex = this.getCurrentIndex(); + final T element = this.elements.get(this.currentIndex); + this.currentIndex++; + return element; // if (!this.iterator.hasNext()) { // this.iterator = this.list.iterator(); // } @@ -52,17 +56,13 @@ public final class CyclicListIterator<T> implements Iterator<T> { // the size of the list could have been changed due to // <li>an index overflow (then restart from index 0), or // <li>an add() or a remove(), so update the index - this.currentIndex = this.getCurrentIndex(); - final T element = this.elements.get(this.currentIndex); - this.currentIndex++; - return element; } @Override public void remove() { - // this.iterator.remove(); this.currentIndex = this.getCurrentIndex(); this.elements.remove(this.currentIndex); + // this.iterator.remove(); } private int getCurrentIndex() { diff --git a/src/main/java/teetime/util/classpath/FileSearcher.java b/src/main/java/teetime/util/classpath/FileSearcher.java index be1af8218d7da5f61cc4bcea543a42234e24e743..413bcf4dbf9037f5fb9a0ec91d1a2a59224266dc 100644 --- a/src/main/java/teetime/util/classpath/FileSearcher.java +++ b/src/main/java/teetime/util/classpath/FileSearcher.java @@ -30,12 +30,12 @@ public final class FileSearcher { } public static List<URL> loadResources(final String name) throws IOException { - final List<URL> list = new ArrayList<URL>(); + final List<URL> urls = new ArrayList<URL>(); final Enumeration<URL> systemRes = CLASS_LOADER.getResources(name); while (systemRes.hasMoreElements()) { - list.add(systemRes.nextElement()); + urls.add(systemRes.nextElement()); } - return list; + return urls; } } diff --git a/src/main/java/teetime/util/concurrent/queue/takestrategy/SCParkTakeStrategy.java b/src/main/java/teetime/util/concurrent/queue/takestrategy/SCParkTakeStrategy.java index 6875d3815e8cb4d910288275b3bb8dcfa493e95e..ad8148120ca4272b1da09cc3d54fa12b71e66f78 100644 --- a/src/main/java/teetime/util/concurrent/queue/takestrategy/SCParkTakeStrategy.java +++ b/src/main/java/teetime/util/concurrent/queue/takestrategy/SCParkTakeStrategy.java @@ -26,9 +26,9 @@ public final class SCParkTakeStrategy<E> implements TakeStrategy<E> { private final AtomicReference<Thread> t = new AtomicReference<Thread>(null); @Override + // Make sure the offer is visible before unpark public void signal() { - // Make sure the offer is visible before unpark storeFence = 1; // store barrier LockSupport.unpark(t.get()); // t.get() load barrier diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinel.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinel.java index 3eabf1f6824eaca45bee788a21a8a13bf1fa3913..58294d9f731e5b23d18b99899887154d57125445 100644 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinel.java +++ b/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithSentinel.java @@ -59,6 +59,7 @@ public final class CircularWorkStealingDequeWithSentinel<T> { private volatile CircularArray<T> activeArray = new CircularArray<T>(LOG_INITIAL_SIZE); private boolean casTop(final long oldVal, final long newVal) { + return this.top.compareAndSet(oldVal, newVal); // boolean preCond; // synchronized (this) { // preCond = (this.top == oldVal); @@ -67,7 +68,6 @@ public final class CircularWorkStealingDequeWithSentinel<T> { // } // } // return preCond; - return this.top.compareAndSet(oldVal, newVal); } public void pushBottom(final T o) { diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinel.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinel.java index 5cec666e37a44423a4e2aa1d580fd370f14e2977..3b0327d7533e00505cb4adc729703f76d05ac811 100644 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinel.java +++ b/src/main/java/teetime/util/concurrent/workstealing/alternative/CircularWorkStealingDequeWithThreadLocalSentinel.java @@ -71,6 +71,7 @@ public final class CircularWorkStealingDequeWithThreadLocalSentinel<T> { } private boolean casTop(final long oldVal, final long newVal) { + return this.top.compareAndSet(oldVal, newVal); // boolean preCond; // synchronized (this) { // preCond = (this.top == oldVal); @@ -79,7 +80,6 @@ public final class CircularWorkStealingDequeWithThreadLocalSentinel<T> { // } // } // return preCond; - return this.top.compareAndSet(oldVal, newVal); } public void pushBottom(final T o) { diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDeque.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDeque.java index 4dc084bf7c8a2ec5a726941e70928f0cdf088ab1..8a45faeffacac44d4fecc8062bc8f6fdc864c0aa 100644 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDeque.java +++ b/src/main/java/teetime/util/concurrent/workstealing/alternative/ExceptionalCircularWorkStealingDeque.java @@ -43,6 +43,7 @@ public final class ExceptionalCircularWorkStealingDeque<T> { private volatile CircularArray<T> activeArray = new CircularArray<T>(LOG_INITIAL_SIZE); private boolean casTop(final long oldVal, final long newVal) { + return this.top.compareAndSet(oldVal, newVal); // boolean preCond; // synchronized (this) { // preCond = (this.top == oldVal); @@ -51,7 +52,6 @@ public final class ExceptionalCircularWorkStealingDeque<T> { // } // } // return preCond; - return this.top.compareAndSet(oldVal, newVal); } public void pushBottom(final T o) { diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDeque.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDeque.java index e5518e7c8db6bfc80dbbf5f3a803ba1e3747cadb..57501cfd888205242fb4a0a7f457254c8d065578 100644 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDeque.java +++ b/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedCircularWorkStealingDeque.java @@ -39,6 +39,7 @@ public final class UntypedCircularWorkStealingDeque { private volatile CircularArray<Object> activeArray = new CircularArray<Object>(LOG_INITIAL_SIZE); private boolean casTop(final long oldVal, final long newVal) { + return this.top.compareAndSet(oldVal, newVal); // boolean preCond; // synchronized (this) { // preCond = (this.top == oldVal); @@ -47,7 +48,6 @@ public final class UntypedCircularWorkStealingDeque { // } // } // return preCond; - return this.top.compareAndSet(oldVal, newVal); } public void pushBottom(final Object o) { diff --git a/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDeque.java b/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDeque.java index f5d37b94e7f6d652dd098e282e5ad19e1499f32d..381aea46e52ac46a4f1f01ce47bb31a9a0764db4 100644 --- a/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDeque.java +++ b/src/main/java/teetime/util/concurrent/workstealing/alternative/UntypedExceptionalCircularWorkStealingDeque.java @@ -44,6 +44,7 @@ public final class UntypedExceptionalCircularWorkStealingDeque { private volatile CircularArray<Object> activeArray = new CircularArray<Object>(LOG_INITIAL_SIZE); private boolean casTop(final long oldVal, final long newVal) { + return this.top.compareAndSet(oldVal, newVal); // boolean preCond; // synchronized (this) { // preCond = (this.top == oldVal); @@ -52,7 +53,6 @@ public final class UntypedExceptionalCircularWorkStealingDeque { // } // } // return preCond; - return this.top.compareAndSet(oldVal, newVal); } public void pushBottom(final Object o) { diff --git a/src/main/java/teetime/util/list/CommittableResizableArrayQueue.java b/src/main/java/teetime/util/list/CommittableResizableArrayQueue.java index 4349a2ae49a07462c6278948c91d8e70a7039cd2..709d22d7d76c14c307a68d3f219719b99609afd5 100644 --- a/src/main/java/teetime/util/list/CommittableResizableArrayQueue.java +++ b/src/main/java/teetime/util/list/CommittableResizableArrayQueue.java @@ -51,16 +51,16 @@ public final class CommittableResizableArrayQueue<T> implements CommittableQueue @Override public T removeFromHeadUncommitted() { + T element = this.get(--this.lastFreeIndexUncommitted); // if (this.capacity() > this.MIN_CAPACITY && this.lastFreeIndexUncommitted < this.capacity() / 2) { // TODO uncomment // this.shrink(); // } - T element = this.get(--this.lastFreeIndexUncommitted); return element; } @Override + // TODO set elements to null to help the gc public void commit() { - // TODO set elements to null to help the gc this.lastFreeIndex = this.lastFreeIndexUncommitted; } @@ -109,10 +109,10 @@ public final class CommittableResizableArrayQueue<T> implements CommittableQueue } private final void copyArray(final T[] elements, final T[] newElements) { + System.arraycopy(elements, 0, newElements, 0, this.lastFreeIndexUncommitted + 1); // for (int i = 0; i < this.lastFreeIndexUncommitted; i++) { // newElements[i] = elements[i]; // } - System.arraycopy(elements, 0, newElements, 0, this.lastFreeIndexUncommitted + 1); } private final void put(final int index, final T element) { diff --git a/src/main/java/teetime/util/list/ListContainerPool.java b/src/main/java/teetime/util/list/ListContainerPool.java index d470a3ef1314a30407e4250511ffb365c6288d2d..8d1d7f943106d73b16433a5613a30cf40655bab6 100644 --- a/src/main/java/teetime/util/list/ListContainerPool.java +++ b/src/main/java/teetime/util/list/ListContainerPool.java @@ -20,7 +20,7 @@ import java.util.List; public final class ListContainerPool<T> implements ObjectPool<ListContainer<T>> { - private final List<ListContainer<T>> pool = new ArrayList<ListContainer<T>>(); + private final List<ListContainer<T>> pool = new ArrayList<ListContainer<T>>(); // NOPMD public ListContainerPool(int initialPoolSize) { while (initialPoolSize-- > 0) { diff --git a/src/test/java/teetime/examples/tokenizer/TokenizerTest.java b/src/test/java/teetime/examples/tokenizer/TokenizerTest.java index b1396eae30773290f18e1a5aa0a511c63d1280dc..070c722444cec08e8870f05a6eb0e8512ba4e024 100644 --- a/src/test/java/teetime/examples/tokenizer/TokenizerTest.java +++ b/src/test/java/teetime/examples/tokenizer/TokenizerTest.java @@ -38,8 +38,7 @@ public class TokenizerTest { @Test public void executeTest() throws IOException { - // Encrypted lorem ipsum - final String inputFile = "src/test/resources/data/cipherInput.txt"; + final String inputFile = "src/test/resources/data/cipherInput.txt"; // Encrypted lorem ipsum final String password = "Password"; final TokenizerConfiguration configuration = new TokenizerConfiguration(inputFile, password); diff --git a/src/test/java/teetime/framework/TraversorTest.java b/src/test/java/teetime/framework/TraversorTest.java index 9f4ef25077219463a7ea4c4df72ba4082b89f94d..35a7826b5800186a72416d97e18a58f8662292b9 100644 --- a/src/test/java/teetime/framework/TraversorTest.java +++ b/src/test/java/teetime/framework/TraversorTest.java @@ -41,11 +41,11 @@ public class TraversorTest { public void traverse() { TestConfiguration tc = new TestConfiguration(); traversor.traverse(tc.init); - Set<Stage> comparingSet = new HashSet<Stage>(); - comparingSet.add(tc.init); - comparingSet.add(tc.f2b); - comparingSet.add(tc.distributor); - assertTrue(comparingSet.equals(traversor.getVisitedStage())); + Set<Stage> comparingStages = new HashSet<Stage>(); + comparingStages.add(tc.init); + comparingStages.add(tc.f2b); + comparingStages.add(tc.distributor); + assertTrue(comparingStages.equals(traversor.getVisitedStage())); } // WordCounterConfiguration diff --git a/src/test/java/teetime/framework/pipe/PipeFactoryLoaderTest.java b/src/test/java/teetime/framework/pipe/PipeFactoryLoaderTest.java index f6418cc01c8b19a660c997129a57819e9396c45b..6ca257a8995f333386703af90d5313bb2dab7602 100644 --- a/src/test/java/teetime/framework/pipe/PipeFactoryLoaderTest.java +++ b/src/test/java/teetime/framework/pipe/PipeFactoryLoaderTest.java @@ -35,15 +35,15 @@ public class PipeFactoryLoaderTest { @Test public void emptyConfig() throws IOException { - final List<IPipeFactory> list = PipeFactoryLoader.loadPipeFactoriesFromClasspath("data/empty-test.conf"); - Assert.assertEquals(true, list.isEmpty()); + final List<IPipeFactory> pipeFactories = PipeFactoryLoader.loadPipeFactoriesFromClasspath("data/empty-test.conf"); + Assert.assertEquals(true, pipeFactories.isEmpty()); } @Test public void singleConfig() throws IOException { - final List<IPipeFactory> list = PipeFactoryLoader.loadPipeFactoriesFromClasspath("pipe-factories.conf"); + final List<IPipeFactory> pipeFactories = PipeFactoryLoader.loadPipeFactoriesFromClasspath("pipe-factories.conf"); final int lines = Files.readLines(new File("target/classes/pipe-factories.conf"), Charsets.UTF_8).size(); - Assert.assertEquals(lines, list.size()); + Assert.assertEquals(lines, pipeFactories.size()); } @Test diff --git a/src/test/java/teetime/stage/CipherStageTest.java b/src/test/java/teetime/stage/CipherStageTest.java index 4f2d8799d3fc17f8c41662563c7a4f3609c54505..d1a28829815331f1a92a2267cced8da6d46d9f79 100644 --- a/src/test/java/teetime/stage/CipherStageTest.java +++ b/src/test/java/teetime/stage/CipherStageTest.java @@ -36,14 +36,14 @@ public class CipherStageTest { final CipherStage encryptStage = new CipherStage("somePassword", CipherMode.ENCRYPT); final CipherStage decryptStage = new CipherStage("somePassword", CipherMode.DECRYPT); - final byte[] input = new byte[] { 1, 2, 3, 4, 5 }; - final List<byte[]> encryptedResult = new ArrayList<byte[]>(); - final List<byte[]> decryptedResult = new ArrayList<byte[]>(); + final byte[] inputBytes = new byte[] { 1, 2, 3, 4, 5 }; + final List<byte[]> encryptedBytes = new ArrayList<byte[]>(); + final List<byte[]> decryptedBytes = new ArrayList<byte[]>(); - test(encryptStage).and().send(input).to(encryptStage.getInputPort()).and().receive(encryptedResult).from(encryptStage.getOutputPort()).start(); - test(decryptStage).and().send(encryptedResult).to(decryptStage.getInputPort()).and().receive(decryptedResult).from(decryptStage.getOutputPort()).start(); + test(encryptStage).and().send(inputBytes).to(encryptStage.getInputPort()).and().receive(encryptedBytes).from(encryptStage.getOutputPort()).start(); + test(decryptStage).and().send(encryptedBytes).to(decryptStage.getInputPort()).and().receive(decryptedBytes).from(decryptStage.getOutputPort()).start(); - assertThat(decryptedResult, contains(input)); + assertThat(decryptedBytes, contains(inputBytes)); } } diff --git a/src/test/java/teetime/stage/InitialElementProducerTest.java b/src/test/java/teetime/stage/InitialElementProducerTest.java index 5667be30ab0836949341b7e260fbbf7b5f99cca7..9f15e2af0b3fc5e0b09189337e83b6628f637b22 100644 --- a/src/test/java/teetime/stage/InitialElementProducerTest.java +++ b/src/test/java/teetime/stage/InitialElementProducerTest.java @@ -87,11 +87,11 @@ public class InitialElementProducerTest { @Test public void instantiateWithIterable() { - List<Integer> test = new ArrayList<Integer>(); - test.add(1); - test.add(2); - test.add(3); - producer = new InitialElementProducer<Integer>(test); + List<Integer> testIntegers = new ArrayList<Integer>(); + testIntegers.add(1); + testIntegers.add(2); + testIntegers.add(3); + producer = new InitialElementProducer<Integer>(testIntegers); List<Integer> results = new ArrayList<Integer>(); test(producer).and().receive(results).from(producer.getOutputPort()).start(); diff --git a/src/test/java/teetime/stage/InstanceCounterTest.java b/src/test/java/teetime/stage/InstanceCounterTest.java index 65ee1b09187a408a444ec8da4f61157c49df9329..e8286613c074330e1e5e10508dd35ee78c4c3445 100644 --- a/src/test/java/teetime/stage/InstanceCounterTest.java +++ b/src/test/java/teetime/stage/InstanceCounterTest.java @@ -66,15 +66,15 @@ public class InstanceCounterTest { @Test public void filterShouldWorkWithMultipleInput() { - final List<Object> input = new ArrayList<Object>(); + final List<Object> inputObjects = new ArrayList<Object>(); - input.add(new Object()); - input.add(new Clazz()); - input.add(new Object()); - input.add(new SubClazz()); - input.add(new Object()); + inputObjects.add(new Object()); + inputObjects.add(new Clazz()); + inputObjects.add(new Object()); + inputObjects.add(new SubClazz()); + inputObjects.add(new Object()); - test(this.filter).and().send(input).to(this.filter.getInputPort()).start(); + test(this.filter).and().send(inputObjects).to(this.filter.getInputPort()).start(); assertThat(this.filter.getCounter(), is(2)); } diff --git a/src/test/java/teetime/stage/InstanceOfFilterTest.java b/src/test/java/teetime/stage/InstanceOfFilterTest.java index 186ce0c44fe7017f5bfd2be494f67d539f254db0..8abd3018b5122f409e023e936f30dd6a1377892a 100644 --- a/src/test/java/teetime/stage/InstanceOfFilterTest.java +++ b/src/test/java/teetime/stage/InstanceOfFilterTest.java @@ -88,16 +88,16 @@ public class InstanceOfFilterTest { @Test public void filterShouldWorkWithMultipleInput() { final List<Clazz> results = new ArrayList<InstanceOfFilterTest.Clazz>(); - final List<Object> input = new ArrayList<Object>(); + final List<Object> inputObjects = new ArrayList<Object>(); - input.add(new Object()); - input.add(new Clazz()); - input.add(new Object()); - input.add(new SubClazz()); - input.add(new Object()); + inputObjects.add(new Object()); + inputObjects.add(new Clazz()); + inputObjects.add(new Object()); + inputObjects.add(new SubClazz()); + inputObjects.add(new Object()); test(filter) - .and().send(input).to(filter.getInputPort()) + .and().send(inputObjects).to(filter.getInputPort()) .and().receive(results).from(filter.getMatchedOutputPort()) .start(); diff --git a/src/test/java/teetime/stage/MultipleInstanceOfFilterTest.java b/src/test/java/teetime/stage/MultipleInstanceOfFilterTest.java index 6221ba7733486296626f1b55ea5fb486d2db96c6..a1b8577b6f4a3abe172b89723c49dc8354de2a7d 100644 --- a/src/test/java/teetime/stage/MultipleInstanceOfFilterTest.java +++ b/src/test/java/teetime/stage/MultipleInstanceOfFilterTest.java @@ -39,24 +39,24 @@ public class MultipleInstanceOfFilterTest { @SuppressWarnings("unchecked") public void filteringForSingleTypeShouldWork() { final MultipleInstanceOfFilter<Object> filter = new MultipleInstanceOfFilter<Object>(); - final List<Object> input = new ArrayList<Object>(Arrays.asList("1", 1.5f, "2", 2.5f, "3", 3.5f)); - final List<String> result = new ArrayList<String>(); + final List<Object> inputObjects = new ArrayList<Object>(Arrays.asList("1", 1.5f, "2", 2.5f, "3", 3.5f)); + final List<String> receivedStrings = new ArrayList<String>(); - StageTester.test(filter).and().send(input).to(filter.getInputPort()).and().receive(result).from(filter.getOutputPortForType(String.class)).start(); + StageTester.test(filter).and().send(inputObjects).to(filter.getInputPort()).and().receive(receivedStrings).from(filter.getOutputPortForType(String.class)).start(); - assertThat(result, is(not(empty()))); - assertThat(result, contains("1", "2", "3")); + assertThat(receivedStrings, is(not(empty()))); + assertThat(receivedStrings, contains("1", "2", "3")); } @Test @SuppressWarnings("unchecked") public void filteringForMultipleTypesShouldWork() { final MultipleInstanceOfFilter<Number> filter = new MultipleInstanceOfFilter<Number>(); - final List<Number> input = new ArrayList<Number>(Arrays.asList(1, 1.5f, 2, 2.5f, 3, 3.5f)); + final List<Number> inputObjects = new ArrayList<Number>(Arrays.asList(1, 1.5f, 2, 2.5f, 3, 3.5f)); final List<Integer> integers = new ArrayList<Integer>(); final List<Float> floats = new ArrayList<Float>(); - StageTester.test(filter).and().send(input).to(filter.getInputPort()).and().receive(integers).from(filter.getOutputPortForType(Integer.class)).and() + StageTester.test(filter).and().send(inputObjects).to(filter.getInputPort()).and().receive(integers).from(filter.getOutputPortForType(Integer.class)).and() .receive(floats).from(filter.getOutputPortForType(Float.class)).start(); assertThat(integers, contains(1, 2, 3)); diff --git a/src/test/java/teetime/stage/basic/distributor/DistributorTest.java b/src/test/java/teetime/stage/basic/distributor/DistributorTest.java index 9f40fe64b7bd57b0466e1f70f37ea3d91bbdb337..ecdeb41cde42135f1c2bb54d0eaf20cc628a7f84 100644 --- a/src/test/java/teetime/stage/basic/distributor/DistributorTest.java +++ b/src/test/java/teetime/stage/basic/distributor/DistributorTest.java @@ -32,7 +32,7 @@ import org.junit.rules.ExpectedException; /** * @author Nils Christian Ehmke - * + * * @since 1.0 */ public class DistributorTest { @@ -41,58 +41,60 @@ public class DistributorTest { public ExpectedException expectedException = ExpectedException.none(); private Distributor<Integer> distributor; - private List<Integer> fstList; - private List<Integer> sndList; + private List<Integer> firstIntegers; + private List<Integer> secondIntegers; @Before public void initializeDistributor() throws Exception { this.distributor = new Distributor<Integer>(); - this.fstList = new ArrayList<Integer>(); - this.sndList = new ArrayList<Integer>(); + this.firstIntegers = new ArrayList<Integer>(); + this.secondIntegers = new ArrayList<Integer>(); } @Test public void roundRobinShouldWork() { distributor.setStrategy(new RoundRobinStrategy()); - test(distributor).and().send(1, 2, 3, 4, 5).to(distributor.getInputPort()).and().receive(fstList).from(distributor.getNewOutputPort()).and() - .receive(sndList).from(distributor.getNewOutputPort()).start(); + test(distributor).and().send(1, 2, 3, 4, 5).to(distributor.getInputPort()).and().receive(firstIntegers).from(distributor.getNewOutputPort()).and() + .receive(secondIntegers).from(distributor.getNewOutputPort()).start(); - assertThat(this.fstList, contains(1, 3, 5)); - assertThat(this.sndList, contains(2, 4)); + assertThat(this.firstIntegers, contains(1, 3, 5)); + assertThat(this.secondIntegers, contains(2, 4)); } @Test public void singleElementRoundRobinShouldWork() { distributor.setStrategy(new RoundRobinStrategy()); - test(distributor).and().send(1).to(distributor.getInputPort()).and().receive(fstList).from(distributor.getNewOutputPort()).and().receive(sndList) + test(distributor).and().send(1).to(distributor.getInputPort()).and().receive(firstIntegers).from(distributor.getNewOutputPort()).and() + .receive(secondIntegers) .from(distributor.getNewOutputPort()).start(); - assertThat(this.fstList, contains(1)); - assertThat(this.sndList, is(empty())); + assertThat(this.firstIntegers, contains(1)); + assertThat(this.secondIntegers, is(empty())); } @Test public void copyByReferenceShouldWork() { distributor.setStrategy(new CopyByReferenceStrategy()); - test(distributor).and().send(1, 2, 3, 4, 5).to(distributor.getInputPort()).and().receive(fstList).from(distributor.getNewOutputPort()).and() - .receive(sndList).from(distributor.getNewOutputPort()).start(); + test(distributor).and().send(1, 2, 3, 4, 5).to(distributor.getInputPort()).and().receive(firstIntegers).from(distributor.getNewOutputPort()).and() + .receive(secondIntegers).from(distributor.getNewOutputPort()).start(); - assertThat(this.fstList, contains(1, 2, 3, 4, 5)); - assertThat(this.sndList, contains(1, 2, 3, 4, 5)); + assertThat(this.firstIntegers, contains(1, 2, 3, 4, 5)); + assertThat(this.secondIntegers, contains(1, 2, 3, 4, 5)); } @Test public void singleElementCopyByReferenceShouldWork() { distributor.setStrategy(new CopyByReferenceStrategy()); - test(distributor).and().send(1).to(distributor.getInputPort()).and().receive(fstList).from(distributor.getNewOutputPort()).and().receive(sndList) + test(distributor).and().send(1).to(distributor.getInputPort()).and().receive(firstIntegers).from(distributor.getNewOutputPort()).and() + .receive(secondIntegers) .from(distributor.getNewOutputPort()).start(); - assertThat(this.fstList, contains(1)); - assertThat(this.sndList, contains(1)); + assertThat(this.firstIntegers, contains(1)); + assertThat(this.secondIntegers, contains(1)); } @Test diff --git a/src/test/java/teetime/util/classpath/FileSearcherTest.java b/src/test/java/teetime/util/classpath/FileSearcherTest.java index b79e6fa7ebd11dc07118f41d8d71144d2eb7e111..05eedee1ace93401af3a3d155bb35e79b2d09bb8 100644 --- a/src/test/java/teetime/util/classpath/FileSearcherTest.java +++ b/src/test/java/teetime/util/classpath/FileSearcherTest.java @@ -30,20 +30,20 @@ public class FileSearcherTest { @Test public void fileInClasspath() throws IOException { - final List<URL> list = FileSearcher.loadResources("pipe-factories.conf"); - Assert.assertEquals(false, list.isEmpty()); + final List<URL> urls = FileSearcher.loadResources("pipe-factories.conf"); + Assert.assertEquals(false, urls.isEmpty()); } @Test public void multipleFiles() throws IOException { - final List<URL> list = FileSearcher.loadResources("LICENSE.txt"); - Assert.assertEquals(true, list.size() > 1); + final List<URL> urls = FileSearcher.loadResources("LICENSE.txt"); + Assert.assertEquals(true, urls.size() > 1); } @Test public void missingFile() throws IOException { - final List<URL> list = FileSearcher.loadResources("filethatdoesnotexistinanyproject.nope"); - Assert.assertEquals(true, list.isEmpty()); + final List<URL> urls = FileSearcher.loadResources("filethatdoesnotexistinanyproject.nope"); + Assert.assertEquals(true, urls.isEmpty()); } }