use of org.h2.command.dml.Call in project h2database by h2database.
the class TestOldVersion method testOldClientNewServer.
private void testOldClientNewServer() throws Exception {
Server server = org.h2.tools.Server.createTcpServer();
server.start();
int port = server.getPort();
assertThrows(ErrorCode.DRIVER_VERSION_ERROR_2, driver).connect("jdbc:h2:tcp://localhost:" + port + "/mem:test", null);
server.stop();
Class<?> serverClass = cl.loadClass("org.h2.tools.Server");
Method m;
m = serverClass.getMethod("createTcpServer", String[].class);
Object serverOld = m.invoke(null, new Object[] { new String[] { "-tcpPort", "" + port } });
m = serverOld.getClass().getMethod("start");
m.invoke(serverOld);
Connection conn;
conn = org.h2.Driver.load().connect("jdbc:h2:mem:", null);
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("call 1");
rs.next();
assertEquals(1, rs.getInt(1));
conn.close();
m = serverOld.getClass().getMethod("stop");
m.invoke(serverOld);
}
use of org.h2.command.dml.Call in project h2database by h2database.
the class TestCompress method testMultiThreaded.
private void testMultiThreaded() throws Exception {
Task[] tasks = new Task[3];
for (int i = 0; i < tasks.length; i++) {
Task t = new Task() {
@Override
public void call() {
CompressTool tool = CompressTool.getInstance();
byte[] b = new byte[1024];
Random r = new Random();
while (!stop) {
r.nextBytes(b);
byte[] test = tool.expand(tool.compress(b, "LZF"));
assertEquals(b, test);
}
}
};
tasks[i] = t;
t.execute();
}
Thread.sleep(1000);
for (Task t : tasks) {
t.get();
}
}
use of org.h2.command.dml.Call in project h2database by h2database.
the class TestFileLockSerialized method testTwoWriters.
private void testTwoWriters() throws Exception {
deleteDb("fileLockSerialized");
String url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized";
final String writeUrl = url + ";FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE";
Connection conn = getConnection(writeUrl, "sa", "sa");
conn.createStatement().execute("create table test(id identity) as " + "select x from system_range(1, 100)");
conn.close();
Task task = new Task() {
@Override
public void call() throws Exception {
while (!stop) {
Thread.sleep(10);
Connection c = getConnection(writeUrl, "sa", "sa");
c.createStatement().execute("select * from test");
c.close();
}
}
}.execute();
Thread.sleep(20);
for (int i = 0; i < 2; i++) {
conn = getConnection(writeUrl, "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("drop table test");
stat.execute("create table test(id identity) as " + "select x from system_range(1, 100)");
conn.createStatement().execute("select * from test");
conn.close();
}
Thread.sleep(100);
conn = getConnection(writeUrl, "sa", "sa");
conn.createStatement().execute("select * from test");
conn.close();
task.get();
}
use of org.h2.command.dml.Call in project h2database by h2database.
the class TestWeb method testStartWebServerWithConnection.
private void testStartWebServerWithConnection() throws Exception {
String old = System.getProperty(SysProperties.H2_BROWSER);
try {
System.setProperty(SysProperties.H2_BROWSER, "call:" + TestWeb.class.getName() + ".openBrowser");
Server.openBrowser("testUrl");
assertEquals("testUrl", lastUrl);
String oldUrl = lastUrl;
final Connection conn = getConnection(getTestName());
Task t = new Task() {
@Override
public void call() throws Exception {
Server.startWebServer(conn, true);
}
};
t.execute();
for (int i = 0; lastUrl == oldUrl; i++) {
if (i > 100) {
throw new Exception("Browser not started");
}
Thread.sleep(100);
}
String url = lastUrl;
WebClient client = new WebClient();
client.readSessionId(url);
url = client.getBaseUrl(url);
try {
client.get(url, "logout.do");
} catch (ConnectException e) {
// the server stops on logout
}
t.get();
conn.close();
} finally {
if (old != null) {
System.setProperty(SysProperties.H2_BROWSER, old);
} else {
System.clearProperty(SysProperties.H2_BROWSER);
}
}
}
use of org.h2.command.dml.Call in project h2database by h2database.
the class TestBenchmark method testConcurrency.
private void testConcurrency(String fileName, int concurrency, final int count) throws Exception {
Thread.sleep(1000);
final MVStore store = new MVStore.Builder().cacheSize(256).cacheConcurrency(concurrency).fileName(fileName).open();
int threadCount = 128;
final CountDownLatch wait = new CountDownLatch(1);
final AtomicInteger counter = new AtomicInteger();
final AtomicBoolean stopped = new AtomicBoolean();
Task[] tasks = new Task[threadCount];
// Profiler prof = new Profiler().startCollecting();
for (int i = 0; i < threadCount; i++) {
final int x = i;
Task t = new Task() {
@Override
public void call() throws Exception {
MVMap<Integer, byte[]> map = store.openMap("test");
Random random = new Random(x);
wait.await();
while (!stopped.get()) {
int key = random.nextInt(count);
byte[] data = map.get(key);
if (data.length > 1) {
counter.incrementAndGet();
}
}
}
};
t.execute("t" + i);
tasks[i] = t;
}
wait.countDown();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
stopped.set(true);
for (Task t : tasks) {
t.get();
}
// System.out.println(prof.getTop(5));
String msg = "concurrency " + concurrency + " threads " + threadCount + " requests: " + counter;
System.out.println(msg);
trace(msg);
store.close();
}
Aggregations