You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2014/10/28 11:55:28 UTC
svn commit: r1634841 - in
/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster:
AbstractClusterTest.java ObservationTest.java
Author: mreutegg
Date: Tue Oct 28 10:55:28 2014
New Revision: 1634841
URL: http://svn.apache.org/r1634841
Log:
OAK-2232: External events incomplete
Ignored test to reproduce the issue
Added:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/ObservationTest.java (with props)
Modified:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/AbstractClusterTest.java
Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/AbstractClusterTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/AbstractClusterTest.java?rev=1634841&r1=1634840&r2=1634841&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/AbstractClusterTest.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/AbstractClusterTest.java Tue Oct 28 10:55:28 2014
@@ -68,6 +68,9 @@ public class AbstractClusterTest {
}
}
+ protected void prepareTestData(Session s) throws RepositoryException {
+ }
+
@Before
public void login() throws RepositoryException {
ns1 = fixture.createNodeStore(1);
@@ -75,12 +78,13 @@ public class AbstractClusterTest {
return;
}
r1 = new Jcr(ns1).createRepository();
+ s1 = r1.login(new SimpleCredentials("admin", "admin".toCharArray()));
+ prepareTestData(s1);
if (ns1 instanceof DocumentNodeStore) {
// make sure initial repository data is visible to
// other cluster nodes initialized later
((DocumentNodeStore) ns1).runBackgroundOperations();
}
- s1 = r1.login(new SimpleCredentials("admin", "admin".toCharArray()));
ns2 = fixture.createNodeStore(2);
r2 = new Jcr(ns2).createRepository();
s2 = r2.login(new SimpleCredentials("admin", "admin".toCharArray()));
Added: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/ObservationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/ObservationTest.java?rev=1634841&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/ObservationTest.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/ObservationTest.java Tue Oct 28 10:55:28 2014
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.jcr.cluster;
+
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.EventIterator;
+import javax.jcr.observation.EventListener;
+import javax.jcr.observation.ObservationManager;
+
+import org.apache.jackrabbit.api.observation.JackrabbitEvent;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Test for external events from another cluster node.
+ */
+@Ignore
+public class ObservationTest extends AbstractClusterTest {
+
+ private ScheduledExecutorService executor;
+
+ @Override
+ protected void prepareTestData(Session s) throws RepositoryException {
+ if (s.itemExists("/test")) {
+ s.getNode("/test").remove();
+ }
+ s.getRootNode().addNode("test", "oak:Unstructured");
+ s.save();
+ }
+
+ @Before
+ public void before() throws Exception {
+ executor = Executors.newScheduledThreadPool(4);
+ }
+
+ @After
+ public void after() {
+ executor.shutdown();
+ }
+
+ @Test
+ public void externalEvents() throws Throwable {
+ final List<Throwable> exceptions = Lists.newArrayList();
+ ObservationManager obsMgr = s1.getWorkspace().getObservationManager();
+ final AtomicLong localEvents = new AtomicLong();
+ final AtomicLong externalEvents = new AtomicLong();
+ EventListener listener = new EventListener() {
+ @Override
+ public void onEvent(EventIterator events) {
+ try {
+ while (events.hasNext()) {
+ Event event = events.nextEvent();
+ String external = "";
+ AtomicLong counter = localEvents;
+ if (event instanceof JackrabbitEvent) {
+ if (((JackrabbitEvent) event).isExternal()) {
+ external = " (external)";
+ counter = externalEvents;
+ }
+ }
+ System.out.println(event.getPath() + external);
+ counter.incrementAndGet();
+ }
+ } catch (RepositoryException e) {
+ exceptions.add(e);
+ }
+ }
+ };
+ obsMgr.addEventListener(listener, Event.NODE_ADDED, "/",
+ true, null, null, false);
+
+ Future f1 = executor.submit(new Worker(s1, exceptions));
+ Future f2 = executor.submit(new Worker(s2, exceptions));
+
+ f1.get();
+ f2.get();
+
+ Thread.sleep(10 * 1000);
+
+ System.out.println("local events: " + localEvents.get());
+ System.out.println("external events: " + externalEvents.get());
+
+ for (Throwable t : exceptions) {
+ throw t;
+ }
+ }
+
+ class Worker implements Runnable {
+
+ private Session s;
+ private List<Throwable> exceptions;
+
+ Worker(Session s, List<Throwable> exceptions) {
+ this.s = s;
+ this.exceptions = exceptions;
+ }
+
+ @Override
+ public void run() {
+ try {
+ Node test = s.getNode("/test");
+ for (int i = 0; i < 500; i++) {
+ test.addNode(UUID.randomUUID().toString());
+ s.save();
+ Thread.sleep((long) (Math.random() * 100));
+ }
+ } catch (Exception e) {
+ exceptions.add(e);
+ }
+ }
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/cluster/ObservationTest.java
------------------------------------------------------------------------------
svn:eol-style = native