Search in sources :

Example 91 with Repository

use of javax.jcr.Repository in project jackrabbit-oak by apache.

the class ObservationQueueTest method heavyLoad.

@Test
public void heavyLoad() throws Throwable {
    List<Whiteboard> whiteboards = Lists.newArrayList(w1, w2);
    Iterator<Repository> repos = Iterators.cycle(r1, r2);
    AtomicLong commitCounter = new AtomicLong();
    for (int i = 0; i < NUM_WRITERS; i++) {
        Session s = loginUser(repos.next());
        Node n = s.getRootNode().addNode("session-" + i, "oak:Unstructured");
        s.save();
        writers.add(new Thread(new Writer(n, commitCounter)));
    }
    for (int i = 0; i < NUM_READERS; i++) {
        Session s = loginUser(repos.next());
        readers.add(new Thread(new Reader(s)));
    }
    AtomicInteger queueLength = new AtomicInteger();
    loggers.add(new Thread(new QueueLogger(whiteboards, queueLength, commitCounter)));
    for (int i = 0; i < NUM_OBSERVERS; i++) {
        Session s = loginUser(repos.next());
        observers.add(new Thread(new Observer(s, queueLength)));
    }
    for (Thread t : Iterables.concat(writers, readers, observers, loggers)) {
        t.start();
    }
    for (Thread t : Iterables.concat(writers, readers)) {
        t.join();
    }
    LOG.info("Writes stopped. Waiting for observers...");
    for (Thread t : Iterables.concat(observers, loggers)) {
        t.join();
    }
    for (Throwable t : exceptions) {
        throw t;
    }
}
Also used : Node(javax.jcr.Node) Repository(javax.jcr.Repository) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) AbstractClusterTest(org.apache.jackrabbit.oak.jcr.cluster.AbstractClusterTest) Test(org.junit.Test)

Example 92 with Repository

use of javax.jcr.Repository in project jackrabbit-oak by apache.

the class RepositoryTest method createRepository.

@Test
public void createRepository() throws RepositoryException {
    Repository repository = getRepository();
    assertNotNull(repository);
}
Also used : Repository(javax.jcr.Repository) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository) Test(org.junit.Test)

Example 93 with Repository

use of javax.jcr.Repository in project jackrabbit-oak by apache.

the class RepositorySidegradeTest method createSourceContent.

@SuppressWarnings("unchecked")
protected NodeStore createSourceContent() throws Exception {
    NodeStore source = SegmentNodeStoreBuilders.builder(new MemoryStore()).build();
    Repository repository = new Jcr(new Oak(source)).createRepository();
    Session session = repository.login(CREDENTIALS);
    try {
        JackrabbitWorkspace workspace = (JackrabbitWorkspace) session.getWorkspace();
        NamespaceRegistry registry = workspace.getNamespaceRegistry();
        registry.registerNamespace("test", "http://www.example.org/");
        NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
        NodeTypeTemplate template = nodeTypeManager.createNodeTypeTemplate();
        template.setName("test:unstructured");
        template.setDeclaredSuperTypeNames(new String[] { "nt:unstructured" });
        PropertyDefinitionTemplate pDef1 = nodeTypeManager.createPropertyDefinitionTemplate();
        pDef1.setName("defaultString");
        pDef1.setRequiredType(PropertyType.STRING);
        Value stringValue = session.getValueFactory().createValue("stringValue");
        pDef1.setDefaultValues(new Value[] { stringValue });
        template.getPropertyDefinitionTemplates().add(pDef1);
        PropertyDefinitionTemplate pDef2 = nodeTypeManager.createPropertyDefinitionTemplate();
        pDef2.setName("defaultPath");
        pDef2.setRequiredType(PropertyType.PATH);
        Value pathValue = session.getValueFactory().createValue("/jcr:path/nt:value", PropertyType.PATH);
        pDef2.setDefaultValues(new Value[] { pathValue });
        template.getPropertyDefinitionTemplates().add(pDef2);
        nodeTypeManager.registerNodeType(template, false);
        template = nodeTypeManager.createNodeTypeTemplate();
        template.setName("test:referenceable");
        template.setDeclaredSuperTypeNames(new String[] { "nt:unstructured", "mix:referenceable" });
        nodeTypeManager.registerNodeType(template, false);
        Node root = session.getRootNode();
        Node referenceable = root.addNode("referenceable", "test:unstructured");
        referenceable.addMixin(NodeType.MIX_REFERENCEABLE);
        Node versionable = root.addNode("versionable", NT_UNSTRUCTURED);
        versionable.addMixin(MIX_VERSIONABLE);
        Node child = versionable.addNode("child", "test:referenceable");
        child.addNode("child2", NT_UNSTRUCTURED);
        session.save();
        session.getWorkspace().getVersionManager().checkin("/versionable");
        Node properties = root.addNode("properties", "test:unstructured");
        properties.setProperty("boolean", true);
        Binary binary = session.getValueFactory().createBinary(new ByteArrayInputStream(BINARY));
        try {
            properties.setProperty("binary", binary);
        } finally {
            binary.dispose();
        }
        properties.setProperty("date", DATE);
        properties.setProperty("decimal", new BigDecimal(123));
        properties.setProperty("double", Math.PI);
        properties.setProperty("long", 9876543210L);
        properties.setProperty("reference", referenceable);
        properties.setProperty("weak_reference", session.getValueFactory().createValue(referenceable, true));
        properties.setProperty("mv_reference", new Value[] { session.getValueFactory().createValue(versionable, false) });
        properties.setProperty("mv_weak_reference", new Value[] { session.getValueFactory().createValue(versionable, true) });
        properties.setProperty("string", "test");
        properties.setProperty("multiple", "a,b,c".split(","));
        session.save();
        binary = properties.getProperty("binary").getBinary();
        try {
            InputStream stream = binary.getStream();
            try {
                for (byte aBINARY : BINARY) {
                    assertEquals(aBINARY, (byte) stream.read());
                }
                assertEquals(-1, stream.read());
            } finally {
                stream.close();
            }
        } finally {
            binary.dispose();
        }
        return source;
    } finally {
        session.logout();
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Node(javax.jcr.Node) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) BigDecimal(java.math.BigDecimal) MemoryStore(org.apache.jackrabbit.oak.segment.memory.MemoryStore) Repository(javax.jcr.Repository) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) NamespaceRegistry(javax.jcr.NamespaceRegistry) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) ByteArrayInputStream(java.io.ByteArrayInputStream) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) Oak(org.apache.jackrabbit.oak.Oak) Value(javax.jcr.Value) Binary(javax.jcr.Binary) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 94 with Repository

