You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2009/06/30 19:36:25 UTC
svn commit: r789841 - in /activemq/sandbox/activemq-flow: ./ activemq-util/
activemq-util/src/main/java/org/apache/activemq/util/
activemq-util/src/main/java/org/apache/activemq/util/buffer/
activemq-util/src/test/java/org/apache/activemq/apollo/ activ...
Author: chirino
Date: Tue Jun 30 17:36:25 2009
New Revision: 789841
URL: http://svn.apache.org/viewvc?rev=789841&view=rev
Log:
- fixing some failures
- Starting to experiment with TestNG
Added:
activemq/sandbox/activemq-flow/activemq-util/src/test/java/org/apache/activemq/apollo/Combinator.java
Modified:
activemq/sandbox/activemq-flow/activemq-util/pom.xml
activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/IOHelper.java
activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/buffer/DataByteArrayInputStream.java
activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/buffer/DataByteArrayOutputStream.java
activemq/sandbox/activemq-flow/activemq-util/src/test/java/org/apache/activemq/util/BitArrayBinTest.java
activemq/sandbox/activemq-flow/pom.xml
Modified: activemq/sandbox/activemq-flow/activemq-util/pom.xml
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-util/pom.xml?rev=789841&r1=789840&r2=789841&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-util/pom.xml (original)
+++ activemq/sandbox/activemq-flow/activemq-util/pom.xml Tue Jun 30 17:36:25 2009
@@ -66,7 +66,14 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>5.8</version>
+ <scope>test</scope>
+ <classifier>jdk15</classifier>
+ </dependency>
+
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
Modified: activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/IOHelper.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/IOHelper.java?rev=789841&r1=789840&r2=789841&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/IOHelper.java (original)
+++ activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/IOHelper.java Tue Jun 30 17:36:25 2009
@@ -221,8 +221,7 @@
}
}
};
- } catch (Exception ignore) {
- ignore.printStackTrace();
+ } catch (Throwable ignore) {
// Perhaps we should issue a warning here so folks know that
// the disk syncs are not going to be of very good quality.
}
Modified: activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/buffer/DataByteArrayInputStream.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/buffer/DataByteArrayInputStream.java?rev=789841&r1=789840&r2=789841&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/buffer/DataByteArrayInputStream.java (original)
+++ activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/buffer/DataByteArrayInputStream.java Tue Jun 30 17:36:25 2009
@@ -294,7 +294,7 @@
case 12:
case 13:
pos += 2;
- if (pos > length) {
+ if (pos > total) {
throw new UTFDataFormatException("bad string");
}
c2 = (int)buf[pos - 1];
@@ -305,7 +305,7 @@
break;
case 14:
pos += 3;
- if (pos > length) {
+ if (pos > total) {
throw new UTFDataFormatException("bad string");
}
c2 = (int)buf[pos - 2];
Modified: activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/buffer/DataByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/buffer/DataByteArrayOutputStream.java?rev=789841&r1=789840&r2=789841&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/buffer/DataByteArrayOutputStream.java (original)
+++ activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/util/buffer/DataByteArrayOutputStream.java Tue Jun 30 17:36:25 2009
@@ -257,7 +257,7 @@
}
onWrite();
}
-
+
private void ensureEnoughBuffer(int newcount) {
if (newcount > buf.length) {
byte newbuf[] = new byte[Math.max(buf.length << 1, newcount)];
Added: activemq/sandbox/activemq-flow/activemq-util/src/test/java/org/apache/activemq/apollo/Combinator.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-util/src/test/java/org/apache/activemq/apollo/Combinator.java?rev=789841&view=auto
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-util/src/test/java/org/apache/activemq/apollo/Combinator.java (added)
+++ activemq/sandbox/activemq-flow/activemq-util/src/test/java/org/apache/activemq/apollo/Combinator.java Tue Jun 30 17:36:25 2009
@@ -0,0 +1,160 @@
+package org.apache.activemq.apollo;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * Combinator objects are used to compute all the possible combinations given a set of combination options.
+ * This class is generally use in conjunction with TestNG test cases generate the @Factory and @DataProvider
+ * results.
+ *
+ * @author chirino
+ */
+public class Combinator {
+
+ private LinkedHashMap<String, ComboOption> comboOptions = new LinkedHashMap<String, ComboOption>();
+ private int annonymousAttributeCounter;
+
+ static class ComboOption {
+ final String attribute;
+ final LinkedHashSet<Object> values = new LinkedHashSet<Object>();
+
+ public ComboOption(String attribute, Collection<Object> options) {
+ this.attribute = attribute;
+ this.values.addAll(options);
+ }
+ }
+
+ public void put(String attribute, Object... options) {
+ ComboOption co = this.comboOptions.get(attribute);
+ if (co == null) {
+ this.comboOptions.put(attribute, new ComboOption(attribute, Arrays.asList(options)));
+ } else {
+ co.values.addAll(Arrays.asList(options));
+ }
+ }
+
+ public void add(Object... options) {
+ put(""+(annonymousAttributeCounter++), options);
+ }
+
+// @SuppressWarnings("unchecked")
+// public void addFromContext(ApplicationContext applicationContext, String name) {
+// List<Object> list = (List)applicationContext.getBean(name);
+// Object[] options = list.toArray();
+// add(options);
+// }
+//
+// public void addAllFromContext(ApplicationContext applicationContext, String name) {
+// List<List<Object>> list = (List)applicationContext.getBean(name);
+// for (List<Object> l : list) {
+// Object[] options = l.toArray();
+// add(options);
+// }
+// }
+
+
+ public List<Map<String, Object>> combinations() {
+ List<Map<String, Object>> expandedOptions = new ArrayList<Map<String, Object>>();
+ expandCombinations(new ArrayList<ComboOption>(comboOptions.values()), expandedOptions);
+ return expandedOptions;
+
+ }
+
+ private void expandCombinations(List<ComboOption> optionsLeft, List<Map<String, Object>> expandedCombos) {
+ if (!optionsLeft.isEmpty()) {
+ Map<String, Object> map;
+ if (comboOptions.size() == optionsLeft.size()) {
+ map = new LinkedHashMap<String, Object>();
+ expandedCombos.add(map);
+ } else {
+ map = expandedCombos.get(expandedCombos.size() - 1);
+ }
+
+ LinkedList<ComboOption> l = new LinkedList<ComboOption>(optionsLeft);
+ ComboOption comboOption = l.removeFirst();
+ int i = 0;
+ for (Iterator<Object> iter = comboOption.values.iterator(); iter.hasNext();) {
+ Object value = iter.next();
+ if (i != 0) {
+ map = new LinkedHashMap<String, Object>(map);
+ expandedCombos.add(map);
+ }
+ map.put(comboOption.attribute, value);
+ expandCombinations(l, expandedCombos);
+ i++;
+ }
+ }
+ }
+
+ /**
+ * Creates a bean for each combination of the type specified by clazz arguement and uses setter/field
+ * injection to initialize the Bean with the combination values.
+ *
+ * @param <T>
+ * @param clazz
+ * @return
+ * @throws InstantiationException
+ * @throws IllegalAccessException
+ */
+ public <T> Object[] combinationsAsBeans(Class<T> clazz) throws Exception {
+ List<Map<String, Object>> combinations = combinations();
+ List<T> rc = new ArrayList<T>(combinations.size());
+ for (Map<String, Object> combination : combinations) {
+ T instance = clazz.newInstance();
+
+ for (Entry<String, Object> entry : combination.entrySet()) {
+ String key = entry.getKey();
+ Object value = entry.getValue();
+ try {
+ // Try setter injection..
+ Method method = clazz.getMethod("set"+ucfc(key), value.getClass());
+ method.invoke(instance, new Object[]{value});
+ } catch (Exception ignore) {
+ // Try property injection..
+ Field declaredField = clazz.getDeclaredField(key);
+ declaredField.set(instance, value);
+ }
+ }
+
+ rc.add(instance);
+ }
+ Object[] t = new Object[rc.size()];
+ rc.toArray(t);
+ return t;
+ }
+
+ /**
+ * Upper case the first character.
+ * @param key
+ * @return
+ */
+ static private String ucfc(String key) {
+ return key.substring(0,1).toUpperCase()+key.substring(1);
+ }
+
+ public Object[][] combinationsAsParameterArgs() {
+ List<Map<String, Object>> combinations = combinations();
+ Object[][] rc = new Object[combinations.size()][];
+ int i=0;
+ for (Map<String, Object> combination : combinations) {
+ int j=0;
+ Object[] arg = new Object[combination.size()];
+ for (Object object : combination.values()) {
+ arg[j++] = object;
+ }
+ rc[i++] = arg;
+ }
+ return rc;
+ }
+
+}
Modified: activemq/sandbox/activemq-flow/activemq-util/src/test/java/org/apache/activemq/util/BitArrayBinTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-util/src/test/java/org/apache/activemq/util/BitArrayBinTest.java?rev=789841&r1=789840&r2=789841&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-util/src/test/java/org/apache/activemq/util/BitArrayBinTest.java (original)
+++ activemq/sandbox/activemq-flow/activemq-util/src/test/java/org/apache/activemq/util/BitArrayBinTest.java Tue Jun 30 17:36:25 2009
@@ -1,10 +1,12 @@
package org.apache.activemq.util;
-import junit.framework.TestCase;
+import org.testng.Assert;
+import org.testng.annotations.Test;
-public class BitArrayBinTest extends TestCase {
+public class BitArrayBinTest {
- public void testSetAroundWindow() throws Exception {
+ @Test()
+ public void testSetAroundWindow() throws Exception {
doTestSetAroundWindow(500, 2000);
doTestSetAroundWindow(512, 2000);
doTestSetAroundWindow(128, 512);
@@ -15,25 +17,26 @@
BitArrayBin toTest = new BitArrayBin(window);
for (int i=0; i <= dataSize; i++) {
- assertTrue("not already set", !toTest.setBit(i, Boolean.TRUE));
+ Assert.assertTrue((!toTest.setBit(i, Boolean.TRUE)), "not already set");
}
int windowOfValidData = roundWindow(dataSize, window);
int i=dataSize;
for (; i >= dataSize -windowOfValidData; i--) {
- assertTrue("was already set, id=" + i, toTest.setBit(i, Boolean.TRUE));
+ Assert.assertTrue(toTest.setBit(i, Boolean.TRUE), ("was already set, id=" + i));
}
for (; i >= 0; i--) {
- assertTrue("was not already set, id=" + i, !toTest.setBit(i, Boolean.TRUE));
+ Assert.assertTrue((!toTest.setBit(i, Boolean.TRUE)), ("was not already set, id=" + i));
}
for (int j= dataSize +1; j<(2*dataSize); j++) {
- assertTrue("not already set: id=" + j, !toTest.setBit(j, Boolean.TRUE));
+ Assert.assertTrue((!toTest.setBit(j, Boolean.TRUE)), ("not already set: id=" + j));
}
}
- public void testSetUnsetAroundWindow() throws Exception {
+ @Test()
+ public void testSetUnsetAroundWindow() throws Exception {
doTestSetUnSetAroundWindow(500, 2000);
doTestSetUnSetAroundWindow(512, 2000);
doTestSetUnSetAroundWindow(128, 512);
@@ -44,24 +47,25 @@
BitArrayBin toTest = new BitArrayBin(window);
for (int i=0; i <=dataSize; i++) {
- assertTrue("not already set", !toTest.setBit(i, Boolean.TRUE));
+ Assert.assertTrue((!toTest.setBit(i, Boolean.TRUE)), "not already set");
}
int windowOfValidData = roundWindow(dataSize, window);
for (int i=dataSize; i >= 0 && i >=dataSize -windowOfValidData; i--) {
- assertTrue("was already set, id=" + i, toTest.setBit(i, Boolean.FALSE));
+ Assert.assertTrue(toTest.setBit(i, Boolean.FALSE), ("was already set, id=" + i));
}
for (int i=0; i <=dataSize; i++) {
- assertTrue("not already set, id:" + i, !toTest.setBit(i, Boolean.TRUE));
+ Assert.assertTrue((!toTest.setBit(i, Boolean.TRUE)), ("not already set, id:" + i));
}
for (int j= 2*dataSize; j< 4*dataSize; j++) {
- assertTrue("not already set: id=" + j, !toTest.setBit(j, Boolean.TRUE));
+ Assert.assertTrue((!toTest.setBit(j, Boolean.TRUE)), ("not already set: id=" + j));
}
}
- public void testSetAroundLongSizeMultiplier() throws Exception {
+ @Test()
+ public void testSetAroundLongSizeMultiplier() throws Exception {
int window = 512;
int dataSize = 1000;
for (int muliplier=1; muliplier <8; muliplier++) {
@@ -69,13 +73,14 @@
BitArrayBin toTest = new BitArrayBin(window);
int instance = value +muliplier*BitArray.LONG_SIZE;
- assertTrue("not already set: id=" + instance, !toTest.setBit(instance, Boolean.TRUE));
- assertTrue("not already set: id=" + value, !toTest.setBit(value, Boolean.TRUE));
+ Assert.assertTrue((!toTest.setBit(instance, Boolean.TRUE)), ("not already set: id=" + instance));
+ Assert.assertTrue((!toTest.setBit(value, Boolean.TRUE)), ("not already set: id=" + value));
}
}
}
- public void testLargeGapInData(int window) throws Exception {
+ @Test()
+ public void testLargeGapInData() throws Exception {
doTestLargeGapInData(128);
doTestLargeGapInData(500);
}
@@ -84,13 +89,13 @@
BitArrayBin toTest = new BitArrayBin(window);
int instance = BitArray.LONG_SIZE;
- assertTrue("not already set: id=" + instance, !toTest.setBit(instance, Boolean.TRUE));
+ Assert.assertTrue((!toTest.setBit(instance, Boolean.TRUE)), ("not already set: id=" + instance));
instance = 12 *BitArray.LONG_SIZE;
- assertTrue("not already set: id=" + instance, !toTest.setBit(instance, Boolean.TRUE));
+ Assert.assertTrue((!toTest.setBit(instance, Boolean.TRUE)), ("not already set: id=" + instance));
instance = 9 *BitArray.LONG_SIZE;
- assertTrue("not already set: id=" + instance, !toTest.setBit(instance, Boolean.TRUE));
+ Assert.assertTrue((!toTest.setBit(instance, Boolean.TRUE)), ("not already set: id=" + instance));
}
// window moves in increments of BitArray.LONG_SIZE.
Modified: activemq/sandbox/activemq-flow/pom.xml
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/pom.xml?rev=789841&r1=789840&r2=789841&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/pom.xml (original)
+++ activemq/sandbox/activemq-flow/pom.xml Tue Jun 30 17:36:25 2009
@@ -65,6 +65,7 @@
<jetty-version>6.1.9</jetty-version>
<jmock-version>1.0.1</jmock-version>
<junit-version>4.4</junit-version>
+ <testng-version>5.8</testng-version>
<jxta-version>2.0</jxta-version>
<log4j-version>1.2.14</log4j-version>
<nlog4j-version>1.5.2</nlog4j-version>
@@ -705,6 +706,14 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>${testng-version}</version>
+ <scope>test</scope>
+ <classifier>jdk15</classifier>
+ </dependency>
+
+ <dependency>
<groupId>jmock</groupId>
<artifactId>jmock</artifactId>
<version>${jmock-version}</version>
@@ -887,8 +896,11 @@
<exclude>**/perf/**</exclude>
<exclude>**/jaxb/**</exclude>
</excludes>
+ <parallel>methods</parallel>
+ <threadCount>16</threadCount>
</configuration>
</plugin>
+
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>