当前位置: 首页>>代码示例>>Java>>正文


Java MVMap.openVersion方法代码示例

本文整理汇总了Java中org.h2.mvstore.MVMap.openVersion方法的典型用法代码示例。如果您正苦于以下问题:Java MVMap.openVersion方法的具体用法?Java MVMap.openVersion怎么用?Java MVMap.openVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.h2.mvstore.MVMap的用法示例。


在下文中一共展示了MVMap.openVersion方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testVersionsToKeep

import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testVersionsToKeep() throws Exception {
    MVStore s = new MVStore.Builder().open();
    MVMap<Integer, Integer> map;
    map = s.openMap("data");
    for (int i = 0; i < 20; i++) {
        long version = s.getCurrentVersion();
        map.put(i, i);
        s.commit();
        if (version >= 6) {
            map.openVersion(version - 5);
            try {
                map.openVersion(version - 6);
                fail();
            } catch (IllegalArgumentException e) {
                // expected
            }
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:20,代码来源:TestMVStore.java

示例2: testVersionsToKeep2

import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testVersionsToKeep2() {
    MVStore s = new MVStore.Builder().autoCommitDisabled().open();
    s.setVersionsToKeep(2);
    final MVMap<Integer, String> m = s.openMap("data");
    s.commit();
    assertEquals(1, s.getCurrentVersion());
    m.put(1, "version 1");
    s.commit();
    assertEquals(2, s.getCurrentVersion());
    m.put(1, "version 2");
    s.commit();
    assertEquals(3, s.getCurrentVersion());
    m.put(1, "version 3");
    s.commit();
    m.put(1, "version 4");
    assertEquals("version 4", m.openVersion(4).get(1));
    assertEquals("version 3", m.openVersion(3).get(1));
    assertEquals("version 2", m.openVersion(2).get(1));
    new AssertThrows(IllegalArgumentException.class) {
        @Override
        public void test() throws Exception {
            m.openVersion(1);
        }
    };
    s.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:27,代码来源:TestMVStore.java

示例3: testOldVersion

import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testOldVersion() {
    MVStore s;
    for (int op = 0; op <= 1; op++) {
        for (int i = 0; i < 5; i++) {
            s = openStore(null);
            s.setVersionsToKeep(Integer.MAX_VALUE);
            MVMap<String, String> m;
            m = s.openMap("data");
            for (int j = 0; j < 5; j++) {
                if (op == 1) {
                    m.put("1", "" + s.getCurrentVersion());
                }
                s.commit();
            }
            for (int j = 0; j < s.getCurrentVersion(); j++) {
                MVMap<String, String> old = m.openVersion(j);
                if (op == 1) {
                    assertEquals("" + j, old.get("1"));
                }
            }
            s.close();
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:25,代码来源:TestMVStore.java

示例4: testConcurrentChangeAndGetVersion

import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testConcurrentChangeAndGetVersion() throws InterruptedException {
    for (int test = 0; test < 10; test++) {
        final MVStore s = new MVStore.Builder().
                autoCommitDisabled().open();
        s.setVersionsToKeep(10);
        final MVMap<Integer, Integer> m = s.openMap("data");
        m.put(1, 1);
        Task task = new Task() {
            @Override
            public void call() throws Exception {
                while (!stop) {
                    m.put(1, 1);
                    s.commit();
                }
            }
        };
        task.execute();
        Thread.sleep(1);
        for (int i = 0; i < 10000; i++) {
            if (task.isFinished()) {
                break;
            }
            for (int j = 0; j < 20; j++) {
                m.put(1, 1);
                s.commit();
            }
            s.setVersionsToKeep(15);
            long version = s.getCurrentVersion() - 1;
            try {
                m.openVersion(version);
            } catch (IllegalArgumentException e) {
                // ignore
            }
            s.setVersionsToKeep(20);
        }
        task.get();
        s.commit();
        s.close();
    }
    FileUtils.deleteRecursive("memFS:", false);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:42,代码来源:TestConcurrent.java

示例5: testExampleMvcc

import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testExampleMvcc() {
    String fileName = getBaseDir() + "/testExampleMvcc.h3";
    FileUtils.delete(fileName);

    // open the store (in-memory if fileName is null)
    MVStore s = MVStore.open(fileName);

    // create/get the map named "data"
    MVMap<Integer, String> map = s.openMap("data");

    // add some data
    map.put(1, "Hello");
    map.put(2, "World");

    // get the current version, for later use
    long oldVersion = s.getCurrentVersion();

    // from now on, the old version is read-only
    s.commit();

    // more changes, in the new version
    // changes can be rolled back if required
    // changes always go into "head" (the newest version)
    map.put(1, "Hi");
    map.remove(2);

    // access the old data (before the commit)
    MVMap<Integer, String> oldMap =
            map.openVersion(oldVersion);

    // print the old version (can be done
    // concurrently with further modifications)
    // this will print "Hello" and "World":
    // System.out.println(oldMap.get(1));
    assertEquals("Hello", oldMap.get(1));
    // System.out.println(oldMap.get(2));
    assertEquals("World", oldMap.get(2));

    // print the newest version ("Hi")
    // System.out.println(map.get(1));
    assertEquals("Hi", map.get(1));

    // close the store
    s.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:46,代码来源:TestMVStore.java

示例6: testVersion

import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testVersion() {
    String fileName = getBaseDir() + "/testVersion.h3";
    FileUtils.delete(fileName);
    MVStore s;
    s = openStore(fileName);
    s.setVersionsToKeep(100);
    s.setAutoCommitDelay(0);
    s.setRetentionTime(Integer.MAX_VALUE);
    MVMap<String, String> m = s.openMap("data");
    s.commit();
    long first = s.getCurrentVersion();
    m.put("0", "test");
    s.commit();
    m.put("1", "Hello");
    m.put("2", "World");
    for (int i = 10; i < 20; i++) {
        m.put("" + i, "data");
    }
    long old = s.getCurrentVersion();
    s.commit();
    m.put("1", "Hallo");
    m.put("2", "Welt");
    MVMap<String, String> mFirst;
    mFirst = m.openVersion(first);
    assertEquals(0, mFirst.size());
    MVMap<String, String> mOld;
    assertEquals("Hallo", m.get("1"));
    assertEquals("Welt", m.get("2"));
    mOld = m.openVersion(old);
    assertEquals("Hello", mOld.get("1"));
    assertEquals("World", mOld.get("2"));
    assertTrue(mOld.isReadOnly());
    s.getCurrentVersion();
    long old3 = s.commit();

    // the old version is still available
    assertEquals("Hello", mOld.get("1"));
    assertEquals("World", mOld.get("2"));

    mOld = m.openVersion(old3);
    assertEquals("Hallo", mOld.get("1"));
    assertEquals("Welt", mOld.get("2"));

    m.put("1",  "Hi");
    assertEquals("Welt", m.remove("2"));
    s.close();

    s = openStore(fileName);
    m = s.openMap("data");
    assertEquals("Hi", m.get("1"));
    assertEquals(null, m.get("2"));

    mOld = m.openVersion(old3);
    assertEquals("Hallo", mOld.get("1"));
    assertEquals("Welt", mOld.get("2"));

    try {
        m.openVersion(-3);
        fail();
    } catch (IllegalArgumentException e) {
        // expected
    }
    s.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:65,代码来源:TestMVStore.java


注:本文中的org.h2.mvstore.MVMap.openVersion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。