Created
November 28, 2013 18:50
-
-
Save cfoster/7696623 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.basex.core.Context; | |
import org.basex.io.out.ArrayOutput; | |
import org.basex.io.serial.Serializer; | |
import org.basex.query.QueryProcessor; | |
import org.basex.query.iter.Iter; | |
import org.basex.query.value.item.Item; | |
public class PTest | |
{ | |
public static Context ctx = new Context(); // mainContext | |
public static void main(String[] args) | |
{ | |
new PTest().startTest(); | |
} | |
public void startTest() | |
{ | |
int threadCount = 100; | |
Test[] testThreads = new Test[threadCount]; | |
for(int i=0;i<threadCount;i++) | |
{ | |
testThreads[i] = new Test((i+1)); | |
testThreads[i].start(); | |
System.out.println("started test "+(i+1)); | |
} | |
for(int i=0;i<threadCount;i++) | |
{ | |
try { | |
testThreads[i].join(); | |
} catch(InterruptedException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} | |
class Test extends Thread | |
{ | |
private int id; | |
public Test(int id) { | |
this.id = id; | |
} | |
public void run() | |
{ | |
try { | |
QueryProcessor qp = new QueryProcessor("1 to 1024", ctx); | |
qp.parse(); | |
ctx.register(qp); | |
qp.compile(); | |
Iter iter = qp.iter(); | |
Item item; | |
ArrayOutput out = new ArrayOutput(); | |
int n=1; | |
while((item=iter.next()) != null) | |
{ | |
out.reset(); | |
Serializer ser = Serializer.get(out); | |
ser.serialize(item); | |
if(!String.valueOf(n).equals(out.toString())) | |
{ | |
System.err.println( | |
"expected "+n+", item value was "+out.toString()); | |
} | |
ser.close(); | |
n++; | |
} | |
System.out.println("test "+id+" finished."); | |
qp.close(); | |
ctx.unregister(qp); | |
} | |
catch(Throwable e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment