use of org.h2.command.dml.Set in project h2database by h2database.
the class TestIntPerfectHash method test.
private int test(byte[] desc, Set<Integer> set) {
int max = -1;
HashSet<Integer> test = new HashSet<>();
IntPerfectHash hash = new IntPerfectHash(desc);
for (int x : set) {
int h = hash.get(x);
assertTrue(h >= 0);
assertTrue(h <= set.size() * 3);
max = Math.max(max, h);
assertFalse(test.contains(h));
test.add(h);
}
return max;
}
use of org.h2.command.dml.Set in project h2database by h2database.
the class TestNetUtils method testFrequentConnections.
private static void testFrequentConnections(boolean ssl, int count) throws Exception {
final ServerSocket serverSocket = NetUtils.createServerSocket(PORT, ssl);
final AtomicInteger counter = new AtomicInteger(count);
Task serverThread = new Task() {
@Override
public void call() {
while (!stop) {
try {
Socket socket = serverSocket.accept();
// System.out.println("opened " + counter);
socket.close();
} catch (Exception e) {
// ignore
}
}
// System.out.println("stopped ");
}
};
serverThread.execute();
try {
Set<ConnectWorker> workers = new HashSet<>();
for (int i = 0; i < WORKER_COUNT; i++) {
workers.add(new ConnectWorker(ssl, counter));
}
// ensure the server is started
Thread.sleep(100);
for (ConnectWorker worker : workers) {
worker.start();
}
for (ConnectWorker worker : workers) {
worker.join();
Exception e = worker.getException();
if (e != null) {
e.printStackTrace();
}
}
} finally {
try {
serverSocket.close();
} catch (Exception e) {
// ignore
}
serverThread.get();
}
}
use of org.h2.command.dml.Set in project h2database by h2database.
the class TestFileLockSerialized method testCheckpointInUpdateRaceCondition.
/**
* If a checkpoint occurs between beforeWriting and checkWritingAllowed then
* the result of checkWritingAllowed is READ_ONLY, which is wrong.
*
* Also, if a checkpoint started before beforeWriting, and ends between
* between beforeWriting and checkWritingAllowed, then the same error
* occurs.
*/
private void testCheckpointInUpdateRaceCondition() throws Exception {
boolean longRun = false;
deleteDb("fileLockSerialized");
String url = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE";
Connection conn = getConnection(url);
conn.createStatement().execute("create table test(id int)");
conn.createStatement().execute("insert into test values(1)");
for (int i = 0; i < (longRun ? 10000 : 5); i++) {
Thread.sleep(402);
conn.createStatement().execute("update test set id = " + i);
}
conn.close();
deleteDb("fileLockSerialized");
}
use of org.h2.command.dml.Set in project h2database by h2database.
the class TestFileLockSerialized method testCache.
/**
* Caches must be cleared. Session.reconnect only closes the DiskFile (which
* is associated with the cache) if there is one session
*/
private void testCache() throws Exception {
deleteDb("fileLockSerialized");
String urlShared = "jdbc:h2:" + getBaseDir() + "/fileLockSerialized;FILE_LOCK=SERIALIZED";
Connection connShared1 = getConnection(urlShared);
Statement statement1 = connShared1.createStatement();
Connection connShared2 = getConnection(urlShared);
Statement statement2 = connShared2.createStatement();
statement1.execute("create table test1(id int)");
statement1.execute("insert into test1 values(1)");
ResultSet rs = statement1.executeQuery("select id from test1");
rs.close();
rs = statement2.executeQuery("select id from test1");
rs.close();
statement1.execute("update test1 set id=2");
Thread.sleep(500);
rs = statement2.executeQuery("select id from test1");
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
rs.close();
connShared1.close();
connShared2.close();
deleteDb("fileLockSerialized");
}
use of org.h2.command.dml.Set in project h2database by h2database.
the class CreateScriptFile method openScriptReader.
/**
* Open a script reader.
*
* @param fileName the file name (the file will be overwritten)
* @param compressionAlgorithm the compression algorithm (uppercase)
* @param cipher the encryption algorithm or null
* @param password the encryption password
* @param charset the character set (for example UTF-8)
* @return the script reader
*/
public static LineNumberReader openScriptReader(String fileName, String compressionAlgorithm, String cipher, String password, String charset) throws IOException {
try {
InputStream in;
if (cipher != null) {
byte[] key = SHA256.getKeyPasswordHash("script", password.toCharArray());
FileStore store = FileStore.open(null, fileName, "rw", cipher, key);
store.init();
in = new FileStoreInputStream(store, null, compressionAlgorithm != null, false);
in = new BufferedInputStream(in, Constants.IO_BUFFER_SIZE_COMPRESS);
} else {
in = FileUtils.newInputStream(fileName);
in = new BufferedInputStream(in, Constants.IO_BUFFER_SIZE);
in = CompressTool.wrapInputStream(in, compressionAlgorithm, "script.sql");
if (in == null) {
throw new IOException("Entry not found: script.sql in " + fileName);
}
}
return new LineNumberReader(new InputStreamReader(in, charset));
} catch (Exception e) {
throw new IOException(e.getMessage(), e);
}
}
Aggregations