Search in sources :

Example 16 with Store

use of org.h2.mvstore.db.MVTableEngine.Store in project h2database by h2database.

the class TestAll method testUnit.

private void testUnit() {
    // mv store
    addTest(new TestCacheConcurrentLIRS());
    addTest(new TestCacheLIRS());
    addTest(new TestCacheLongKeyLIRS());
    addTest(new TestConcurrentLinkedList());
    addTest(new TestDataUtils());
    addTest(new TestFreeSpace());
    addTest(new TestKillProcessWhileWriting());
    addTest(new TestMVRTree());
    addTest(new TestMVStore());
    addTest(new TestMVStoreBenchmark());
    addTest(new TestMVStoreStopCompact());
    addTest(new TestMVStoreTool());
    addTest(new TestMVTableEngine());
    addTest(new TestObjectDataType());
    addTest(new TestRandomMapOps());
    addTest(new TestSpinLock());
    addTest(new TestStreamStore());
    addTest(new TestTransactionStore());
    // unit
    addTest(new TestAnsCompression());
    addTest(new TestAutoReconnect());
    addTest(new TestBinaryArithmeticStream());
    addTest(new TestBitStream());
    addTest(new TestBnf());
    addTest(new TestCache());
    addTest(new TestCharsetCollator());
    addTest(new TestClearReferences());
    addTest(new TestCollation());
    addTest(new TestCompress());
    addTest(new TestConnectionInfo());
    addTest(new TestDataPage());
    addTest(new TestDateIso8601());
    addTest(new TestExit());
    addTest(new TestFile());
    addTest(new TestFileLock());
    addTest(new TestFtp());
    addTest(new TestIntArray());
    addTest(new TestIntIntHashMap());
    addTest(new TestIntPerfectHash());
    addTest(new TestJmx());
    addTest(new TestMathUtils());
    addTest(new TestMode());
    addTest(new TestModifyOnWrite());
    addTest(new TestOldVersion());
    addTest(new TestObjectDeserialization());
    addTest(new TestMultiThreadedKernel());
    addTest(new TestOverflow());
    addTest(new TestPageStore());
    addTest(new TestPageStoreCoverage());
    addTest(new TestPerfectHash());
    addTest(new TestPgServer());
    addTest(new TestReader());
    addTest(new TestRecovery());
    addTest(new TestScriptReader());
    addTest(new RecoverLobTest());
    addTest(createTest("org.h2.test.unit.TestServlet"));
    addTest(new TestSecurity());
    addTest(new TestShell());
    addTest(new TestSort());
    addTest(new TestStreams());
    addTest(new TestStringUtils());
    addTest(new TestTimeStampWithTimeZone());
    addTest(new TestTraceSystem());
    addTest(new TestUpgrade());
    addTest(new TestUsingIndex());
    addTest(new TestUtils());
    addTest(new TestValue());
    addTest(new TestValueHashMap());
    addTest(new TestWeb());
    runAddedTests();
    // serial
    addTest(new TestDate());
    addTest(new TestDateTimeUtils());
    addTest(new TestCluster());
    addTest(new TestConcurrent());
    addTest(new TestFileLockSerialized());
    addTest(new TestFileLockProcess());
    addTest(new TestFileSystem());
    addTest(new TestNetUtils());
    addTest(new TestPattern());
    addTest(new TestTools());
    addTest(new TestSampleApps());
    addTest(new TestStringCache());
    addTest(new TestValueMemory());
    runAddedTests(1);
}
Also used : TestPageStoreCoverage(org.h2.test.unit.TestPageStoreCoverage) TestDateIso8601(org.h2.test.unit.TestDateIso8601) RecoverLobTest(org.h2.test.recover.RecoverLobTest) TestMVTableEngine(org.h2.test.store.TestMVTableEngine) TestPgServer(org.h2.test.unit.TestPgServer) TestValueMemory(org.h2.test.unit.TestValueMemory) TestKillProcessWhileWriting(org.h2.test.store.TestKillProcessWhileWriting) TestExit(org.h2.test.unit.TestExit) TestMode(org.h2.test.unit.TestMode) TestPageStore(org.h2.test.unit.TestPageStore) TestSort(org.h2.test.unit.TestSort) TestUtils(org.h2.test.unit.TestUtils) TestOldVersion(org.h2.test.unit.TestOldVersion) TestObjectDeserialization(org.h2.test.unit.TestObjectDeserialization) TestCompress(org.h2.test.unit.TestCompress) TestCluster(org.h2.test.db.TestCluster) TestCharsetCollator(org.h2.test.unit.TestCharsetCollator) TestFileLockSerialized(org.h2.test.unit.TestFileLockSerialized) TestMVStoreBenchmark(org.h2.test.store.TestMVStoreBenchmark) TestFileLock(org.h2.test.unit.TestFileLock) TestIntArray(org.h2.test.unit.TestIntArray) TestCacheLongKeyLIRS(org.h2.test.store.TestCacheLongKeyLIRS) TestOverflow(org.h2.test.unit.TestOverflow) TestModifyOnWrite(org.h2.test.unit.TestModifyOnWrite) TestPattern(org.h2.test.unit.TestPattern) TestValueHashMap(org.h2.test.unit.TestValueHashMap) TestReader(org.h2.test.unit.TestReader) TestNetUtils(org.h2.test.unit.TestNetUtils) TestObjectDataType(org.h2.test.store.TestObjectDataType) TestDataPage(org.h2.test.unit.TestDataPage) TestWeb(org.h2.test.server.TestWeb) TestTraceSystem(org.h2.test.unit.TestTraceSystem) TestClearReferences(org.h2.test.unit.TestClearReferences) TestUpgrade(org.h2.test.db.TestUpgrade) TestStreamStore(org.h2.test.store.TestStreamStore) TestTransactionStore(org.h2.test.store.TestTransactionStore) TestConnectionInfo(org.h2.test.unit.TestConnectionInfo) TestTools(org.h2.test.unit.TestTools) TestStreams(org.h2.test.unit.TestStreams) TestFile(org.h2.test.unit.TestFile) TestSampleApps(org.h2.test.unit.TestSampleApps) TestCacheConcurrentLIRS(org.h2.test.store.TestCacheConcurrentLIRS) TestConcurrent(org.h2.test.store.TestConcurrent) TestFtp(org.h2.test.unit.TestFtp) TestStringUtils(org.h2.test.unit.TestStringUtils) TestSpinLock(org.h2.test.store.TestSpinLock) TestDataUtils(org.h2.test.store.TestDataUtils) TestUsingIndex(org.h2.test.db.TestUsingIndex) TestRandomMapOps(org.h2.test.store.TestRandomMapOps) TestValue(org.h2.test.unit.TestValue) TestIntPerfectHash(org.h2.test.unit.TestIntPerfectHash) TestMVStore(org.h2.test.store.TestMVStore) TestMathUtils(org.h2.test.unit.TestMathUtils) TestRecovery(org.h2.test.unit.TestRecovery) TestTimeStampWithTimeZone(org.h2.test.unit.TestTimeStampWithTimeZone) TestFileLockProcess(org.h2.test.unit.TestFileLockProcess) TestMultiThreadedKernel(org.h2.test.db.TestMultiThreadedKernel) TestFreeSpace(org.h2.test.store.TestFreeSpace) TestDateTimeUtils(org.h2.test.unit.TestDateTimeUtils) TestMVRTree(org.h2.test.store.TestMVRTree) TestSecurity(org.h2.test.unit.TestSecurity) TestMVStoreTool(org.h2.test.store.TestMVStoreTool) TestIntIntHashMap(org.h2.test.unit.TestIntIntHashMap) TestBnf(org.h2.test.unit.TestBnf) TestCacheLIRS(org.h2.test.store.TestCacheLIRS) TestAutoReconnect(org.h2.test.unit.TestAutoReconnect) TestBinaryArithmeticStream(org.h2.test.unit.TestBinaryArithmeticStream) TestCollation(org.h2.test.unit.TestCollation) TestJmx(org.h2.test.unit.TestJmx) TestPerfectHash(org.h2.test.unit.TestPerfectHash) TestAnsCompression(org.h2.test.unit.TestAnsCompression) TestShell(org.h2.test.unit.TestShell) TestStringCache(org.h2.test.unit.TestStringCache) TestConcurrentLinkedList(org.h2.test.store.TestConcurrentLinkedList) TestCache(org.h2.test.unit.TestCache) TestDate(org.h2.test.unit.TestDate) TestMVStoreStopCompact(org.h2.test.store.TestMVStoreStopCompact) TestBitStream(org.h2.test.unit.TestBitStream) TestScriptReader(org.h2.test.unit.TestScriptReader) TestFileSystem(org.h2.test.unit.TestFileSystem)

