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 fr...@apache.org on 2018/04/19 12:05:53 UTC

svn commit: r1829528 [2/2] - in /jackrabbit/oak/trunk/oak-segment-tar/src: main/java/org/apache/jackrabbit/oak/segment/ main/java/org/apache/jackrabbit/oak/segment/file/ main/java/org/apache/jackrabbit/oak/segment/file/proc/ main/java/org/apache/jackra...

Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/JournalNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/JournalNodeTest.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/JournalNodeTest.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/JournalNodeTest.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,66 @@
+/*
+ * 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.segment.file.proc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Set;
+
+import com.google.common.collect.Sets;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.junit.Test;
+
+public class JournalNodeTest {
+
+    @Test
+    public void shouldExposeCommitHandle() {
+        Backend backend = mock(Backend.class);
+        when(backend.commitExists("h")).thenReturn(true);
+
+        NodeState n  = new JournalNode(backend);
+
+        assertTrue(n.hasChildNode("h"));
+        assertTrue(n.getChildNode("h").exists());
+    }
+
+    @Test
+    public void shouldNotExposeNonExistingHandle() {
+        NodeState n = new JournalNode(mock(Backend.class));
+
+        assertFalse(n.hasChildNode("h"));
+        assertFalse(n.getChildNode("h").exists());
+    }
+
+    @Test
+    public void shouldExposeAllCommitHandles() {
+        Set<String> names = Sets.newHashSet("h1", "h2", "h3");
+
+        Backend backend = mock(Backend.class);
+        when(backend.getCommitHandles()).thenReturn(names);
+
+        assertEquals(names, Sets.newHashSet(new JournalNode(backend).getChildNodeNames()));
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/JournalNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/MissingSegmentTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/MissingSegmentTest.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/MissingSegmentTest.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/MissingSegmentTest.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,46 @@
+/*
+ * 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.segment.file.proc;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.junit.Test;
+
+public class MissingSegmentTest {
+
+    @Test
+    public void shouldHaveIdProperty() {
+        PropertyState property = new MissingSegmentNode("s").getProperty("id");
+
+        assertEquals(Type.STRING, property.getType());
+        assertEquals("s", property.getValue(Type.STRING));
+    }
+
+    @Test
+    public void shouldHaveExistsProperty() {
+        PropertyState property = new MissingSegmentNode("s").getProperty("exists");
+
+        assertEquals(Type.BOOLEAN, property.getType());
+        assertEquals(false, property.getValue(Type.BOOLEAN));
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/MissingSegmentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/ProcTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/ProcTest.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/ProcTest.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/ProcTest.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,46 @@
+/*
+ * 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.segment.file.proc;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.junit.Test;
+
+public class ProcTest {
+
+    @Test
+    public void procNodeShouldExposeStore() {
+        assertTrue(
+            Proc.of(mock(Backend.class))
+                .hasChildNode("store")
+        );
+    }
+
+    @Test
+    public void procShouldExposeJournal() {
+        assertTrue(
+            Proc.of(mock(Backend.class))
+                .hasChildNode("journal")
+        );
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/ProcTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/RecordNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/RecordNodeTest.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/RecordNodeTest.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/RecordNodeTest.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,107 @@
+/*
+ * 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.segment.file.proc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Optional;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend.Record;
+import org.junit.Test;
+
+public class RecordNodeTest {
+
+    private Record mockRecord() {
+        Record record = mock(Record.class);
+        when(record.getSegmentId()).thenReturn("");
+        when(record.getType()).thenReturn("");
+        return record;
+    }
+
+    @Test
+    public void shouldHaveNumberProperty() {
+        Record record = mockRecord();
+        when(record.getNumber()).thenReturn(1);
+
+        PropertyState p = new RecordNode(record).getProperty("number");
+
+        assertEquals(Type.LONG, p.getType());
+        assertEquals(1, p.getValue(Type.LONG).intValue());
+    }
+
+    @Test
+    public void shouldHaveOffsetProperty() {
+        Record record = mockRecord();
+        when(record.getOffset()).thenReturn(2);
+
+        PropertyState p = new RecordNode(record).getProperty("offset");
+
+        assertEquals(Type.LONG, p.getType());
+        assertEquals(2, p.getValue(Type.LONG).intValue());
+    }
+
+    @Test
+    public void shouldHaveTypeProperty() {
+        Record record = mockRecord();
+        when(record.getType()).thenReturn("t");
+
+        PropertyState p = new RecordNode(record).getProperty("type");
+
+        assertEquals(Type.STRING, p.getType());
+        assertEquals("t", p.getValue(Type.STRING));
+    }
+
+    @Test
+    public void shouldHaveSegmentIdProperty() {
+        Record record = mockRecord();
+        when(record.getSegmentId()).thenReturn("s");
+
+        PropertyState p = new RecordNode(record).getProperty("segmentId");
+
+        assertEquals(Type.STRING, p.getType());
+        assertEquals("s", p.getValue(Type.STRING));
+    }
+
+    @Test
+    public void shouldHaveAddressProperty() {
+        Record record = mockRecord();
+        when(record.getAddress()).thenReturn(1);
+
+        PropertyState p = new RecordNode(record).getProperty("address");
+
+        assertEquals(Type.LONG, p.getType());
+        assertEquals(1, p.getValue(Type.LONG).intValue());
+    }
+
+    @Test
+    public void mightHaveRootChild() {
+        Record record = mockRecord();
+        when(record.getRoot()).thenReturn(Optional.of(EmptyNodeState.EMPTY_NODE));
+
+        assertTrue(new RecordNode(record).hasChildNode("root"));
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/RecordNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/RecordsNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/RecordsNodeTest.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/RecordsNodeTest.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/RecordsNodeTest.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,74 @@
+/*
+ * 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.segment.file.proc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import com.google.common.collect.Sets;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend.Record;
+import org.junit.Test;
+
+public class RecordsNodeTest {
+
+    @Test
+    public void shouldExposeRecordNumber() {
+        Record record = mock(Record.class);
+        when(record.getNumber()).thenReturn(1);
+
+        Backend backend = mock(Backend.class);
+        when(backend.getSegmentRecords("s")).thenReturn(Optional.of(Collections.singletonList(record)));
+
+        assertTrue(new RecordsNode(backend, "s").hasChildNode("1"));
+    }
+
+    @Test
+    public void shouldExposeAllRecordNumbers() {
+        Set<Integer> numbers = Sets.newHashSet(1, 2, 3);
+
+        Set<Record> records = numbers.stream()
+            .map(RecordsNodeTest::newRecord)
+            .collect(Collectors.toSet());
+
+        Backend backend = mock(Backend.class);
+        when(backend.getSegmentRecords("s")).thenReturn(Optional.of(records));
+
+        Set<String> names = numbers.stream()
+            .map(Object::toString)
+            .collect(Collectors.toSet());
+
+        assertEquals(names, Sets.newHashSet(new RecordsNode(backend, "s").getChildNodeNames()));
+    }
+
+    private static Record newRecord(Integer number) {
+        Record record = mock(Record.class);
+        when(record.getNumber()).thenReturn(number);
+        return record;
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/RecordsNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/ReferencesNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/ReferencesNodeTest.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/ReferencesNodeTest.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/ReferencesNodeTest.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,64 @@
+/*
+ * 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.segment.file.proc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend.Segment;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.junit.Test;
+
+public class ReferencesNodeTest {
+
+    @Test
+    public void shouldExposeReference() {
+        List<String> references = Collections.singletonList("u");
+
+        Backend backend = mock(Backend.class);
+        when(backend.getSegmentReferences("s")).thenReturn(Optional.of(references));
+
+        assertTrue(new ReferencesNode(backend, "s").hasChildNode("u"));
+    }
+
+    @Test
+    public void shouldExposeAllReferences() {
+        List<String> references = Arrays.asList("u", "v", "w");
+
+        Backend backend = mock(Backend.class);
+        when(backend.getSegmentReferences("s")).thenReturn(Optional.of(references));
+
+        assertEquals(Sets.newHashSet(references), Sets.newHashSet(new ReferencesNode(backend, "s").getChildNodeNames()));
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/ReferencesNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentNodeTest.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentNodeTest.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentNodeTest.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,64 @@
+/*
+ * 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.segment.file.proc;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Optional;
+
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend.Segment;
+import org.junit.Test;
+
+public class SegmentNodeTest {
+
+    @Test
+    public void shouldHandleMissingSegment() {
+        Backend backend = mock(Backend.class);
+        when(backend.getSegment("s")).thenReturn(Optional.empty());
+
+        assertEquals(MissingSegmentNode.class, SegmentNode.newSegmentNode(backend, "s").getClass());
+    }
+
+    @Test
+    public void shouldHandleDataSegment() {
+        Segment segment = mock(Segment.class);
+        when(segment.isDataSegment()).thenReturn(true);
+
+        Backend backend = mock(Backend.class);
+        when(backend.getSegment("s")).thenReturn(Optional.of(segment));
+
+        assertEquals(DataSegmentNode.class, SegmentNode.newSegmentNode(backend, "s").getClass());
+    }
+
+    @Test
+    public void shouldHandleBulkSegment() {
+        Segment segment = mock(Segment.class);
+        when(segment.isDataSegment()).thenReturn(false);
+
+        Backend backend = mock(Backend.class);
+        when(backend.getSegment("s")).thenReturn(Optional.of(segment));
+
+        assertEquals(BulkSegmentNode.class, SegmentNode.newSegmentNode(backend, "s").getClass());
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/StoreNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/StoreNodeTest.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/StoreNodeTest.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/StoreNodeTest.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,66 @@
+/*
+ * 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.segment.file.proc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Set;
+
+import com.google.common.collect.Sets;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.junit.Test;
+
+public class StoreNodeTest {
+
+    @Test
+    public void shouldExposeAllTarNames() {
+        Set<String> names = Sets.newHashSet("t1", "t2", "t3");
+
+        Backend backend = mock(Backend.class);
+        when(backend.getTarNames()).thenReturn(names);
+
+        assertEquals(names, Sets.newHashSet(new StoreNode(backend).getChildNodeNames()));
+    }
+
+    @Test
+    public void shouldExposeTarName() {
+        Backend backend = mock(Backend.class);
+        when(backend.tarExists("t")).thenReturn(true);
+
+        NodeState n = new StoreNode(backend);
+
+        assertTrue(n.hasChildNode("t"));
+        assertTrue(n.getChildNode("t").exists());
+    }
+
+    @Test
+    public void shouldNotExposeNonExistingTarName() {
+        NodeState n = new StoreNode(mock(Backend.class));
+
+        assertFalse(n.hasChildNode("t"));
+        assertFalse(n.getChildNode("t").exists());
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/StoreNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/TarNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/TarNodeTest.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/TarNodeTest.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/TarNodeTest.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,95 @@
+/*
+ * 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.segment.file.proc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Optional;
+import java.util.Set;
+
+import com.google.common.collect.Sets;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend.Segment;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.junit.Test;
+
+public class TarNodeTest {
+
+    @Test
+    public void shouldExposeSegmentId() {
+        Segment segment = mock(Segment.class);
+
+        Backend backend = mock(Backend.class);
+        when(backend.segmentExists("t", "s")).thenReturn(true);
+        when(backend.getSegment("s")).thenReturn(Optional.of(segment));
+
+        NodeState n = new TarNode(backend, "t");
+
+        assertTrue(n.hasChildNode("s"));
+        assertTrue(n.getChildNode("s").exists());
+    }
+
+    @Test
+    public void shouldNotExposeNonExistingSegmentId() {
+        NodeState n = new TarNode(mock(Backend.class), "t");
+
+        assertFalse(n.hasChildNode("s"));
+        assertFalse(n.getChildNode("s").exists());
+    }
+
+    @Test
+    public void shouldExposeAllSegmentIds() {
+        Set<String> names = Sets.newHashSet("s1", "s2", "s3");
+
+        Backend backend = mock(Backend.class);
+        when(backend.getSegmentIds("t")).thenReturn(names);
+
+        assertEquals(names, Sets.newHashSet(new TarNode(backend, "t").getChildNodeNames()));
+    }
+
+    @Test
+    public void shouldHaveNameProperty() {
+        Backend backend = mock(Backend.class);
+        when(backend.getTarSize("t")).thenReturn(Optional.empty());
+
+        PropertyState property = new TarNode(backend, "t").getProperty("name");
+
+        assertEquals(Type.STRING, property.getType());
+        assertEquals("t", property.getValue(Type.STRING));
+    }
+
+    @Test
+    public void shouldHaveSizeProperty() {
+        Backend backend = mock(Backend.class);
+        when(backend.getTarSize("t")).thenReturn(Optional.of(1L));
+
+        PropertyState property = new TarNode(backend, "t").getProperty("size");
+
+        assertEquals(Type.LONG, property.getType());
+        assertEquals(1L, property.getValue(Type.LONG).longValue());
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/TarNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native