diff options
Diffstat (limited to 'vespajlib/src/test/java/com/yahoo/concurrent/ThreadFactoryFactoryTest.java')
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/concurrent/ThreadFactoryFactoryTest.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/concurrent/ThreadFactoryFactoryTest.java b/vespajlib/src/test/java/com/yahoo/concurrent/ThreadFactoryFactoryTest.java new file mode 100644 index 00000000000..7fc6a9cc390 --- /dev/null +++ b/vespajlib/src/test/java/com/yahoo/concurrent/ThreadFactoryFactoryTest.java @@ -0,0 +1,44 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.concurrent; + +import org.junit.Test; + + +import java.util.concurrent.ThreadFactory; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +/** + * Created with IntelliJ IDEA. + * User: balder + * Date: 26.04.13 + * Time: 12:01 + * To change this template use File | Settings | File Templates. + */ +public class ThreadFactoryFactoryTest { + + static class Runner implements Runnable { + @Override + public void run() { + + } + } + + @Test + public void requireThatFactoryCreatesCorrectlyNamedThreads() { + Thread thread = ThreadFactoryFactory.getThreadFactory("a").newThread(new Runner()); + assertEquals("a-1-thread-1", thread.getName()); + thread = ThreadFactoryFactory.getThreadFactory("a").newThread(new Runner()); + assertEquals("a-2-thread-1", thread.getName()); + thread = ThreadFactoryFactory.getThreadFactory("b").newThread(new Runner()); + assertEquals("b-1-thread-1", thread.getName()); + ThreadFactory factory = ThreadFactoryFactory.getThreadFactory("a"); + thread = factory.newThread(new Runner()); + assertEquals("a-3-thread-1", thread.getName()); + thread = factory.newThread(new Runner()); + assertEquals("a-3-thread-2", thread.getName()); + thread = factory.newThread(new Runner()); + assertEquals("a-3-thread-3", thread.getName()); + } + +} |