jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1365977 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/memory/ test/java/org/apache/jackrabbit/oak/plugins/memory/
Date Thu, 26 Jul 2012 13:16:11 GMT
Author: jukka
Date: Thu Jul 26 13:16:11 2012
New Revision: 1365977

URL: http://svn.apache.org/viewvc?rev=1365977&view=rev
Log:
OAK-167: Caching NodeStore implementation

Add test cases for basic MNSB state changes

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilderTest.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleanValue.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleanValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleanValue.java?rev=1365977&r1=1365976&r2=1365977&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleanValue.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleanValue.java
Thu Jul 26 13:16:11 2012
@@ -18,22 +18,32 @@ package org.apache.jackrabbit.oak.plugin
 
 import javax.jcr.PropertyType;
 
+import org.apache.jackrabbit.oak.api.CoreValue;
+
 abstract class BooleanValue extends MemoryValue {
 
-    public static final BooleanValue TRUE = new BooleanValue() {
+    public static final CoreValue TRUE = new BooleanValue() {
         @Override
         public boolean getBoolean() {
             return true;
         }
     };
 
-    public static final BooleanValue FALSE = new BooleanValue() {
+    public static final CoreValue FALSE = new BooleanValue() {
         @Override
         public boolean getBoolean() {
             return false;
         }
     };
 
+    public static CoreValue create(boolean value) {
+        if (value) {
+            return TRUE;
+        } else {
+            return FALSE;
+        }
+    }
+
     @Override
     public int getType() {
         return PropertyType.BOOLEAN;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java?rev=1365977&r1=1365976&r2=1365977&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java
Thu Jul 26 13:16:11 2012
@@ -18,24 +18,42 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import java.util.Collections;
 import java.util.List;
 
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.api.PropertyState;
 
 /**
  * Single-valued property state.
  */
 public class SinglePropertyState extends EmptyPropertyState {
 
+    public static PropertyState create(String name, boolean value) {
+        return new SinglePropertyState(name, BooleanValue.create(value));
+    }
+
+    public static PropertyState create(String name, double value) {
+        return new SinglePropertyState(name, new DoubleValue(value));
+    }
+
+    public static PropertyState create(String name, long value) {
+        return new SinglePropertyState(name, new LongValue(value));
+    }
+
+    public static PropertyState create(String name, String value) {
+        return new SinglePropertyState(name, new StringValue(value));
+    }
+
     private final CoreValue value;
 
     public SinglePropertyState(String name, CoreValue value) {
         super(name);
-        assert value != null;
-        this.value = value;
+        this.value = checkNotNull(value);
     }
 
     @Override

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilderTest.java?rev=1365977&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilderTest.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilderTest.java
Thu Jul 26 13:16:11 2012
@@ -0,0 +1,101 @@
+/*
+ * 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.plugins.memory;
+
+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 static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.fail;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStateBuilder;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class MemoryNodeStateBuilderTest {
+
+    private static final NodeState BASE = new MemoryNodeState(
+            ImmutableMap.<String, PropertyState>of(
+                    "a", SinglePropertyState.create("a", 1),
+                    "b", SinglePropertyState.create("b", 2),
+                    "c", SinglePropertyState.create("c", 3)),
+            ImmutableMap.of(
+                    "x", MemoryNodeState.EMPTY_NODE,
+                    "y", MemoryNodeState.EMPTY_NODE,
+                    "z", MemoryNodeState.EMPTY_NODE));
+
+    @Test
+    public void testConnectOnAddProperty() {
+        NodeStateBuilder root = new MemoryNodeStateBuilder(BASE);
+        NodeStateBuilder childA = root.getChildBuilder("x");
+        NodeStateBuilder childB = root.getChildBuilder("x");
+
+        assertNull(childA.getProperty("test"));
+        childB.setProperty("test", new StringValue("foo"));
+        assertNotNull(childA.getProperty("test"));
+    }
+
+    @Test
+    public void testConnectOnUpdateProperty() {
+        NodeStateBuilder root = new MemoryNodeStateBuilder(BASE);
+        NodeStateBuilder childA = root.getChildBuilder("x");
+        NodeStateBuilder childB = root.getChildBuilder("x");
+
+        childB.setProperty("test", new StringValue("foo"));
+        childA.setProperty("test", new StringValue("bar"));
+        assertEquals(
+                "bar",
+                childB.getProperty("test").getValue().getString());
+    }
+
+    @Test
+    public void testConnectOnRemoveProperty() {
+        NodeStateBuilder root = new MemoryNodeStateBuilder(BASE);
+        NodeStateBuilder childA = root.getChildBuilder("x");
+        NodeStateBuilder childB = root.getChildBuilder("x");
+
+        childB.setProperty("test", new StringValue("foo"));
+        childA.removeProperty("test");
+        assertNull(childB.getProperty("test"));
+    }
+
+    @Test
+    public void testConnectOnAddNode() {
+        NodeStateBuilder root = new MemoryNodeStateBuilder(BASE);
+        NodeStateBuilder childA = root.getChildBuilder("x");
+        NodeStateBuilder childB = root.getChildBuilder("x");
+
+        assertFalse(childA.hasChildNode("test"));
+        childB.setNode("test", MemoryNodeState.EMPTY_NODE);
+        assertTrue(childA.hasChildNode("test"));
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testConnectOnRemoveNode() {
+        NodeStateBuilder root = new MemoryNodeStateBuilder(BASE);
+        NodeStateBuilder child = root.getChildBuilder("x");
+
+        root.removeNode("x");
+        child.getChildNodeCount(); // should throw ISE
+        fail();
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message