Skip to content

Commit

Permalink
making all constants capitalised
Browse files Browse the repository at this point in the history
  • Loading branch information
toby-weston-db committed Jan 14, 2014
1 parent 7d02d40 commit a735a9d
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
*/
public class DeadlockDetector {

private static final ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
private static final String lineSeparator = System.getProperty("line.separator");
private static final ThreadMXBean MBEAN = ManagementFactory.getThreadMXBean();
private static final String LINE_SEPARATOR = System.getProperty("line.separator");

/**
* Print deadlocks without deadlock stack traces.
Expand All @@ -60,7 +60,7 @@ private static void print(OutputStream writer, List<ThreadInfo> deadlocks) {
writeln(writer, "Deadlock detected");
writeln(writer, "=================");
for (ThreadInfo thread : deadlocks) {
writeln(writer, format("%s\"%s\":", lineSeparator, thread.getThreadName()));
writeln(writer, format("%s\"%s\":", LINE_SEPARATOR, thread.getThreadName()));
writeln(writer, format(" waiting to lock Monitor of %s ", thread.getLockName()));
writeln(writer, format(" which is held by \"%s\"", thread.getLockOwnerName()));
ThreadDump.printStackTrace(writer, thread.getStackTrace());
Expand All @@ -71,19 +71,19 @@ private static void print(OutputStream writer, List<ThreadInfo> deadlocks) {
}

private static void writeln(OutputStream writer, String string) throws IOException {
writer.write(format("%s%s", string, lineSeparator).getBytes());
writer.write(format("%s%s", string, LINE_SEPARATOR).getBytes());
}

private static List<ThreadInfo> findDeadlocks(int stackDepth) {
long[] result;
if (mbean.isSynchronizerUsageSupported())
result = mbean.findDeadlockedThreads();
if (MBEAN.isSynchronizerUsageSupported())
result = MBEAN.findDeadlockedThreads();
else
result = mbean.findMonitorDeadlockedThreads();
result = MBEAN.findMonitorDeadlockedThreads();
long[] monitorDeadlockedThreads = result;
if (monitorDeadlockedThreads == null)
return emptyList();
return asList(mbean.getThreadInfo(monitorDeadlockedThreads, stackDepth));
return asList(MBEAN.getThreadInfo(monitorDeadlockedThreads, stackDepth));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

public final class Interrupter {

private static final AtomicLong counter = new AtomicLong(0);
private static final AtomicLong COUNTER = new AtomicLong(0);

private final Thread threadToInterrupt;
private Thread interrupterThread;
Expand Down Expand Up @@ -60,7 +60,7 @@ public void run() {
currentThread().interrupt();
}
}
}, "Interrupter-Thread-" + counter.incrementAndGet());
}, "Interrupter-Thread-" + COUNTER.incrementAndGet());
interrupterThread.start();
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public class ThreadDump {

private static final String lineSeparator = System.getProperty("line.separator");
private static final String LINE_SEPARATOR = System.getProperty("line.separator");

public static void dumpThreads(OutputStream stream) {
DeadlockDetector.printDeadlocks(stream);
Expand All @@ -43,7 +43,7 @@ public Void call() throws IOException {
}

private void print(Thread thread, StackTraceElement[] stackTraceElements) throws IOException {
writeln(writer, format("%sThread %s@%d: (state = %s)", lineSeparator, thread.getName(), thread.getId(), thread.getState()));
writeln(writer, format("%sThread %s@%d: (state = %s)", LINE_SEPARATOR, thread.getName(), thread.getId(), thread.getState()));
printStackTrace (writer, stackTraceElements);
}
};
Expand All @@ -55,7 +55,7 @@ static void printStackTrace (final OutputStream writer, StackTraceElement[] stac
}

private static void writeln(OutputStream writer, String string) throws IOException {
writer.write(format("%s%s", string, lineSeparator).getBytes());
writer.write(format("%s%s", string, LINE_SEPARATOR).getBytes());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import com.google.code.tempusfugit.temporal.Condition;

@RunWith(ConcurrentTestRunner.class)
@Concurrent(count = concurrentCount)
@Concurrent(count = CONCURRENT_COUNT)
public abstract class AbstractConcurrentTestRunnerTest {

protected final static int concurrentCount = 3;
protected final static int CONCURRENT_COUNT = 3;

protected static final Set<String> threads = synchronizedSet(new HashSet<String>());
protected static final Set<String> THREADS = synchronizedSet(new HashSet<String>());

@Test
public void shouldRunInParallel1() throws TimeoutException, InterruptedException {
Expand Down Expand Up @@ -56,14 +56,14 @@ public void shouldRunInParallel5() throws TimeoutException, InterruptedException
}

private void logCurrentThread() throws TimeoutException, InterruptedException {
threads.add(Thread.currentThread().getName());
THREADS.add(Thread.currentThread().getName());
waitToForceCachedThreadPoolToCreateNewThread();
}

private void waitToForceCachedThreadPoolToCreateNewThread() throws InterruptedException, TimeoutException {
waitOrTimeout(new Condition() {
public boolean isSatisfied() {
return threads.size() == getConcurrentCount();
return THREADS.size() == getConcurrentCount();
}
}, timeout(seconds(1)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class CallableAdapterTest {

private final Mockery context = new Mockery();
private final Callable callable = context.mock(Callable.class);

private static final Object RESULT = new Object();

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@
@Ignore("Bug #10 (https://code.google.com/p/tempus-fugit/issues/detail?id=10)")
public class ConcurrentTestRunnerAfterClassTest {

private static Thread testThread;
private static Thread TEST_THREAD;

@Test
public void runsMultipleTimes() {
testThread = Thread.currentThread();
TEST_THREAD = Thread.currentThread();
}

@After
public void assertAfterIsEvaluatedOnTestThread() {
assertThat(Thread.currentThread(), is(testThread));
assertThat(Thread.currentThread(), is(TEST_THREAD));
}

@AfterClass
public static void assertAfterClassIsEvaluatedOnTestThread() {
assertThat(Thread.currentThread(), is(testThread));
assertThat(Thread.currentThread(), is(TEST_THREAD));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public class ConcurrentTestRunnerTest extends AbstractConcurrentTestRunnerTest {

@AfterClass
public static void assertTestThreadsSpawned() {
assertThat(threads.size(), is(concurrentCount));
assertThat(THREADS.size(), is(CONCURRENT_COUNT));
}

@Override
protected int getConcurrentCount() {
return concurrentCount;
return CONCURRENT_COUNT;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*/
public class DeadlockDetectorTest {

public static final int withEntireStackTrace = Integer.MAX_VALUE;
private static final int withEntireStackTrace = Integer.MAX_VALUE;

private final CountDownLatch latch = new CountDownLatch(2);
private final Deadlocks deadlocks = new Deadlocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@

import com.google.code.tempusfugit.concurrency.annotations.Concurrent;

@Concurrent(count = overiddenConcurrentCount)
@Concurrent(count = OVERRIDDEN_CONCURRENT_COUNT)
public class OverrideConcurrentTestRunnerTest extends AbstractConcurrentTestRunnerTest {

protected final static int overiddenConcurrentCount = 4;
protected final static int OVERRIDDEN_CONCURRENT_COUNT = 4;

@AfterClass
public static void assertTestThreadsSpawned() {
assertThat(threads.size(), is(overiddenConcurrentCount));
assertThat(THREADS.size(), is(OVERRIDDEN_CONCURRENT_COUNT));
}

@Override
protected int getConcurrentCount() {
return overiddenConcurrentCount;
return OVERRIDDEN_CONCURRENT_COUNT;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,30 @@ public class RunConcurrentlyTest {

@Rule public ConcurrentRule rule = new ConcurrentRule();

private static final AtomicInteger counter = new AtomicInteger();
private static final AtomicInteger COUNTER = new AtomicInteger();

private static final Set<String> threads = synchronizedSet(new HashSet<String>());
private static final Set<String> THREADS = synchronizedSet(new HashSet<String>());

@Test
@Concurrent (count = 5)
public void runsMultipleTimes() {
counter.getAndIncrement();
COUNTER.getAndIncrement();
}

@AfterClass
public static void assertTestMethodRanMultipleTimes() {
assertThat(counter.get(), is(5));
assertThat(COUNTER.get(), is(5));
}

@Test
@Concurrent (count = 5)
public void spawnTestThreads() {
threads.add(Thread.currentThread().getName());
THREADS.add(Thread.currentThread().getName());
}

@AfterClass
public static void assertTestThreadsSpawned() {
assertThat(threads.size(), is(5));
assertThat(THREADS.size(), is(5));
}

@Test (expected = AssertionFailedError.class)
Expand Down

0 comments on commit a735a9d

Please sign in to comment.