mirror of https://github.com/apache/activemq.git
Clean up, convert all to JUnit 4 style tests, replace system.out calls with loggers.
This commit is contained in:
parent
39a1e04554
commit
18300c6514
|
@ -16,6 +16,10 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.thread;
|
package org.apache.activemq.thread;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
@ -28,28 +32,34 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TestName;
|
||||||
|
|
||||||
|
public class PooledTaskRunnerTest {
|
||||||
|
|
||||||
|
@Rule public TestName name = new TestName();
|
||||||
|
|
||||||
public class PooledTaskRunnerTest extends TestCase {
|
|
||||||
private ExecutorService executor;
|
private ExecutorService executor;
|
||||||
|
|
||||||
@Override
|
@Before
|
||||||
protected void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
|
||||||
executor = Executors.newCachedThreadPool(new IgnoreUncaughtExceptionThreadFactory());
|
executor = Executors.newCachedThreadPool(new IgnoreUncaughtExceptionThreadFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@After
|
||||||
protected void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
executor.shutdownNow();
|
executor.shutdownNow();
|
||||||
|
|
||||||
super.tearDown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNormalBehavior() throws Exception {
|
public void testNormalBehavior() throws Exception {
|
||||||
final CountDownLatch latch = new CountDownLatch( 1 );
|
final CountDownLatch latch = new CountDownLatch( 1 );
|
||||||
|
|
||||||
PooledTaskRunner runner = new PooledTaskRunner( executor, new Task() {
|
PooledTaskRunner runner = new PooledTaskRunner( executor, new Task() {
|
||||||
|
@Override
|
||||||
public boolean iterate() {
|
public boolean iterate() {
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
|
|
||||||
|
@ -64,12 +74,13 @@ public class PooledTaskRunnerTest extends TestCase {
|
||||||
runner.shutdown();
|
runner.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testWakeupResultsInThreadSafeCalls() throws Exception {
|
public void testWakeupResultsInThreadSafeCalls() throws Exception {
|
||||||
|
|
||||||
ThreadPoolExecutor executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 10, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactory() {
|
ThreadPoolExecutor executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 10, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactory() {
|
||||||
|
@Override
|
||||||
public Thread newThread(Runnable runnable) {
|
public Thread newThread(Runnable runnable) {
|
||||||
Thread thread = new Thread(runnable, getName());
|
Thread thread = new Thread(runnable, name.getMethodName());
|
||||||
thread.setDaemon(true);
|
thread.setDaemon(true);
|
||||||
thread.setPriority(Thread.NORM_PRIORITY);
|
thread.setPriority(Thread.NORM_PRIORITY);
|
||||||
return thread;
|
return thread;
|
||||||
|
@ -82,6 +93,7 @@ public class PooledTaskRunnerTest extends TestCase {
|
||||||
|
|
||||||
final PooledTaskRunner runner = new PooledTaskRunner(executor, new Task() {
|
final PooledTaskRunner runner = new PooledTaskRunner(executor, new Task() {
|
||||||
String threadUnSafeVal = null;
|
String threadUnSafeVal = null;
|
||||||
|
@Override
|
||||||
public boolean iterate() {
|
public boolean iterate() {
|
||||||
if (threadUnSafeVal != null) {
|
if (threadUnSafeVal != null) {
|
||||||
clashCount.incrementAndGet();
|
clashCount.incrementAndGet();
|
||||||
|
@ -98,6 +110,7 @@ public class PooledTaskRunnerTest extends TestCase {
|
||||||
}, 1 );
|
}, 1 );
|
||||||
|
|
||||||
Runnable doWakeup = new Runnable() {
|
Runnable doWakeup = new Runnable() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
runner.wakeup();
|
runner.wakeup();
|
||||||
|
@ -105,27 +118,30 @@ public class PooledTaskRunnerTest extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
final int iterations = 1000;
|
final int iterations = 1000;
|
||||||
for (int i=0; i< iterations; i++) {
|
for (int i=0; i< iterations; i++) {
|
||||||
if (i%100 == 0) {
|
if (i%100 == 0) {
|
||||||
Thread.sleep(10);
|
Thread.sleep(10);
|
||||||
}
|
}
|
||||||
executor.execute(doWakeup);
|
executor.execute(doWakeup);
|
||||||
}
|
}
|
||||||
|
|
||||||
doneLatch.await(20, TimeUnit.SECONDS);
|
doneLatch.await(20, TimeUnit.SECONDS);
|
||||||
assertEquals("thread safety clash", 0, clashCount.get());
|
assertEquals("thread safety clash", 0, clashCount.get());
|
||||||
assertTrue("called more than once", count.get() > 1);
|
assertTrue("called more than once", count.get() > 1);
|
||||||
runner.shutdown();
|
runner.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testShutsDownAfterRunnerFailure() throws Exception {
|
public void testShutsDownAfterRunnerFailure() throws Exception {
|
||||||
Future<Object> future = executor.submit( new Callable<Object>() {
|
Future<Object> future = executor.submit( new Callable<Object>() {
|
||||||
|
@Override
|
||||||
public Object call() throws Exception {
|
public Object call() throws Exception {
|
||||||
final CountDownLatch latch = new CountDownLatch( 1 );
|
final CountDownLatch latch = new CountDownLatch( 1 );
|
||||||
|
|
||||||
PooledTaskRunner runner = new PooledTaskRunner( executor, new Task() {
|
PooledTaskRunner runner = new PooledTaskRunner( executor, new Task() {
|
||||||
|
@Override
|
||||||
public boolean iterate() {
|
public boolean iterate() {
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
|
|
||||||
|
@ -149,15 +165,19 @@ public class PooledTaskRunnerTest extends TestCase {
|
||||||
fail( "TaskRunner did not shut down cleanly" );
|
fail( "TaskRunner did not shut down cleanly" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IgnoreUncaughtExceptionThreadFactory implements ThreadFactory, Thread.UncaughtExceptionHandler {
|
private class IgnoreUncaughtExceptionThreadFactory implements ThreadFactory, Thread.UncaughtExceptionHandler {
|
||||||
|
|
||||||
ThreadFactory threadFactory = Executors.defaultThreadFactory();
|
ThreadFactory threadFactory = Executors.defaultThreadFactory();
|
||||||
|
|
||||||
|
@Override
|
||||||
public Thread newThread(Runnable r) {
|
public Thread newThread(Runnable r) {
|
||||||
Thread thread = threadFactory.newThread(r);
|
Thread thread = threadFactory.newThread(r);
|
||||||
thread.setUncaughtExceptionHandler(this);
|
thread.setUncaughtExceptionHandler(this);
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void uncaughtException(Thread t, Throwable e) {
|
public void uncaughtException(Thread t, Throwable e) {
|
||||||
// ignore ie: no printStackTrace that would sully the test console
|
// ignore ie: no printStackTrace that would sully the test console
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,24 +16,29 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.thread;
|
package org.apache.activemq.thread;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.concurrent.BrokenBarrierException;
|
import java.util.concurrent.BrokenBarrierException;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.CyclicBarrier;
|
import java.util.concurrent.CyclicBarrier;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class TaskRunnerTest extends TestCase {
|
public class TaskRunnerTest {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(TaskRunnerTest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(TaskRunnerTest.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testWakeupPooled() throws InterruptedException, BrokenBarrierException {
|
public void testWakeupPooled() throws InterruptedException, BrokenBarrierException {
|
||||||
System.setProperty("org.apache.activemq.UseDedicatedTaskRunner", "false");
|
System.setProperty("org.apache.activemq.UseDedicatedTaskRunner", "false");
|
||||||
doTestWakeup();
|
doTestWakeup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testWakeupDedicated() throws InterruptedException, BrokenBarrierException {
|
public void testWakeupDedicated() throws InterruptedException, BrokenBarrierException {
|
||||||
System.setProperty("org.apache.activemq.UseDedicatedTaskRunner", "true");
|
System.setProperty("org.apache.activemq.UseDedicatedTaskRunner", "true");
|
||||||
doTestWakeup();
|
doTestWakeup();
|
||||||
|
@ -42,7 +47,7 @@ public class TaskRunnerTest extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Simulate multiple threads queuing work for the TaskRunner. The Task
|
* Simulate multiple threads queuing work for the TaskRunner. The Task
|
||||||
* Runner dequeues the work.
|
* Runner dequeues the work.
|
||||||
*
|
*
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
* @throws BrokenBarrierException
|
* @throws BrokenBarrierException
|
||||||
*/
|
*/
|
||||||
|
@ -56,6 +61,7 @@ public class TaskRunnerTest extends TestCase {
|
||||||
|
|
||||||
TaskRunnerFactory factory = new TaskRunnerFactory();
|
TaskRunnerFactory factory = new TaskRunnerFactory();
|
||||||
final TaskRunner runner = factory.createTaskRunner(new Task() {
|
final TaskRunner runner = factory.createTaskRunner(new Task() {
|
||||||
|
@Override
|
||||||
public boolean iterate() {
|
public boolean iterate() {
|
||||||
if (queue.get() == 0) {
|
if (queue.get() == 0) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -78,6 +84,7 @@ public class TaskRunnerTest extends TestCase {
|
||||||
final CyclicBarrier barrier = new CyclicBarrier(workerCount + 1);
|
final CyclicBarrier barrier = new CyclicBarrier(workerCount + 1);
|
||||||
for (int i = 0; i < workerCount; i++) {
|
for (int i = 0; i < workerCount; i++) {
|
||||||
new Thread() {
|
new Thread() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
barrier.await();
|
barrier.await();
|
||||||
|
@ -104,9 +111,4 @@ public class TaskRunnerTest extends TestCase {
|
||||||
|
|
||||||
runner.shutdown();
|
runner.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
junit.textui.TestRunner.run(TaskRunnerTest.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,13 +30,17 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class MemoryUsageConcurrencyTest {
|
public class MemoryUsageConcurrencyTest {
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(MemoryUsageConcurrencyTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCycle() throws Exception {
|
public void testCycle() throws Exception {
|
||||||
Random r = new Random(0xb4a14);
|
Random r = new Random(0xb4a14);
|
||||||
for (int i = 0; i < 50000; i++) {
|
for (int i = 0; i < 30000; i++) {
|
||||||
checkPercentage(i, i, r.nextInt(100) + 10, i % 2 == 0, i % 5 == 0);
|
checkPercentage(i, i, r.nextInt(100) + 10, i % 2 == 0, i % 5 == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,7 +158,7 @@ public class MemoryUsageConcurrencyTest {
|
||||||
try {
|
try {
|
||||||
waitForSpaceThread.join(1000);
|
waitForSpaceThread.join(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
System.out.println("Attempt: " + attempt + " : " + memUsage + " waitForSpace never returned");
|
LOG.debug("Attempt: {} : {} waitForSpace never returned", attempt, memUsage);
|
||||||
waitForSpaceThread.interrupt();
|
waitForSpaceThread.interrupt();
|
||||||
waitForSpaceThread.join();
|
waitForSpaceThread.join();
|
||||||
}
|
}
|
||||||
|
@ -164,8 +168,8 @@ public class MemoryUsageConcurrencyTest {
|
||||||
addThread.join();
|
addThread.join();
|
||||||
|
|
||||||
if (memUsage.getPercentUsage() != 0 || memUsage.getUsage() != memUsage.getPercentUsage()) {
|
if (memUsage.getPercentUsage() != 0 || memUsage.getUsage() != memUsage.getPercentUsage()) {
|
||||||
System.out.println("Attempt: " + attempt + " : " + memUsage);
|
LOG.debug("Attempt: {} : {}", attempt, memUsage);
|
||||||
System.out.println("Operations: " + ops);
|
LOG.debug("Operations: {}", ops);
|
||||||
assertEquals(0, memUsage.getPercentUsage());
|
assertEquals(0, memUsage.getPercentUsage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,18 +16,21 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.util;
|
package org.apache.activemq.util;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class DataByteArrayInputStreamTest extends TestCase {
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class DataByteArrayInputStreamTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://issues.apache.org/activemq/browse/AMQ-1911
|
* https://issues.apache.org/activemq/browse/AMQ-1911
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testNonAscii() throws Exception {
|
public void testNonAscii() throws Exception {
|
||||||
doMarshallUnMarshallValidation("mei\u00DFen");
|
doMarshallUnMarshallValidation("mei\u00DFen");
|
||||||
|
|
||||||
String accumulator = new String();
|
String accumulator = new String();
|
||||||
|
|
||||||
int test = 0; // int to get Supplementary chars
|
int test = 0; // int to get Supplementary chars
|
||||||
while(Character.isDefined(test)) {
|
while(Character.isDefined(test)) {
|
||||||
String toTest = String.valueOf((char)test);
|
String toTest = String.valueOf((char)test);
|
||||||
|
@ -35,15 +38,15 @@ public class DataByteArrayInputStreamTest extends TestCase {
|
||||||
doMarshallUnMarshallValidation(toTest);
|
doMarshallUnMarshallValidation(toTest);
|
||||||
test++;
|
test++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int massiveThreeByteCharValue = 0x0FFF;
|
int massiveThreeByteCharValue = 0x0FFF;
|
||||||
String toTest = String.valueOf((char)massiveThreeByteCharValue);
|
String toTest = String.valueOf((char)massiveThreeByteCharValue);
|
||||||
accumulator += toTest;
|
accumulator += toTest;
|
||||||
doMarshallUnMarshallValidation(String.valueOf((char)massiveThreeByteCharValue));
|
doMarshallUnMarshallValidation(String.valueOf((char)massiveThreeByteCharValue));
|
||||||
|
|
||||||
// Altogether
|
// Altogether
|
||||||
doMarshallUnMarshallValidation(accumulator);
|
doMarshallUnMarshallValidation(accumulator);
|
||||||
|
|
||||||
// the three byte values
|
// the three byte values
|
||||||
char t = '\u0800';
|
char t = '\u0800';
|
||||||
final char max = '\uffff';
|
final char max = '\uffff';
|
||||||
|
@ -54,20 +57,20 @@ public class DataByteArrayInputStreamTest extends TestCase {
|
||||||
doMarshallUnMarshallValidation(val);
|
doMarshallUnMarshallValidation(val);
|
||||||
t++;
|
t++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Altogether so long as it is not too big
|
// Altogether so long as it is not too big
|
||||||
while (accumulator.length() > 20000) {
|
while (accumulator.length() > 20000) {
|
||||||
accumulator = accumulator.substring(20000);
|
accumulator = accumulator.substring(20000);
|
||||||
}
|
}
|
||||||
doMarshallUnMarshallValidation(accumulator);
|
doMarshallUnMarshallValidation(accumulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void doMarshallUnMarshallValidation(String value) throws Exception {
|
void doMarshallUnMarshallValidation(String value) throws Exception {
|
||||||
DataByteArrayOutputStream out = new DataByteArrayOutputStream();
|
DataByteArrayOutputStream out = new DataByteArrayOutputStream();
|
||||||
out.writeBoolean(true);
|
out.writeBoolean(true);
|
||||||
out.writeUTF(value);
|
out.writeUTF(value);
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
DataByteArrayInputStream in = new DataByteArrayInputStream(out.getData());
|
DataByteArrayInputStream in = new DataByteArrayInputStream(out.getData());
|
||||||
in.readBoolean();
|
in.readBoolean();
|
||||||
String readBack = in.readUTF();
|
String readBack = in.readUTF();
|
||||||
|
|
|
@ -18,14 +18,15 @@ package org.apache.activemq.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class DataByteArrayOutputStreamTest extends TestCase {
|
public class DataByteArrayOutputStreamTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test case assumes that an ArrayIndexOutOfBoundsException will be thrown when the buffer fails to resize
|
* This test case assumes that an ArrayIndexOutOfBoundsException will be thrown when the buffer fails to resize
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testResize() throws IOException {
|
public void testResize() throws IOException {
|
||||||
int initSize = 64;
|
int initSize = 64;
|
||||||
DataByteArrayOutputStream out = new DataByteArrayOutputStream();
|
DataByteArrayOutputStream out = new DataByteArrayOutputStream();
|
||||||
|
|
|
@ -16,10 +16,13 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.util;
|
package org.apache.activemq.util;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class IdGeneratorTest extends TestCase {
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class IdGeneratorTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSanitizeHostName() throws Exception {
|
public void testSanitizeHostName() throws Exception {
|
||||||
assertEquals("somehost.lan", IdGenerator.sanitizeHostName("somehost.lan"));
|
assertEquals("somehost.lan", IdGenerator.sanitizeHostName("somehost.lan"));
|
||||||
// include a UTF-8 char in the text \u0E08 is a Thai elephant
|
// include a UTF-8 char in the text \u0E08 is a Thai elephant
|
||||||
|
|
|
@ -16,14 +16,14 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.util;
|
package org.apache.activemq.util;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
import org.junit.Test;
|
||||||
* @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
|
|
||||||
*/
|
public class IntrospectionSupportTest {
|
||||||
public class IntrospectionSupportTest extends TestCase {
|
|
||||||
|
private class DummyClass {
|
||||||
|
|
||||||
class DummyClass {
|
|
||||||
private boolean trace;
|
private boolean trace;
|
||||||
|
|
||||||
DummyClass(boolean trace) {
|
DummyClass(boolean trace) {
|
||||||
|
@ -39,11 +39,13 @@ public class IntrospectionSupportTest extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSetPropertyPrimitiveWithWrapperValue() {
|
public void testSetPropertyPrimitiveWithWrapperValue() {
|
||||||
// Wrapper value
|
// Wrapper value
|
||||||
Boolean value = Boolean.valueOf(true);
|
Boolean value = Boolean.valueOf(true);
|
||||||
|
|
||||||
DummyClass dummyClass = new DummyClass(false);
|
DummyClass dummyClass = new DummyClass(false);
|
||||||
|
dummyClass.setTrace(false);
|
||||||
|
|
||||||
// dummy field expects a primitive
|
// dummy field expects a primitive
|
||||||
IntrospectionSupport.setProperty(dummyClass, "trace", value);
|
IntrospectionSupport.setProperty(dummyClass, "trace", value);
|
||||||
|
|
|
@ -16,37 +16,21 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.util;
|
package org.apache.activemq.util;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
public class MarshallingSupportTest {
|
||||||
* @author rajdavies
|
|
||||||
*/
|
|
||||||
public class MarshallingSupportTest extends TestCase {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
* @see junit.framework.TestCase#setUp()
|
|
||||||
*/
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
* @see junit.framework.TestCase#tearDown()
|
|
||||||
*/
|
|
||||||
protected void tearDown() throws Exception {
|
|
||||||
super.tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for
|
* Test method for
|
||||||
* {@link org.apache.activemq.util.MarshallingSupport#propertiesToString(java.util.Properties)}.
|
* {@link org.apache.activemq.util.MarshallingSupport#propertiesToString(java.util.Properties)}.
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testPropertiesToString() throws Exception {
|
public void testPropertiesToString() throws Exception {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
|
|
|
@ -16,13 +16,15 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.util;
|
package org.apache.activemq.util;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotSame;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
import org.junit.Test;
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class StopWatchTest extends TestCase {
|
|
||||||
|
|
||||||
|
public class StopWatchTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testStopWatch() throws Exception {
|
public void testStopWatch() throws Exception {
|
||||||
StopWatch watch = new StopWatch();
|
StopWatch watch = new StopWatch();
|
||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
|
@ -32,6 +34,7 @@ public class StopWatchTest extends TestCase {
|
||||||
assertTrue("Should take approx 200 millis, was: " + taken, taken > 150);
|
assertTrue("Should take approx 200 millis, was: " + taken, taken > 150);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testStopWatchNotStarted() throws Exception {
|
public void testStopWatchNotStarted() throws Exception {
|
||||||
StopWatch watch = new StopWatch(false);
|
StopWatch watch = new StopWatch(false);
|
||||||
long taken = watch.stop();
|
long taken = watch.stop();
|
||||||
|
@ -45,6 +48,7 @@ public class StopWatchTest extends TestCase {
|
||||||
assertTrue("Should take approx 200 millis, was: " + taken, taken > 150);
|
assertTrue("Should take approx 200 millis, was: " + taken, taken > 150);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testStopWatchRestart() throws Exception {
|
public void testStopWatchRestart() throws Exception {
|
||||||
StopWatch watch = new StopWatch();
|
StopWatch watch = new StopWatch();
|
||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
|
@ -61,6 +65,7 @@ public class StopWatchTest extends TestCase {
|
||||||
assertTrue("Should take approx 100 millis, was: " + taken, taken > 50);
|
assertTrue("Should take approx 100 millis, was: " + taken, taken > 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testStopWatchTaken() throws Exception {
|
public void testStopWatchTaken() throws Exception {
|
||||||
StopWatch watch = new StopWatch();
|
StopWatch watch = new StopWatch();
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
|
|
|
@ -16,16 +16,17 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.util;
|
package org.apache.activemq.util;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
/**
|
import org.junit.Test;
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class StringArrayConverterTest extends TestCase {
|
|
||||||
|
|
||||||
|
public class StringArrayConverterTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testConvertToStringArray() throws Exception {
|
public void testConvertToStringArray() throws Exception {
|
||||||
assertEquals(null, StringArrayConverter.convertToStringArray(null));
|
assertNull(StringArrayConverter.convertToStringArray(null));
|
||||||
assertEquals(null, StringArrayConverter.convertToStringArray(""));
|
assertNull(StringArrayConverter.convertToStringArray(""));
|
||||||
|
|
||||||
String[] array = StringArrayConverter.convertToStringArray("foo");
|
String[] array = StringArrayConverter.convertToStringArray("foo");
|
||||||
assertEquals(1, array.length);
|
assertEquals(1, array.length);
|
||||||
|
@ -43,6 +44,7 @@ public class StringArrayConverterTest extends TestCase {
|
||||||
assertEquals("baz", array[2]);
|
assertEquals("baz", array[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testConvertToString() throws Exception {
|
public void testConvertToString() throws Exception {
|
||||||
assertEquals(null, StringArrayConverter.convertToString(null));
|
assertEquals(null, StringArrayConverter.convertToString(null));
|
||||||
assertEquals(null, StringArrayConverter.convertToString(new String[]{}));
|
assertEquals(null, StringArrayConverter.convertToString(new String[]{}));
|
||||||
|
@ -51,5 +53,4 @@ public class StringArrayConverterTest extends TestCase {
|
||||||
assertEquals("foo,bar", StringArrayConverter.convertToString(new String[]{"foo", "bar"}));
|
assertEquals("foo,bar", StringArrayConverter.convertToString(new String[]{"foo", "bar"}));
|
||||||
assertEquals("foo,bar,baz", StringArrayConverter.convertToString(new String[]{"foo", "bar", "baz"}));
|
assertEquals("foo,bar,baz", StringArrayConverter.convertToString(new String[]{"foo", "bar", "baz"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,20 +23,10 @@ import static org.junit.Assert.assertNull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.activemq.command.ActiveMQDestination;
|
import org.apache.activemq.command.ActiveMQDestination;
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class StringToListOfActiveMQDestinationConverterTest {
|
public class StringToListOfActiveMQDestinationConverterTest {
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConvertToActiveMQDestination() {
|
public void testConvertToActiveMQDestination() {
|
||||||
|
|
||||||
|
@ -62,5 +52,4 @@ public class StringToListOfActiveMQDestinationConverterTest {
|
||||||
String result = StringToListOfActiveMQDestinationConverter.convertFromActiveMQDestination(null);
|
String result = StringToListOfActiveMQDestinationConverter.convertFromActiveMQDestination(null);
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,22 +16,28 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.util;
|
package org.apache.activemq.util;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.activemq.util.URISupport.CompositeData;
|
import org.apache.activemq.util.URISupport.CompositeData;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class URISupportTest extends TestCase {
|
public class URISupportTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEmptyCompositePath() throws Exception {
|
public void testEmptyCompositePath() throws Exception {
|
||||||
CompositeData data = URISupport.parseComposite(new URI("broker:()/localhost?persistent=false"));
|
CompositeData data = URISupport.parseComposite(new URI("broker:()/localhost?persistent=false"));
|
||||||
assertEquals(0, data.getComponents().length);
|
assertEquals(0, data.getComponents().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCompositePath() throws Exception {
|
public void testCompositePath() throws Exception {
|
||||||
CompositeData data = URISupport.parseComposite(new URI("test:(path)/path"));
|
CompositeData data = URISupport.parseComposite(new URI("test:(path)/path"));
|
||||||
assertEquals("path", data.getPath());
|
assertEquals("path", data.getPath());
|
||||||
|
@ -39,17 +45,20 @@ public class URISupportTest extends TestCase {
|
||||||
assertNull(data.getPath());
|
assertNull(data.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSimpleComposite() throws Exception {
|
public void testSimpleComposite() throws Exception {
|
||||||
CompositeData data = URISupport.parseComposite(new URI("test:part1"));
|
CompositeData data = URISupport.parseComposite(new URI("test:part1"));
|
||||||
assertEquals(1, data.getComponents().length);
|
assertEquals(1, data.getComponents().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testComposite() throws Exception {
|
public void testComposite() throws Exception {
|
||||||
URI uri = new URI("test:(part1://host,part2://(sub1://part,sube2:part))");
|
URI uri = new URI("test:(part1://host,part2://(sub1://part,sube2:part))");
|
||||||
CompositeData data = URISupport.parseComposite(uri);
|
CompositeData data = URISupport.parseComposite(uri);
|
||||||
assertEquals(2, data.getComponents().length);
|
assertEquals(2, data.getComponents().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEmptyCompositeWithParenthesisInParam() throws Exception {
|
public void testEmptyCompositeWithParenthesisInParam() throws Exception {
|
||||||
URI uri = new URI("failover://()?updateURIsURL=file:/C:/Dir(1)/a.csv");
|
URI uri = new URI("failover://()?updateURIsURL=file:/C:/Dir(1)/a.csv");
|
||||||
CompositeData data = URISupport.parseComposite(uri);
|
CompositeData data = URISupport.parseComposite(uri);
|
||||||
|
@ -59,6 +68,7 @@ public class URISupportTest extends TestCase {
|
||||||
assertEquals("file:/C:/Dir(1)/a.csv", data.getParameters().get("updateURIsURL"));
|
assertEquals("file:/C:/Dir(1)/a.csv", data.getParameters().get("updateURIsURL"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCompositeWithParenthesisInParam() throws Exception {
|
public void testCompositeWithParenthesisInParam() throws Exception {
|
||||||
URI uri = new URI("failover://(test)?updateURIsURL=file:/C:/Dir(1)/a.csv");
|
URI uri = new URI("failover://(test)?updateURIsURL=file:/C:/Dir(1)/a.csv");
|
||||||
CompositeData data = URISupport.parseComposite(uri);
|
CompositeData data = URISupport.parseComposite(uri);
|
||||||
|
@ -68,6 +78,7 @@ public class URISupportTest extends TestCase {
|
||||||
assertEquals("file:/C:/Dir(1)/a.csv", data.getParameters().get("updateURIsURL"));
|
assertEquals("file:/C:/Dir(1)/a.csv", data.getParameters().get("updateURIsURL"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCompositeWithComponentParam() throws Exception {
|
public void testCompositeWithComponentParam() throws Exception {
|
||||||
CompositeData data = URISupport.parseComposite(new URI("test:(part1://host?part1=true)?outside=true"));
|
CompositeData data = URISupport.parseComposite(new URI("test:(part1://host?part1=true)?outside=true"));
|
||||||
assertEquals(1, data.getComponents().length);
|
assertEquals(1, data.getComponents().length);
|
||||||
|
@ -77,6 +88,7 @@ public class URISupportTest extends TestCase {
|
||||||
assertTrue(part1Params.containsKey("part1"));
|
assertTrue(part1Params.containsKey("part1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testParsingURI() throws Exception {
|
public void testParsingURI() throws Exception {
|
||||||
URI source = new URI("tcp://localhost:61626/foo/bar?cheese=Edam&x=123");
|
URI source = new URI("tcp://localhost:61626/foo/bar?cheese=Edam&x=123");
|
||||||
|
|
||||||
|
@ -95,12 +107,14 @@ public class URISupportTest extends TestCase {
|
||||||
assertEquals("Map key: " + key, map.get(key), expected);
|
assertEquals("Map key: " + key, map.get(key), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testParsingCompositeURI() throws URISyntaxException {
|
public void testParsingCompositeURI() throws URISyntaxException {
|
||||||
CompositeData data = URISupport.parseComposite(new URI("broker://(tcp://localhost:61616)?name=foo"));
|
CompositeData data = URISupport.parseComposite(new URI("broker://(tcp://localhost:61616)?name=foo"));
|
||||||
assertEquals("one component", 1, data.getComponents().length);
|
assertEquals("one component", 1, data.getComponents().length);
|
||||||
assertEquals("Size: " + data.getParameters(), 1, data.getParameters().size());
|
assertEquals("Size: " + data.getParameters(), 1, data.getParameters().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCheckParenthesis() throws Exception {
|
public void testCheckParenthesis() throws Exception {
|
||||||
String str = "fred:(((ddd))";
|
String str = "fred:(((ddd))";
|
||||||
assertFalse(URISupport.checkParenthesis(str));
|
assertFalse(URISupport.checkParenthesis(str));
|
||||||
|
@ -108,6 +122,7 @@ public class URISupportTest extends TestCase {
|
||||||
assertTrue(URISupport.checkParenthesis(str));
|
assertTrue(URISupport.checkParenthesis(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCreateWithQuery() throws Exception {
|
public void testCreateWithQuery() throws Exception {
|
||||||
URI source = new URI("vm://localhost");
|
URI source = new URI("vm://localhost");
|
||||||
URI dest = URISupport.createURIWithQuery(source, "network=true&one=two");
|
URI dest = URISupport.createURIWithQuery(source, "network=true&one=two");
|
||||||
|
@ -118,6 +133,7 @@ public class URISupportTest extends TestCase {
|
||||||
assertFalse("same uri, ssp", dest.getQuery().equals(source.getQuery()));
|
assertFalse("same uri, ssp", dest.getQuery().equals(source.getQuery()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testParsingParams() throws Exception {
|
public void testParsingParams() throws Exception {
|
||||||
URI uri = new URI("static:(http://localhost:61617?proxyHost=jo&proxyPort=90)?proxyHost=localhost&proxyPort=80");
|
URI uri = new URI("static:(http://localhost:61617?proxyHost=jo&proxyPort=90)?proxyHost=localhost&proxyPort=80");
|
||||||
Map<String,String>parameters = URISupport.parseParameters(uri);
|
Map<String,String>parameters = URISupport.parseParameters(uri);
|
||||||
|
@ -129,6 +145,7 @@ public class URISupportTest extends TestCase {
|
||||||
parameters = URISupport.parseParameters(uri);
|
parameters = URISupport.parseParameters(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCompositeCreateURIWithQuery() throws Exception {
|
public void testCompositeCreateURIWithQuery() throws Exception {
|
||||||
String queryString = "query=value";
|
String queryString = "query=value";
|
||||||
URI originalURI = new URI("outerscheme:(innerscheme:innerssp)");
|
URI originalURI = new URI("outerscheme:(innerscheme:innerssp)");
|
||||||
|
@ -151,6 +168,7 @@ public class URISupportTest extends TestCase {
|
||||||
assertEquals(new URI(querylessURI + "?" + queryString), URISupport.createURIWithQuery(originalURI, queryString));
|
assertEquals(new URI(querylessURI + "?" + queryString), URISupport.createURIWithQuery(originalURI, queryString));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testApplyParameters() throws Exception {
|
public void testApplyParameters() throws Exception {
|
||||||
|
|
||||||
URI uri = new URI("http://0.0.0.0:61616");
|
URI uri = new URI("http://0.0.0.0:61616");
|
||||||
|
@ -178,6 +196,7 @@ public class URISupportTest extends TestCase {
|
||||||
assertEquals(parameters.get("proxyPort"), "80");
|
assertEquals(parameters.get("proxyPort"), "80");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testIsCompositeURIWithQueryNoSlashes() throws URISyntaxException {
|
public void testIsCompositeURIWithQueryNoSlashes() throws URISyntaxException {
|
||||||
URI[] compositeURIs = new URI[] { new URI("test:(part1://host?part1=true)?outside=true"), new URI("broker:(tcp://localhost:61616)?name=foo") };
|
URI[] compositeURIs = new URI[] { new URI("test:(part1://host?part1=true)?outside=true"), new URI("broker:(tcp://localhost:61616)?name=foo") };
|
||||||
for (URI uri : compositeURIs) {
|
for (URI uri : compositeURIs) {
|
||||||
|
@ -185,6 +204,7 @@ public class URISupportTest extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testIsCompositeURIWithQueryAndSlashes() throws URISyntaxException {
|
public void testIsCompositeURIWithQueryAndSlashes() throws URISyntaxException {
|
||||||
URI[] compositeURIs = new URI[] { new URI("test://(part1://host?part1=true)?outside=true"), new URI("broker://(tcp://localhost:61616)?name=foo") };
|
URI[] compositeURIs = new URI[] { new URI("test://(part1://host?part1=true)?outside=true"), new URI("broker://(tcp://localhost:61616)?name=foo") };
|
||||||
for (URI uri : compositeURIs) {
|
for (URI uri : compositeURIs) {
|
||||||
|
@ -192,6 +212,7 @@ public class URISupportTest extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testIsCompositeURINoQueryNoSlashes() throws URISyntaxException {
|
public void testIsCompositeURINoQueryNoSlashes() throws URISyntaxException {
|
||||||
URI[] compositeURIs = new URI[] { new URI("test:(part1://host,part2://(sub1://part,sube2:part))"), new URI("test:(path)/path") };
|
URI[] compositeURIs = new URI[] { new URI("test:(part1://host,part2://(sub1://part,sube2:part))"), new URI("test:(path)/path") };
|
||||||
for (URI uri : compositeURIs) {
|
for (URI uri : compositeURIs) {
|
||||||
|
@ -199,10 +220,12 @@ public class URISupportTest extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testIsCompositeURINoQueryNoSlashesNoParentheses() throws URISyntaxException {
|
public void testIsCompositeURINoQueryNoSlashesNoParentheses() throws URISyntaxException {
|
||||||
assertFalse("test:part1" + " must be detected as non-composite URI", URISupport.isCompositeURI(new URI("test:part1")));
|
assertFalse("test:part1" + " must be detected as non-composite URI", URISupport.isCompositeURI(new URI("test:part1")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testIsCompositeURINoQueryWithSlashes() throws URISyntaxException {
|
public void testIsCompositeURINoQueryWithSlashes() throws URISyntaxException {
|
||||||
URI[] compositeURIs = new URI[] { new URI("failover://(tcp://bla:61616,tcp://bla:61617)"),
|
URI[] compositeURIs = new URI[] { new URI("failover://(tcp://bla:61616,tcp://bla:61617)"),
|
||||||
new URI("failover://(tcp://localhost:61616,ssl://anotherhost:61617)") };
|
new URI("failover://(tcp://localhost:61616,ssl://anotherhost:61617)") };
|
||||||
|
@ -210,5 +233,4 @@ public class URISupportTest extends TestCase {
|
||||||
assertTrue(uri + " must be detected as composite URI", URISupport.isCompositeURI(uri));
|
assertTrue(uri + " must be detected as composite URI", URISupport.isCompositeURI(uri));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue