Search in sources :

Example 11 with MemoryStore

use of org.apache.jackrabbit.oak.segment.memory.MemoryStore in project jackrabbit-oak by apache.

the class SegmentIdTableBenchmark method test.

private static void test() throws IOException {
    long time;
    int repeat = 10000;
    int count = 10000;
    long[] array = new long[count];
    Random r = new Random(1);
    for (int i = 0; i < array.length; i++) {
        array[i] = r.nextLong();
    }
    time = System.currentTimeMillis();
    MemoryStore store = new MemoryStore();
    SegmentIdFactory maker = newSegmentIdMaker(store);
    final SegmentIdTable tbl = new SegmentIdTable();
    for (int i = 0; i < repeat; i++) {
        for (int j = 0; j < count; j++) {
            tbl.newSegmentId(j, array[j], maker);
        }
    }
    time = System.currentTimeMillis() - time;
    System.out.println("SegmentIdTable: " + time);
    time = System.currentTimeMillis();
    ConcurrentTable cm = new ConcurrentTable(store, 16 * 1024);
    for (int i = 0; i < repeat; i++) {
        for (int j = 0; j < count; j++) {
            cm.getSegmentId(j, array[j]);
        }
    }
    time = System.currentTimeMillis() - time;
    System.out.println("ConcurrentTable: " + time);
//        time = System.currentTimeMillis();
//        WeakHashMap<SegmentId, SegmentId> map = new WeakHashMap<SegmentId, SegmentId>(count);
//        for (int i = 0; i < repeat; i++) {
//            for (int j = 0; j < count; j++) {
//                SegmentId id = new SegmentId(tracker, j, j);
//                if (map.get(id) == null) {
//                    map.put(id, id);
//                }
//            }
//        }
//        time = System.currentTimeMillis() - time;
//        System.out.println("WeakHashMap: " + time);
}
Also used : MemoryStore(org.apache.jackrabbit.oak.segment.memory.MemoryStore) Random(java.util.Random)

Example 12 with MemoryStore

use of org.apache.jackrabbit.oak.segment.memory.MemoryStore in project jackrabbit-oak by apache.

the class MutableSegmentReferencesTest method shouldContainAddedSegment.

@Test
public void shouldContainAddedSegment() throws Exception {
    MemoryStore store = new MemoryStore();
    SegmentId id = store.getSegmentIdProvider().newDataSegmentId();
    MutableSegmentReferences table = new MutableSegmentReferences();
    assertFalse(table.contains(id));
    table.addOrReference(id);
    assertTrue(table.contains(id));
}
Also used : MemoryStore(org.apache.jackrabbit.oak.segment.memory.MemoryStore) Test(org.junit.Test)

Example 13 with MemoryStore

use of org.apache.jackrabbit.oak.segment.memory.MemoryStore in project jackrabbit-oak by apache.

the class MutableSegmentReferencesTest method shouldNotAddSameSegmentIdTwice.

@Test
public void shouldNotAddSameSegmentIdTwice() throws Exception {
    MemoryStore store = new MemoryStore();
    SegmentId id = store.getSegmentIdProvider().newDataSegmentId();
    MutableSegmentReferences table = new MutableSegmentReferences();
    int first = table.addOrReference(id);
    int second = table.addOrReference(id);
    assertEquals(first, second);
}
Also used : MemoryStore(org.apache.jackrabbit.oak.segment.memory.MemoryStore) Test(org.junit.Test)

Example 14 with MemoryStore

use of org.apache.jackrabbit.oak.segment.memory.MemoryStore in project jackrabbit-oak by apache.

the class BrokenVersionableTest method upgradeRepository.

@Before
public synchronized void upgradeRepository() throws Exception {
    targetNodeStore = SegmentNodeStoreBuilders.builder(new MemoryStore()).build();
    targetRepository = (RepositoryImpl) new Jcr(new Oak(targetNodeStore)).createRepository();
    NodeStore source = createSourceContent();
    RepositorySidegrade sidegrade = new RepositorySidegrade(source, targetNodeStore);
    sidegrade.setCopyOrphanedVersions(null);
    sidegrade.copy();
}
Also used : MemoryStore(org.apache.jackrabbit.oak.segment.memory.MemoryStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) SegmentNodeStore(org.apache.jackrabbit.oak.segment.SegmentNodeStore) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) Oak(org.apache.jackrabbit.oak.Oak) Before(org.junit.Before)

Example 15 with MemoryStore

use of org.apache.jackrabbit.oak.segment.memory.MemoryStore in project jackrabbit-oak by apache.

the class BrokenVersionableTest method createSourceContent.

private NodeStore createSourceContent() throws Exception {
    SegmentNodeStore source = SegmentNodeStoreBuilders.builder(new MemoryStore()).build();
    RepositoryImpl repository = (RepositoryImpl) new Jcr(new Oak(source)).createRepository();
    Session session = repository.login(CREDENTIALS);
    List<String> versionHistoryPaths = new ArrayList<String>();
    try {
        CndImporter.registerNodeTypes(new StringReader("<test = 'http://jackrabbit.apache.org/ns/test'>\n" + "[test:Versionable] > nt:unstructured, mix:versionable"), session);
        Node root = session.getRootNode();
        Node versionable1 = root.addNode("versionable1", NT_UNSTRUCTURED);
        versionable1.addMixin(MIX_VERSIONABLE);
        versionable1.addNode("child", NT_UNSTRUCTURED);
        Node versionable2 = root.addNode("versionable2", "test:Versionable");
        versionable2.addNode("child", NT_UNSTRUCTURED);
        session.save();
        VersionManager vMgr = session.getWorkspace().getVersionManager();
        vMgr.checkin("/versionable1");
        vMgr.checkin("/versionable2");
        versionHistoryPaths.add(vMgr.getVersionHistory("/versionable1").getPath());
        versionHistoryPaths.add(vMgr.getVersionHistory("/versionable2").getPath());
    } finally {
        session.logout();
        repository.shutdown();
    }
    // remove version history to corrupt the JCR repository structure
    NodeBuilder rootBuilder = source.getRoot().builder();
    for (String versionHistoryPath : versionHistoryPaths) {
        NodeStateTestUtils.createOrGetBuilder(rootBuilder, versionHistoryPath).remove();
    }
    source.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    return source;
}
Also used : Node(javax.jcr.Node) ArrayList(java.util.ArrayList) VersionManager(javax.jcr.version.VersionManager) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) MemoryStore(org.apache.jackrabbit.oak.segment.memory.MemoryStore) RepositoryImpl(org.apache.jackrabbit.oak.jcr.repository.RepositoryImpl) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) Oak(org.apache.jackrabbit.oak.Oak) StringReader(java.io.StringReader) SegmentNodeStore(org.apache.jackrabbit.oak.segment.SegmentNodeStore) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Aggregations

MemoryStore (org.apache.jackrabbit.oak.segment.memory.MemoryStore)28 Test (org.junit.Test)15 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)9 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)9 Before (org.junit.Before)7 Oak (org.apache.jackrabbit.oak.Oak)6 Jcr (org.apache.jackrabbit.oak.jcr.Jcr)6 SegmentNodeStore (org.apache.jackrabbit.oak.segment.SegmentNodeStore)4 Session (javax.jcr.Session)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Callable (java.util.concurrent.Callable)2 Semaphore (java.util.concurrent.Semaphore)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Node (javax.jcr.Node)2 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)2 InitialContent (org.apache.jackrabbit.oak.InitialContent)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1