Skip to content

Instantly share code, notes, and snippets.

@cfoster
Created November 28, 2013 18:50
Show Gist options
  • Save cfoster/7696623 to your computer and use it in GitHub Desktop.
Save cfoster/7696623 to your computer and use it in GitHub Desktop.
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