jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1302981 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/mk/simple/ main/java/org/apache/jackrabbit/oak/kernel/ test/java/org/apache/jackrabbit/oak/kernel/
Date Tue, 20 Mar 2012 16:30:05 GMT
Author: jukka
Date: Tue Mar 20 16:30:04 2012
New Revision: 1302981

URL: http://svn.apache.org/viewvc?rev=1302981&view=rev
Log:
OAK-30: Strongly typed wrapper for the MicroKernel

Implement the tree interfaces from OAK-3 on top of the MK interface

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelChildNodeEntry.java
  (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
  (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
  (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
  (with props)
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java
  (with props)
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java?rev=1302981&r1=1302980&r2=1302981&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java
Tue Mar 20 16:30:04 2012
@@ -78,7 +78,7 @@ public class SimpleKernelImpl extends Mi
     private Server server;
     private boolean disposed;
 
-    private SimpleKernelImpl(String name) {
+    public SimpleKernelImpl(String name) {
         this.name = name;
         boolean startServer = false;
         if (name.startsWith("server:")) {

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelChildNodeEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelChildNodeEntry.java?rev=1302981&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelChildNodeEntry.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelChildNodeEntry.java
Tue Mar 20 16:30:04 2012
@@ -0,0 +1,45 @@
+/*
+ * 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.kernel;
+
+import org.apache.jackrabbit.mk.model.AbstractChildNodeEntry;
+import org.apache.jackrabbit.mk.model.NodeState;
+
+class KernelChildNodeEntry extends AbstractChildNodeEntry {
+
+    private final String name;
+
+    private final NodeState node;
+
+    public KernelChildNodeEntry(String name, NodeState node) {
+        this.name = name;
+        this.node = node;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public NodeState getNode() {
+        return node;
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelChildNodeEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java?rev=1302981&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
Tue Mar 20 16:30:04 2012
@@ -0,0 +1,204 @@
+/*
+ * 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.kernel;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.api.MicroKernelException;
+import org.apache.jackrabbit.mk.json.JsopReader;
+import org.apache.jackrabbit.mk.json.JsopTokenizer;
+import org.apache.jackrabbit.mk.model.AbstractNodeState;
+import org.apache.jackrabbit.mk.model.ChildNodeEntry;
+import org.apache.jackrabbit.mk.model.NodeState;
+import org.apache.jackrabbit.mk.model.PropertyState;
+
+/**
+ * Basic {@link NodeState} implementation based on the {@link MicroKernel}
+ * interface. This class makes an attempt to load data lazily.
+ */
+class KernelNodeState extends AbstractNodeState {
+
+    /**
+     * Maximum number of child nodes kept in memory.
+     */
+    static final int MAX_CHILD_NODE_NAMES = 1000;
+
+    private final MicroKernel kernel;
+
+    private final String path;
+
+    private final String revision;
+
+    private Map<String, PropertyState> properties = null;
+
+    private long childNodeCount = -1;
+
+    private Map<String, NodeState> childNodes = null; // TODO: WeakReference?
+
+    public KernelNodeState(MicroKernel kernel, String path, String revision) {
+        this.kernel = kernel;
+        this.path = path;
+        this.revision = revision;
+    }
+
+    private synchronized void init() {
+        if (properties == null) {
+            String json = kernel.getNodes(
+                    path, revision, 0, 0, MAX_CHILD_NODE_NAMES, null);
+
+            JsopReader reader = new JsopTokenizer(json);
+            reader.read('{');
+            properties = new LinkedHashMap<String, PropertyState>();
+            childNodes = new LinkedHashMap<String, NodeState>();
+            do {
+                String name = reader.readString();
+                reader.read(':');
+                if (":childNodeCount".equals(name)) {
+                    childNodeCount =
+                            Long.valueOf(reader.read(JsopTokenizer.NUMBER));
+                } else if (reader.matches('{')) {
+                    reader.read('}');
+                    String childPath = path + "/" + name;
+                    if ("/".equals(path)) {
+                        childPath = "/" + name;
+                    }
+                    childNodes.put(name, new KernelNodeState(
+                            kernel, childPath, revision));
+                } else if (reader.matches(JsopTokenizer.NUMBER)) {
+                    properties.put(name, new KernelPropertyState(
+                            name, reader.getToken()));
+                } else {
+                    properties.put(name, new KernelPropertyState(
+                            name, reader.readString()));
+                }
+            } while (reader.matches(','));
+            reader.read('}');
+            reader.read(JsopTokenizer.END);
+        }
+    }
+
+    @Override
+    public long getPropertyCount() {
+        init();
+        return properties.size();
+    }
+
+    @Override
+    public PropertyState getProperty(String name) {
+        init();
+        return properties.get(name);
+    }
+
+    @Override
+    public Iterable<? extends PropertyState> getProperties() {
+        init();
+        return properties.values();
+    }
+
+    @Override
+    public long getChildNodeCount() {
+        init();
+        return childNodeCount;
+    }
+
+    @Override
+    public NodeState getChildNode(String name) {
+        init();
+        NodeState child = childNodes.get(name);
+        if (child == null && childNodeCount > MAX_CHILD_NODE_NAMES) {
+            String childPath = getChildPath(name);
+            try {
+                kernel.getNodes(childPath, revision, 0, 0, 0, null);
+                child = new KernelNodeState(kernel, childPath, revision);
+            } catch (MicroKernelException e) {
+                // FIXME: Better way to determine whether a child node exists
+            }
+        }
+        return child;
+    }
+
+    @Override
+    public Iterable<? extends ChildNodeEntry> getChildNodeEntries(
+            long offset, int count) {
+        init();
+        if (count == -1) {
+            count = Integer.MAX_VALUE;
+            if (childNodeCount > count) {
+                throw new RuntimeException("Too many child nodes");
+            }
+        }
+
+        List<ChildNodeEntry> entries = new ArrayList<ChildNodeEntry>();
+
+        if (offset < childNodes.size()) {
+            Iterator<Map.Entry<String, NodeState>> iterator =
+                    childNodes.entrySet().iterator();
+            while (offset > 0) {
+                iterator.next();
+                offset--;
+            }
+            while (count > 0 && iterator.hasNext()) {
+                Map.Entry<String, NodeState> entry = iterator.next();
+                entries.add(new KernelChildNodeEntry(
+                        entry.getKey(), entry.getValue()));
+                count--;
+            }
+            offset = childNodes.size();
+        }
+
+        if (count > 0 && childNodeCount > MAX_CHILD_NODE_NAMES) {
+            String json = kernel.getNodes(
+                    path, revision, 0, offset, count, null);
+
+            JsopReader reader = new JsopTokenizer(json);
+            reader.read('{');
+            do {
+                String name = reader.readString();
+                reader.read(':');
+                if (reader.matches('{')) {
+                    reader.read('}');
+                    String childPath = getChildPath(name);
+                    NodeState child =
+                            new KernelNodeState(kernel, childPath, revision);
+                    entries.add(new KernelChildNodeEntry(name, child));
+                } else {
+                    reader.read();
+                }
+            } while (reader.matches(','));
+            reader.read('}');
+            reader.read(JsopTokenizer.END);
+        }
+
+        return entries;
+    }
+
+    private String getChildPath(String name) {
+        if ("/".equals(path)) {
+            return "/" + name;
+        } else {
+            return path + "/" + name;
+        }
+    }
+
+}
\ No newline at end of file

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java?rev=1302981&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
Tue Mar 20 16:30:04 2012
@@ -0,0 +1,52 @@
+/*
+ * 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.kernel;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.model.NodeBuilder;
+import org.apache.jackrabbit.mk.model.NodeState;
+import org.apache.jackrabbit.mk.model.NodeStore;
+
+/**
+ * {@link MicroKernel}-based {@link NodeStore} implementation.
+ */
+public class KernelNodeStore implements NodeStore {
+
+    private final MicroKernel kernel;
+
+    public KernelNodeStore(MicroKernel kernel) {
+        this.kernel = kernel;
+    }
+
+    @Override
+    public NodeState getRoot() {
+        return new KernelNodeState(kernel, "/", kernel.getHeadRevision());
+    }
+
+    @Override
+    public void setRoot(NodeState newRoot) {
+        throw new UnsupportedOperationException(); // FIXME
+    }
+
+    @Override
+    public NodeBuilder getNodeBuilder(NodeState base) {
+        throw new UnsupportedOperationException(); // FIXME
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java?rev=1302981&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
Tue Mar 20 16:30:04 2012
@@ -0,0 +1,44 @@
+/*
+ * 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.kernel;
+
+import org.apache.jackrabbit.mk.model.AbstractPropertyState;
+
+class KernelPropertyState extends AbstractPropertyState {
+
+    private final String name;
+
+    private final String value;
+
+    public KernelPropertyState(String name, String value) {
+        this.name = name;
+        this.value = value;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public String getEncodedValue() {
+        return value;
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java?rev=1302981&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java
Tue Mar 20 16:30:04 2012
@@ -0,0 +1,133 @@
+/*
+ * 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.kernel;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.model.ChildNodeEntry;
+import org.apache.jackrabbit.mk.model.NodeState;
+import org.apache.jackrabbit.mk.model.PropertyState;
+import org.apache.jackrabbit.mk.simple.SimpleKernelImpl;
+import org.junit.Before;
+import org.junit.Test;
+
+public class KernelNodeStateTest {
+
+    private NodeState state;
+
+    @Before
+    public void setUp() {
+        MicroKernel kernel = new SimpleKernelImpl("mem:KernelNodeStateTest");
+        String jsop =
+                "+\"test\":{\"a\":1,\"b\":2,\"c\":3,"
+                + "\"x\":{},\"y\":{},\"z\":{}}";
+        String revision = kernel.commit(
+                "/", jsop, kernel.getHeadRevision(), "test data");
+        state = new KernelNodeState(kernel, "/test", revision);
+    }
+
+    @Test
+    public void testGetPropertyCount() {
+        assertEquals(3, state.getPropertyCount());
+    }
+
+    @Test
+    public void testGetProperty() {
+        assertEquals("a", state.getProperty("a").getName());
+        assertEquals("1", state.getProperty("a").getEncodedValue());
+        assertEquals("b", state.getProperty("b").getName());
+        assertEquals("2", state.getProperty("b").getEncodedValue());
+        assertEquals("c", state.getProperty("c").getName());
+        assertEquals("3", state.getProperty("c").getEncodedValue());
+        assertNull(state.getProperty("x"));
+    }
+
+    @Test
+    public void testGetProperties() {
+        List<String> names = new ArrayList<String>();
+        List<String> values = new ArrayList<String>();
+        for (PropertyState property : state.getProperties()) {
+            names.add(property.getName());
+            values.add(property.getEncodedValue());
+        }
+        Collections.sort(names);
+        Collections.sort(values);
+        assertEquals(Arrays.asList("a", "b", "c"), names);
+        assertEquals(Arrays.asList("1", "2", "3"), values);
+    }
+
+    @Test
+    public void testGetChildNodeCount() {
+        assertEquals(3, state.getChildNodeCount());
+    }
+
+    @Test
+    public void testGetChildNode() {
+        assertNotNull(state.getChildNode("x"));
+        assertNotNull(state.getChildNode("y"));
+        assertNotNull(state.getChildNode("z"));
+        assertNull(state.getChildNode("a"));
+    }
+
+    @Test
+    public void testGetChildNodeEntries() {
+        List<String> names = new ArrayList<String>();
+        for (ChildNodeEntry entry : state.getChildNodeEntries(0, -1)) {
+            names.add(entry.getName());
+        }
+        Collections.sort(names);
+        assertEquals(Arrays.asList("x", "y", "z"), names);
+    }
+
+    @Test
+    public void testGetChildNodeEntriesWithOffset() {
+        List<String> names = new ArrayList<String>();
+        for (ChildNodeEntry entry : state.getChildNodeEntries(1, -1)) {
+            names.add(entry.getName());
+        }
+        Collections.sort(names);
+        assertEquals(Arrays.asList("y", "z"), names);
+
+        // Offset beyond the range
+        assertFalse(state.getChildNodeEntries(3, -1).iterator().hasNext());
+    }
+
+    @Test
+    public void testGetChildNodeEntriesWithCount() {
+        List<String> names = new ArrayList<String>();
+        for (ChildNodeEntry entry : state.getChildNodeEntries(0, 2)) {
+            names.add(entry.getName());
+        }
+        Collections.sort(names);
+        assertEquals(Arrays.asList("x", "y"), names);
+
+        // Zero count
+        assertFalse(state.getChildNodeEntries(0, 0).iterator().hasNext());
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java?rev=1302981&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java
Tue Mar 20 16:30:04 2012
@@ -0,0 +1,102 @@
+/*
+ * 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.kernel;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.model.ChildNodeEntry;
+import org.apache.jackrabbit.mk.model.NodeState;
+import org.apache.jackrabbit.mk.simple.SimpleKernelImpl;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LargeKernelNodeStateTest {
+
+    private final int N = KernelNodeState.MAX_CHILD_NODE_NAMES;
+
+    private NodeState state;
+
+    @Before
+    public void setUp() {
+        MicroKernel kernel =
+                new SimpleKernelImpl("mem:LargeKernelNodeStateTest");
+        StringBuilder jsop = new StringBuilder("+\"test\":{\"a\":1");
+        for (int i = 0; i <= N; i++) {
+            jsop.append(",\"x" + i + "\":{}");
+        }
+        jsop.append("}");
+        String revision = kernel.commit(
+                "/", jsop.toString(), kernel.getHeadRevision(), "test data");
+        state = new KernelNodeState(kernel, "/test", revision);
+    }
+
+    @Test
+    public void testGetChildNodeCount() {
+        assertEquals(N + 1, state.getChildNodeCount());
+    }
+
+    @Test
+    public void testGetChildNode() {
+        assertNotNull(state.getChildNode("x0"));
+        assertNotNull(state.getChildNode("x1"));
+        assertNotNull(state.getChildNode("x" + N));
+        assertNull(state.getChildNode("x" + (N + 1)));
+    }
+
+    @Test
+    @SuppressWarnings("unused")
+    public void testGetChildNodeEntries() {
+        long count = 0;
+        for (ChildNodeEntry entry : state.getChildNodeEntries(0, -1)) {
+            count++;
+        }
+        assertEquals(N + 1, count);
+    }
+
+    @Test
+    @SuppressWarnings("unused")
+    public void testGetChildNodeEntriesWithOffset() {
+        long count = 0;
+        for (ChildNodeEntry entry : state.getChildNodeEntries(N, -1)) {
+            count++;
+        }
+        assertEquals(1, count);
+
+        // Offset beyond the range
+        assertFalse(state.getChildNodeEntries(N + 1, -1).iterator().hasNext());
+    }
+
+    @Test
+    @SuppressWarnings("unused")
+    public void testGetChildNodeEntriesWithCount() {
+        long count = 0;
+        for (ChildNodeEntry entry : state.getChildNodeEntries(0, N + 1)) {
+            count++;
+        }
+        assertEquals(N + 1, count);
+
+        // Zero count
+        assertFalse(state.getChildNodeEntries(0, 0).iterator().hasNext());
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message