Example 17 with Store

use of org.h2.mvstore.db.MVTableEngine.Store 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);
    }
}
Also used : FileStore(org.h2.store.FileStore) InputStreamReader(java.io.InputStreamReader) FileStoreInputStream(org.h2.store.FileStoreInputStream) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileStoreInputStream(org.h2.store.FileStoreInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) IOException(java.io.IOException) LineNumberReader(java.io.LineNumberReader)

Example 18 with Store

use of org.h2.mvstore.db.MVTableEngine.Store in project h2database by h2database.

the class ValueLob method getInputStream.

@Override
public InputStream getInputStream() {
    if (fileName == null) {
        return new ByteArrayInputStream(small);
    }
    FileStore store = handler.openFile(fileName, "r", true);
    boolean alwaysClose = SysProperties.lobCloseBetweenReads;
    return new BufferedInputStream(new FileStoreInputStream(store, handler, compressed, alwaysClose), Constants.IO_BUFFER_SIZE);
}
Also used : FileStore(org.h2.store.FileStore) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) FileStoreInputStream(org.h2.store.FileStoreInputStream)

Example 19 with Store

use of org.h2.mvstore.db.MVTableEngine.Store 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();
}
Also used : Task(org.h2.util.Task) CountDownLatch(java.util.concurrent.CountDownLatch) MVStore(org.h2.mvstore.MVStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 20 with Store

use of org.h2.mvstore.db.MVTableEngine.Store in project h2database by h2database.

the class TestBenchmark method testConcurrency.

private void testConcurrency() throws Exception {
    // String fileName = getBaseDir() + "/" + getTestName();
    String fileName = "nioMemFS:/" + getTestName();
    FileUtils.delete(fileName);
    MVStore store = new MVStore.Builder().cacheSize(16).fileName(fileName).open();
    MVMap<Integer, byte[]> map = store.openMap("test");
    byte[] data = new byte[1024];
    int count = 1000000;
    for (int i = 0; i < count; i++) {
        map.put(i, data);
    }
    store.close();
    for (int concurrency = 1024; concurrency > 0; concurrency /= 2) {
        testConcurrency(fileName, concurrency, count);
        testConcurrency(fileName, concurrency, count);
        testConcurrency(fileName, concurrency, count);
    }
    FileUtils.delete(fileName);
}
Also used : MVStore(org.h2.mvstore.MVStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

MVStore (org.h2.mvstore.MVStore)29 IOException (java.io.IOException)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 ByteArrayInputStream (java.io.ByteArrayInputStream)10 InputStream (java.io.InputStream)8 HashMap (java.util.HashMap)8 DbException (org.h2.message.DbException)8 StreamStore (org.h2.mvstore.StreamStore)8 PageStore (org.h2.store.PageStore)8 Random (java.util.Random)7 OutputStream (java.io.OutputStream)6 FileStore (org.h2.store.FileStore)6 BufferedInputStream (java.io.BufferedInputStream)5 ArrayList (java.util.ArrayList)5 FileStore (org.h2.mvstore.FileStore)5 Store (org.h2.mvstore.db.MVTableEngine.Store)5 Row (org.h2.result.Row)5 FileStoreInputStream (org.h2.store.FileStoreInputStream)5 PrintWriter (java.io.PrintWriter)4 Database (org.h2.engine.Database)4