Author: vgritsenko
Date: Tue Aug 7 06:44:56 2007
New Revision: 563499
URL: http://svn.apache.org/viewvc?view=rev&rev=563499
Log:
start all threads at once
Modified:
xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java
Modified:
xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java
URL:
http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java?view=diff&rev=563499&r1=563498&r2=563499
==============================================================================
---
xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java
(original)
+++
xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java
Tue Aug 7 06:44:56 2007
@@ -153,53 +153,61 @@
}
public void testConcurrentCreateCollection() throws Exception {
+ final int THREADS = 10;
final String name = "create";
- try {
- final int THREADS = 10;
- Thread[] threads = new Thread[THREADS];
- final Counter count = new Counter();
-
- for (int i = 0; i < THREADS; i++) {
+ final Object go = new Object();
+ final Counter count = new Counter();
- threads[i] = new Thread() {
- public void run() {
+ Thread[] threads = new Thread[THREADS];
+ for (int i = 0; i < THREADS; i++) {
+ threads[i] = new Thread() {
+ public void run() {
+ synchronized (go) {
try {
- db.createCollection(name, new Configuration(
- DOMParser.toDocument(
- "<collection compressed='true'
name='" + name + "' inline-metadata='true'>" +
- " <filer
class='org.apache.xindice.core.filer.BTreeFiler' />" +
- "</collection>"), false
- ));
- } catch (DBException e) {
- if (e.faultCode ==
FaultCodes.COL_DUPLICATE_COLLECTION) {
- count.incCount();
- } else {
- throw new RuntimeException("Failure: " + e);
- }
- } catch (XindiceException e) {
- // ignore
+ go.wait();
+ } catch (InterruptedException e) { /* ignored */ }
+ }
+
+ try {
+ db.createCollection(name, new Configuration(
+ DOMParser.toDocument(
+ "<collection compressed='true'
name='" + name + "' inline-metadata='true'>" +
+ " <filer
class='org.apache.xindice.core.filer.BTreeFiler' />" +
+ "</collection>"), false
+ ));
+ } catch (DBException e) {
+ if (e.faultCode ==
FaultCodes.COL_DUPLICATE_COLLECTION) {
+ count.incCount();
+ } else {
+ throw new RuntimeException("Failure: " + e);
}
+ } catch (XindiceException e) {
+ // ignore
}
- };
- }
+ }
+ };
+ threads[i].setName("CollectionTest" + i);
+ threads[i].start();
+ }
- for (int i = 0; i < THREADS; i++) {
- threads[i].start();
+ try {
+ // Start all the threads at once
+ Thread.sleep(250);
+ synchronized (go) {
+ go.notifyAll();
}
-
for (int i = 0; i < THREADS; i++) {
threads[i].join();
}
-
- assertEquals(THREADS - 1, count.getCount());
-
} finally {
Collection col = db.getCollection(name);
- if (col != null) {
- db.dropCollection(col);
- }
+ if (col != null) {
+ db.dropCollection(col);
+ }
}
+
+ assertEquals(THREADS - 1, count.getCount());
}
private class Counter {