use of javax.jcr.Repository in project jackrabbit-oak by apache.

the class RepositoryFixture method createRepository.

private Repository createRepository() throws IOException {
    Oak oak = new Oak(getNodeStore());
    //Effectively disable async indexing
    oak.withAsyncIndexing("async", 3600);
    configureLuceneProvider(oak);
    Jcr jcr = new Jcr(oak);
    Repository repository = jcr.createRepository();
    whiteboard = oak.getWhiteboard();
    return repository;
}
Also used : Repository(javax.jcr.Repository) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository) Oak(org.apache.jackrabbit.oak.Oak) Jcr(org.apache.jackrabbit.oak.jcr.Jcr)

Example 95 with Repository

use of javax.jcr.Repository in project jackrabbit-oak by apache.

the class SimpleRepositoryFactoryTest method testRepositoryService.

@Test
public void testRepositoryService() throws Exception {
    Map<String, String> config = new HashMap<String, String>();
    config.put("org.apache.jackrabbit.repository.home", tmpFolder.getRoot().getAbsolutePath());
    config.put("org.apache.jackrabbit.oak.repository.configFile", path("oak-base-config.json") + "," + path("oak-tar-config.json"));
    Repository repository = JcrUtils.getRepository(config);
    assertNotNull(repository);
    ((JackrabbitRepository) repository).shutdown();
}
Also used : Repository(javax.jcr.Repository) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository) HashMap(java.util.HashMap) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository) Test(org.junit.Test)

Aggregations

Repository (javax.jcr.Repository)107 Session (javax.jcr.Session)31 RepositoryException (javax.jcr.RepositoryException)26 SimpleCredentials (javax.jcr.SimpleCredentials)15 Test (org.junit.Test)13 HashMap (java.util.HashMap)12 Node (javax.jcr.Node)12 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)10 SlingRepository (org.apache.sling.jcr.api.SlingRepository)10 JackrabbitRepository (org.apache.jackrabbit.api.JackrabbitRepository)9 Oak (org.apache.jackrabbit.oak.Oak)7 Jcr (org.apache.jackrabbit.oak.jcr.Jcr)7 IOException (java.io.IOException)6 Map (java.util.Map)6 InitialContext (javax.naming.InitialContext)6 NamingException (javax.naming.NamingException)6 ServletContext (javax.servlet.ServletContext)5 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)5 File (java.io.File)4 OutputStreamWriter (java.io.OutputStreamWriter)4