Repository: atlas Updated Branches: refs/heads/master 8b65aed03 -> effb7537f
http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/test/java/com/thinkaurelius/titan/diskstorage/hbase/HBaseKeyColumnValueStoreTest.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/test/java/com/thinkaurelius/titan/diskstorage/hbase/HBaseKeyColumnValueStoreTest.java b/graphdb/titan0/src/test/java/com/thinkaurelius/titan/diskstorage/hbase/HBaseKeyColumnValueStoreTest.java deleted file mode 100644 index 21087a5..0000000 --- a/graphdb/titan0/src/test/java/com/thinkaurelius/titan/diskstorage/hbase/HBaseKeyColumnValueStoreTest.java +++ /dev/null @@ -1,139 +0,0 @@ -/** - * 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 com.thinkaurelius.titan.diskstorage.hbase; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.testng.Assert.fail; - -import java.util.concurrent.TimeUnit; - -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import com.thinkaurelius.titan.diskstorage.BackendException; -import com.thinkaurelius.titan.diskstorage.EntryMetaData; -import com.thinkaurelius.titan.diskstorage.StaticBuffer; -import com.thinkaurelius.titan.diskstorage.configuration.Configuration; -import com.thinkaurelius.titan.diskstorage.locking.LocalLockMediator; -import com.thinkaurelius.titan.diskstorage.locking.PermanentLockingException; -import com.thinkaurelius.titan.diskstorage.util.KeyColumn; -import com.thinkaurelius.titan.diskstorage.util.time.StandardDuration; -import com.thinkaurelius.titan.diskstorage.util.time.Timepoint; -import com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration; - -public class HBaseKeyColumnValueStoreTest { - - @Mock - HBaseStoreManager storeManager; - - @Mock - ConnectionMask connectionMask; - - @Mock - LocalLockMediator localLockMediator; - - @Mock - StaticBuffer key; - - @Mock - StaticBuffer column; - - @Mock - StaticBuffer expectedValue; - - @Mock - HBaseTransaction transaction; - - @Mock - Configuration storageConfig; - - @BeforeMethod - public void setup() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void shouldSucceedInLockingIfLockMediatorSucceeds() throws BackendException { - - when(storeManager.getMetaDataSchema("hbase")).thenReturn(new EntryMetaData[] {EntryMetaData.TIMESTAMP}); - when(storeManager.getStorageConfig()).thenReturn(storageConfig); - when(storageConfig.get(GraphDatabaseConfiguration.LOCK_EXPIRE)).thenReturn( - new StandardDuration(300L, TimeUnit.MILLISECONDS)); - when(storageConfig.get(GraphDatabaseConfiguration.LOCK_WAIT)).thenReturn( - new StandardDuration(10L, TimeUnit.MILLISECONDS)); - when(storageConfig.get(GraphDatabaseConfiguration.LOCK_RETRY)).thenReturn(3); - KeyColumn lockID = new KeyColumn(key, column); - when(localLockMediator.lock(eq(lockID), eq(transaction), any(Timepoint.class))). - thenReturn(true); - - HBaseKeyColumnValueStore hBaseKeyColumnValueStore = - new HBaseKeyColumnValueStore(storeManager, connectionMask, "titan", "e", "hbase", localLockMediator); - hBaseKeyColumnValueStore.acquireLock(key, column, expectedValue, transaction); - - verify(transaction).updateLocks(lockID, expectedValue); - verify(localLockMediator, times(1)).lock(eq(lockID), eq(transaction), any(Timepoint.class)); - } - - @Test - public void shouldRetryRightNumberOfTimesIfLockMediationFails() throws BackendException { - when(storeManager.getMetaDataSchema("hbase")).thenReturn(new EntryMetaData[] {EntryMetaData.TIMESTAMP}); - when(storeManager.getStorageConfig()).thenReturn(storageConfig); - when(storageConfig.get(GraphDatabaseConfiguration.LOCK_EXPIRE)).thenReturn( - new StandardDuration(300L, TimeUnit.MILLISECONDS)); - when(storageConfig.get(GraphDatabaseConfiguration.LOCK_WAIT)).thenReturn( - new StandardDuration(10L, TimeUnit.MILLISECONDS)); - when(storageConfig.get(GraphDatabaseConfiguration.LOCK_RETRY)).thenReturn(3); - KeyColumn lockID = new KeyColumn(key, column); - when(localLockMediator.lock(eq(lockID), eq(transaction), any(Timepoint.class))). - thenReturn(false).thenReturn(false).thenReturn(true); - - HBaseKeyColumnValueStore hBaseKeyColumnValueStore = - new HBaseKeyColumnValueStore(storeManager, connectionMask, "titan", "e", "hbase", localLockMediator); - hBaseKeyColumnValueStore.acquireLock(key, column, expectedValue, transaction); - - verify(transaction).updateLocks(lockID, expectedValue); - verify(localLockMediator, times(3)).lock(eq(lockID), eq(transaction), any(Timepoint.class)); - } - - @Test(expectedExceptions = PermanentLockingException.class) - public void shouldThrowExceptionAfterConfiguredRetriesIfLockMediationFails() throws BackendException { - when(storeManager.getMetaDataSchema("hbase")).thenReturn(new EntryMetaData[] {EntryMetaData.TIMESTAMP}); - when(storeManager.getStorageConfig()).thenReturn(storageConfig); - when(storageConfig.get(GraphDatabaseConfiguration.LOCK_EXPIRE)).thenReturn( - new StandardDuration(300L, TimeUnit.MILLISECONDS)); - when(storageConfig.get(GraphDatabaseConfiguration.LOCK_WAIT)).thenReturn( - new StandardDuration(10L, TimeUnit.MILLISECONDS)); - when(storageConfig.get(GraphDatabaseConfiguration.LOCK_RETRY)).thenReturn(3); - KeyColumn lockID = new KeyColumn(key, column); - when(localLockMediator.lock(eq(lockID), eq(transaction), any(Timepoint.class))). - thenReturn(false).thenReturn(false).thenReturn(false); - - HBaseKeyColumnValueStore hBaseKeyColumnValueStore = - new HBaseKeyColumnValueStore(storeManager, connectionMask, "titan", "e", "hbase", localLockMediator); - hBaseKeyColumnValueStore.acquireLock(key, column, expectedValue, transaction); - - fail("Should fail as lock could not be acquired after 3 retries."); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/test/java/com/thinkaurelius/titan/diskstorage/locking/LocalLockMediatorTest.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/test/java/com/thinkaurelius/titan/diskstorage/locking/LocalLockMediatorTest.java b/graphdb/titan0/src/test/java/com/thinkaurelius/titan/diskstorage/locking/LocalLockMediatorTest.java deleted file mode 100644 index b3cf4f7..0000000 --- a/graphdb/titan0/src/test/java/com/thinkaurelius/titan/diskstorage/locking/LocalLockMediatorTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2013 Aurelius LLC - * Licensed 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 com.thinkaurelius.titan.diskstorage.locking; - -import com.thinkaurelius.titan.diskstorage.hbase.HBaseTransaction; -import com.thinkaurelius.titan.diskstorage.util.time.TimestampProvider; -import com.thinkaurelius.titan.diskstorage.util.time.Timestamps; -import com.thinkaurelius.titan.diskstorage.StaticBuffer; -import com.thinkaurelius.titan.diskstorage.util.KeyColumn; -import com.thinkaurelius.titan.diskstorage.util.StaticArrayBuffer; -import org.mockito.Mockito; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.util.concurrent.TimeUnit; - -public class LocalLockMediatorTest { - - private static final String LOCK_NAMESPACE = "test"; - private static final StaticBuffer LOCK_ROW = StaticArrayBuffer.of(new byte[]{1}); - private static final StaticBuffer LOCK_COL = StaticArrayBuffer.of(new byte[]{1}); - private static final KeyColumn kc = new KeyColumn(LOCK_ROW, LOCK_COL); - private static final HBaseTransaction mockTx1 = Mockito.mock(HBaseTransaction.class); - private static final HBaseTransaction mockTx2 = Mockito.mock(HBaseTransaction.class); - - @Test - public void testLock() throws InterruptedException { - TimestampProvider times = Timestamps.MICRO; - LocalLockMediator<HBaseTransaction> llm = - new LocalLockMediator<>(LOCK_NAMESPACE, times); - - //Expire immediately - Assert.assertTrue(llm.lock(kc, mockTx1, times.getTime(0, TimeUnit.NANOSECONDS))); - Assert.assertTrue(llm.lock(kc, mockTx2, times.getTime(Long.MAX_VALUE, TimeUnit.NANOSECONDS))); - - llm = new LocalLockMediator<>(LOCK_NAMESPACE, times); - - //Expire later - Assert.assertTrue(llm.lock(kc, mockTx1, times.getTime(Long.MAX_VALUE, TimeUnit.NANOSECONDS))); - //So second lock should fail on same keyCol - Assert.assertFalse(llm.lock(kc, mockTx2, times.getTime(Long.MAX_VALUE, TimeUnit.NANOSECONDS))); - - //Unlock - Assert.assertTrue(llm.unlock(kc, mockTx1)); - //Now locking should succeed - Assert.assertTrue(llm.lock(kc, mockTx2, times.getTime(Long.MAX_VALUE, TimeUnit.NANOSECONDS))); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/test/java/org/apache/atlas/repository/graphdb/titan0/AbstractGraphDatabaseTest.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/test/java/org/apache/atlas/repository/graphdb/titan0/AbstractGraphDatabaseTest.java b/graphdb/titan0/src/test/java/org/apache/atlas/repository/graphdb/titan0/AbstractGraphDatabaseTest.java deleted file mode 100644 index 513813d..0000000 --- a/graphdb/titan0/src/test/java/org/apache/atlas/repository/graphdb/titan0/AbstractGraphDatabaseTest.java +++ /dev/null @@ -1,188 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; - -import org.apache.atlas.graph.GraphSandboxUtil; -import org.apache.atlas.repository.Constants; -import org.apache.atlas.repository.graphdb.AtlasCardinality; -import org.apache.atlas.repository.graphdb.AtlasGraph; -import org.apache.atlas.repository.graphdb.AtlasGraphManagement; -import org.apache.atlas.repository.graphdb.AtlasPropertyKey; -import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * - */ -public abstract class AbstractGraphDatabaseTest { - - protected static final String WEIGHT_PROPERTY = "weight"; - protected static final String TRAIT_NAMES = Constants.TRAIT_NAMES_PROPERTY_KEY; - protected static final String TYPE_PROPERTY_NAME = "__type"; - protected static final String TYPESYSTEM = "TYPESYSTEM"; - - private static final String BACKING_INDEX_NAME = "backing"; - - private AtlasGraph<?, ?> graph = null; - - @BeforeClass - public static void createIndices() { - GraphSandboxUtil.create(); - - Titan0GraphDatabase db = new Titan0GraphDatabase(); - AtlasGraphManagement mgmt = db.getGraph().getManagementSystem(); - - if (mgmt.getGraphIndex(BACKING_INDEX_NAME) == null) { - mgmt.createVertexMixedIndex(BACKING_INDEX_NAME, Constants.BACKING_INDEX, Collections.emptyList()); - } - mgmt.makePropertyKey("age13", Integer.class, AtlasCardinality.SINGLE); - - createIndices(mgmt, "name", String.class, false, AtlasCardinality.SINGLE); - createIndices(mgmt, WEIGHT_PROPERTY, Integer.class, false, AtlasCardinality.SINGLE); - createIndices(mgmt, "size15", String.class, false, AtlasCardinality.SINGLE); - createIndices(mgmt, "typeName", String.class, false, AtlasCardinality.SINGLE); - createIndices(mgmt, "__type", String.class, false, AtlasCardinality.SINGLE); - createIndices(mgmt, Constants.GUID_PROPERTY_KEY, String.class, true, AtlasCardinality.SINGLE); - createIndices(mgmt, Constants.TRAIT_NAMES_PROPERTY_KEY, String.class, false, AtlasCardinality.SET); - createIndices(mgmt, Constants.SUPER_TYPES_PROPERTY_KEY, String.class, false, AtlasCardinality.SET); - mgmt.commit(); - } - - @AfterMethod - public void commitGraph() { - //force any pending actions to be committed so we can be sure they don't cause errors. - pushChangesAndFlushCache(); - getGraph().commit(); - } - - @AfterClass - public static void cleanUp() { - Titan0Graph graph = new Titan0Graph(); - graph.clear(); - - } - - protected <V, E> void pushChangesAndFlushCache() { - getGraph().commit(); - } - - private static void createIndices(AtlasGraphManagement management, String propertyName, Class propertyClass, - boolean isUnique, AtlasCardinality cardinality) { - - if (management.containsPropertyKey(propertyName)) { - //index was already created - return; - } - - AtlasPropertyKey key = management.makePropertyKey(propertyName, propertyClass, cardinality); - try { - if (propertyClass != Integer.class) { - management.addMixedIndex(BACKING_INDEX_NAME, key); - } - } catch(Throwable t) { - //ok - t.printStackTrace(); - } - try { - management.createVertexCompositeIndex(propertyName, isUnique, Collections.singletonList(key)); - - } catch(Throwable t) { - //ok - t.printStackTrace(); - } - - - } - - - - - protected final <V, E> AtlasGraph<V, E> getGraph() { - if (graph == null) { - graph = new Titan0Graph(); - } - return (AtlasGraph<V, E>)graph; - } - - protected Titan0Graph getTitan0Graph() { - AtlasGraph g = getGraph(); - return (Titan0Graph)g; - } - - - protected List<AtlasVertex> newVertices = new ArrayList<>(); - - protected final <V, E> AtlasVertex<V, E> createVertex(AtlasGraph<V, E> theGraph) { - AtlasVertex<V, E> vertex = theGraph.addVertex(); - newVertices.add(vertex); - return vertex; - } - - @AfterMethod - public void removeVertices() { - for(AtlasVertex vertex : newVertices) { - if (vertex.exists()) { - getGraph().removeVertex(vertex); - } - } - getGraph().commit(); - newVertices.clear(); - } - protected void runSynchronouslyInNewThread(final Runnable r) throws Throwable { - - RunnableWrapper wrapper = new RunnableWrapper(r); - Thread th = new Thread(wrapper); - th.start(); - th.join(); - Throwable ex = wrapper.getExceptionThrown(); - if (ex != null) { - throw ex; - } - } - - private static final class RunnableWrapper implements Runnable { - private final Runnable r; - private Throwable exceptionThrown = null; - - private RunnableWrapper(Runnable r) { - this.r = r; - } - - @Override - public void run() { - try { - r.run(); - } catch(Throwable e) { - exceptionThrown = e; - } - - } - - public Throwable getExceptionThrown() { - return exceptionThrown; - } - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/test/java/org/apache/atlas/repository/graphdb/titan0/GraphQueryTest.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/test/java/org/apache/atlas/repository/graphdb/titan0/GraphQueryTest.java b/graphdb/titan0/src/test/java/org/apache/atlas/repository/graphdb/titan0/GraphQueryTest.java deleted file mode 100644 index 5e02205..0000000 --- a/graphdb/titan0/src/test/java/org/apache/atlas/repository/graphdb/titan0/GraphQueryTest.java +++ /dev/null @@ -1,451 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; - - - -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertTrue; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import org.apache.atlas.AtlasException; -import org.apache.atlas.repository.graphdb.AtlasGraph; -import org.apache.atlas.repository.graphdb.AtlasGraphQuery; -import org.apache.atlas.repository.graphdb.AtlasGraphQuery.ComparisionOperator; -import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; - - - -/** - * Tests for Titan0GraphQuery. - */ -@Test -public class GraphQueryTest extends AbstractGraphDatabaseTest { - - - @Test - public <V, E> void testQueryThatCannotRunInMemory() throws AtlasException { - AtlasGraph<V, E> graph = getGraph(); - AtlasVertex<V, E> v1 = createVertex(graph); - - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - - AtlasVertex<V, E> v2 = createVertex(graph); - v2.setProperty("name", "Fred"); - - AtlasVertex<V, E> v3 = createVertex(graph); - v3.setProperty("size15", "15"); - - graph.commit(); - - AtlasVertex<V, E> v4 = createVertex(graph); - v4.setProperty("name", "Fred"); - v4.setProperty("size15", "15"); - - AtlasGraphQuery q = graph.query(); - q.has("name", ComparisionOperator.NOT_EQUAL, "George"); - q.has("size15", "15"); - graph.commit(); - pause(); //pause to let the index get updated - - assertQueryMatches(q, v1, v3, v4); - - } - - @Test - public void testCombinationOfAndsAndOrs() throws AtlasException { - Titan0Graph graph = getTitan0Graph(); - - AtlasVertex<Titan0Vertex, Titan0Edge> v1 = createVertex(graph); - - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - v1.setProperty("typeName", "Person"); - - AtlasVertex<Titan0Vertex, Titan0Edge> v2 = createVertex(graph); - v2.setProperty("name", "George"); - v2.setProperty("size15", "16"); - v2.setProperty("typeName", "Person"); - - AtlasVertex<Titan0Vertex, Titan0Edge> v3 = createVertex(graph); - v3.setProperty("name", "Jane"); - v3.setProperty("size15", "17"); - v3.setProperty("typeName", "Person"); - - - AtlasVertex<Titan0Vertex, Titan0Edge> v4 = createVertex(graph); - v4.setProperty("name", "Bob"); - v4.setProperty("size15", "18"); - v4.setProperty("typeName", "Person"); - - AtlasVertex<Titan0Vertex, Titan0Edge> v5 = createVertex(graph); - v5.setProperty("name", "Julia"); - v5.setProperty("size15", "19"); - v5.setProperty("typeName", "Manager"); - - - AtlasGraphQuery q = getGraphQuery(); - q.has("typeName", "Person"); - //initially match - AtlasGraphQuery inner1a = q.createChildQuery(); - AtlasGraphQuery inner1b = q.createChildQuery(); - inner1a.has("name", "Fred"); - inner1b.has("name", "Jane"); - q.or(toList(inner1a, inner1b)); - - - AtlasGraphQuery inner2a = q.createChildQuery(); - AtlasGraphQuery inner2b = q.createChildQuery(); - AtlasGraphQuery inner2c = q.createChildQuery(); - inner2a.has("size15", "18"); - inner2b.has("size15", "15"); - inner2c.has("size15", "16"); - q.or(toList(inner2a, inner2b, inner2c)); - - assertQueryMatches(q, v1); - graph.commit(); - pause(); //let the index update - assertQueryMatches(q, v1); - } - - @Test - public void testWithinStep() throws AtlasException { - Titan0Graph graph = getTitan0Graph(); - - AtlasVertex<Titan0Vertex, Titan0Edge> v1 = createVertex(graph); - - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - v1.setProperty("typeName", "Person"); - - AtlasVertex<Titan0Vertex, Titan0Edge> v2 = createVertex(graph); - v2.setProperty("name", "George"); - v2.setProperty("size15", "16"); - v2.setProperty("typeName", "Person"); - - AtlasVertex<Titan0Vertex, Titan0Edge> v3 = createVertex(graph); - v3.setProperty("name", "Jane"); - v3.setProperty("size15", "17"); - v3.setProperty("typeName", "Person"); - - - AtlasVertex<Titan0Vertex, Titan0Edge> v4 = createVertex(graph); - v4.setProperty("name", "Bob"); - v4.setProperty("size15", "18"); - v4.setProperty("typeName", "Person"); - - AtlasVertex<Titan0Vertex, Titan0Edge> v5 = createVertex(graph); - v5.setProperty("name", "Julia"); - v5.setProperty("size15", "19"); - v5.setProperty("typeName", "Manager"); - - - AtlasGraphQuery q = getGraphQuery(); - q.has("typeName", "Person"); - //initially match - q.in("name", toList("Fred", "Jane")); - q.in("size15", toList("18", "15", "16")); - - assertQueryMatches(q, v1); - graph.commit(); - pause(); //let the index update - assertQueryMatches(q, v1); - } - - @Test - public void testWithinStepWhereGraphIsStale() throws AtlasException { - Titan0Graph graph = getTitan0Graph(); - - AtlasVertex<Titan0Vertex, Titan0Edge> v1 = createVertex(graph); - - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - v1.setProperty("typeName", "Person"); - - AtlasVertex<Titan0Vertex, Titan0Edge> v2 = createVertex(graph); - v2.setProperty("name", "George"); - v2.setProperty("size15", "16"); - v2.setProperty("typeName", "Person"); - - AtlasVertex<Titan0Vertex, Titan0Edge> v3 = createVertex(graph); - v3.setProperty("name", "Jane"); - v3.setProperty("size15", "17"); - v3.setProperty("typeName", "Person"); - - - AtlasVertex<Titan0Vertex, Titan0Edge> v4 = createVertex(graph); - v4.setProperty("name", "Bob"); - v4.setProperty("size15", "18"); - v4.setProperty("typeName", "Person"); - - AtlasVertex<Titan0Vertex, Titan0Edge> v5 = createVertex(graph); - v5.setProperty("name", "Julia"); - v5.setProperty("size15", "19"); - v5.setProperty("typeName", "Manager"); - - - AtlasGraphQuery q = getGraphQuery(); - q.has("typeName", "Person"); - //initially match - q.in("name", toList("Fred", "Jane")); - - graph.commit(); - pause(); //let the index update - assertQueryMatches(q, v1, v3); - //make v3 no longer match the query. Within step should filter out the vertex since it no longer matches. - v3.setProperty("name", "Janet"); - assertQueryMatches(q, v1); - } - - @Test - public void testSimpleOrQuery() throws AtlasException { - Titan0Graph graph = getTitan0Graph(); - - - AtlasVertex<Titan0Vertex, Titan0Edge> v1 = createVertex(graph); - - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - - AtlasVertex<Titan0Vertex, Titan0Edge> v2 = createVertex(graph); - v2.setProperty("name", "Fred"); - - AtlasVertex<Titan0Vertex, Titan0Edge> v3 = createVertex(graph); - v3.setProperty("size15", "15"); - - graph.commit(); - - AtlasVertex<Titan0Vertex, Titan0Edge> v4 = createVertex(graph); - v4.setProperty("name", "Fred"); - v4.setProperty("size15", "15"); - - AtlasVertex<Titan0Vertex, Titan0Edge> v5 = createVertex(graph); - v5.setProperty("name", "George"); - v5.setProperty("size15", "16"); - - AtlasGraphQuery q = graph.query(); - AtlasGraphQuery inner1 = q.createChildQuery().has("name", "Fred"); - AtlasGraphQuery inner2 = q.createChildQuery().has("size15", "15"); - q.or(toList(inner1, inner2)); - assertQueryMatches(q, v1, v2, v3, v4); - graph.commit(); - pause(); //pause to let the indexer get updated (this fails frequently without a pause) - assertQueryMatches(q, v1, v2, v3, v4); - } - - - - - @Test - public <V, E> void testQueryMatchesAddedVertices() throws AtlasException { - AtlasGraph<V, E> graph = getGraph(); - - AtlasVertex<V, E> v1 = createVertex(graph); - - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - - AtlasVertex<V, E> v2 = createVertex(graph); - v2.setProperty("name", "Fred"); - - AtlasVertex<V, E> v3 = createVertex(graph); - v3.setProperty("size15", "15"); - - graph.commit(); - - AtlasVertex<V, E> v4 = createVertex(graph); - v4.setProperty("name", "Fred"); - v4.setProperty("size15", "15"); - - AtlasGraphQuery q = getGraphQuery(); - q.has("name", "Fred"); - q.has("size15", "15"); - - assertQueryMatches(q, v1, v4); - graph.commit(); - assertQueryMatches(q, v1, v4); - - } - - - @Test - public <V, E> void testQueryDoesNotMatchRemovedVertices() throws AtlasException { - AtlasGraph<V, E> graph = getGraph(); - - AtlasVertex<V, E> v1 = createVertex(graph); - - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - - AtlasVertex<V, E> v2 = createVertex(graph); - v2.setProperty("name", "Fred"); - - AtlasVertex<V, E> v3 = createVertex(graph); - v3.setProperty("size15", "15"); - - AtlasVertex<V, E> v4 = createVertex(graph); - v4.setProperty("name", "Fred"); - v4.setProperty("size15", "15"); - - graph.commit(); - - graph.removeVertex(v1); - - AtlasGraphQuery q = getGraphQuery(); - q.has("name", "Fred"); - q.has("size15", "15"); - - assertQueryMatches(q, v4); - graph.commit(); - - assertQueryMatches(q, v4); - } - - @Test - public <V, E> void testQueryDoesNotMatchUncommittedAddedAndRemovedVertices() throws AtlasException { - AtlasGraph<V, E> graph = getGraph(); - - AtlasVertex<V, E> v1 = createVertex(graph); - - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - - AtlasVertex<V, E> v2 = createVertex(graph); - v2.setProperty("name", "Fred"); - - AtlasVertex<V, E> v3 = createVertex(graph); - v3.setProperty("size15", "15"); - - AtlasVertex<V, E> v4 = createVertex(graph); - v4.setProperty("name", "Fred"); - v4.setProperty("size15", "15"); - - - AtlasGraphQuery q = getGraphQuery(); - q.has("name", "Fred"); - q.has("size15", "15"); - - assertQueryMatches(q, v1, v4); - - graph.removeVertex(v1); - - - assertQueryMatches(q, v4); - graph.commit(); - - assertQueryMatches(q, v4); - } - - - @Test - public <V, E> void testQueryResultsReflectPropertyAdd() throws AtlasException { - AtlasGraph<V, E> graph = getGraph(); - - AtlasVertex<V, E> v1 = createVertex(graph); - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - v1.addProperty(TRAIT_NAMES, "trait1"); - v1.addProperty(TRAIT_NAMES, "trait2"); - - AtlasVertex<V, E> v2 = createVertex(graph); - v2.setProperty("name", "Fred"); - v2.addProperty(TRAIT_NAMES, "trait1"); - - AtlasVertex<V, E> v3 = createVertex(graph); - v3.setProperty("size15", "15"); - v3.addProperty(TRAIT_NAMES, "trait2"); - - AtlasGraphQuery query = getGraphQuery(); - query.has("name", "Fred"); - query.has(TRAIT_NAMES, "trait1"); - query.has("size15", "15"); - - assertQueryMatches(query, v1); - //make v3 match the query - v3.setProperty("name", "Fred"); - v3.addProperty(TRAIT_NAMES, "trait1"); - assertQueryMatches(query, v1, v3); - v3.removeProperty(TRAIT_NAMES); - assertQueryMatches(query, v1); - v3.addProperty(TRAIT_NAMES, "trait2"); - assertQueryMatches(query, v1); - v1.removeProperty(TRAIT_NAMES); - assertQueryMatches(query); - graph.commit(); - assertQueryMatches(query); - - } - - private static <T> List<T> toList(Iterable<T> itr) { - List<T> result = new ArrayList<>(); - for(T object : itr) { - result.add(object); - } - return result; - - } - - private <V, E> void assertQueryMatches(AtlasGraphQuery expr, AtlasVertex... expectedResults) throws AtlasException { - - //getGraph().commit(); - Collection<AtlasVertex<Titan0Vertex, Titan0Edge>> temp = toList(expr.vertices()); - //filter out vertices from previous test executions - Collection<AtlasVertex<Titan0Vertex, Titan0Edge>> result = - Collections2.filter(temp, new Predicate<AtlasVertex<Titan0Vertex, Titan0Edge>>() { - - @Override - public boolean apply(AtlasVertex<Titan0Vertex, Titan0Edge> input) { - return newVertices.contains(input); - } - - }); - String errorMessage = "Expected/found result sizes differ. Expected: " - + Arrays.asList(expectedResults).toString() +", found: " + result; - assertEquals(errorMessage, expectedResults.length, result.size()); - - for(AtlasVertex<V, E> v : expectedResults) { - assertTrue(result.contains(v)); - } - } - - private static List<Object> toList(Object...objects) { - return Arrays.asList(objects); - } - - private AtlasGraphQuery<Titan0Vertex, Titan0Edge> getGraphQuery() { - return getTitan0Graph().query(); - } - - private void pause() { - try { - Thread.sleep(5000); - } catch(InterruptedException e) { - //ignore - } - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/test/java/org/apache/atlas/repository/graphdb/titan0/Titan0DatabaseTest.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/test/java/org/apache/atlas/repository/graphdb/titan0/Titan0DatabaseTest.java b/graphdb/titan0/src/test/java/org/apache/atlas/repository/graphdb/titan0/Titan0DatabaseTest.java deleted file mode 100644 index e255e6c..0000000 --- a/graphdb/titan0/src/test/java/org/apache/atlas/repository/graphdb/titan0/Titan0DatabaseTest.java +++ /dev/null @@ -1,413 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; - -import org.apache.atlas.AtlasException; -import org.apache.atlas.graph.GraphSandboxUtil; -import org.apache.atlas.repository.Constants; -import org.apache.atlas.repository.graphdb.AtlasCardinality; -import org.apache.atlas.repository.graphdb.AtlasEdge; -import org.apache.atlas.repository.graphdb.AtlasEdgeDirection; -import org.apache.atlas.repository.graphdb.AtlasGraph; -import org.apache.atlas.repository.graphdb.AtlasGraphManagement; -import org.apache.atlas.repository.graphdb.AtlasGraphQuery; -import org.apache.atlas.repository.graphdb.AtlasGraphQuery.ComparisionOperator; -import org.apache.atlas.repository.graphdb.AtlasPropertyKey; -import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.apache.atlas.typesystem.types.DataTypes.TypeCategory; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import static org.testng.Assert.*; - -/** - * Sanity test of basic graph operations using the Titan 0.5.4 graphdb - * abstraction layer implementation. - */ -public class Titan0DatabaseTest { - - private AtlasGraph<?, ?> atlasGraph; - - private <V, E> AtlasGraph<V, E> getGraph() { - GraphSandboxUtil.create(); - - if (atlasGraph == null) { - Titan0GraphDatabase db = new Titan0GraphDatabase(); - atlasGraph = db.getGraph(); - AtlasGraphManagement mgmt = atlasGraph.getManagementSystem(); - // create the index (which defines these properties as being mult - // many) - for (String propertyName : new String[]{"__superTypeNames", "__traitNames"}) { - AtlasPropertyKey propertyKey = mgmt.getPropertyKey(propertyName); - if (propertyKey == null) { - propertyKey = mgmt.makePropertyKey(propertyName, String.class, AtlasCardinality.SET); - mgmt.createVertexCompositeIndex(propertyName, false, Collections.singletonList(propertyKey)); - } - } - mgmt.commit(); - } - return (AtlasGraph<V, E>) atlasGraph; - } - - @AfterClass - public void cleanup() { - atlasGraph.clear(); - atlasGraph = null; - - } - - @Test - public <V, E> void testPropertyDataTypes() { - - // primitives - AtlasGraph<V, E> graph = getGraph(); - - testProperty(graph, "booleanProperty", Boolean.TRUE); - testProperty(graph, "booleanProperty", Boolean.FALSE); - - testProperty(graph, "byteProperty", Byte.MAX_VALUE); - testProperty(graph, "byteProperty", Byte.MIN_VALUE); - - testProperty(graph, "shortProperty", Short.MAX_VALUE); - testProperty(graph, "shortProperty", Short.MIN_VALUE); - - testProperty(graph, "intProperty", Integer.MAX_VALUE); - testProperty(graph, "intProperty", Integer.MIN_VALUE); - - testProperty(graph, "longProperty", Long.MIN_VALUE); - testProperty(graph, "longProperty", Long.MAX_VALUE); - - testProperty(graph, "doubleProperty", Double.MAX_VALUE); - testProperty(graph, "doubleProperty", Double.MIN_VALUE); - - testProperty(graph, "floatProperty", Float.MAX_VALUE); - testProperty(graph, "floatProperty", Float.MIN_VALUE); - - // enumerations - TypeCategory - testProperty(graph, "typeCategoryProperty", TypeCategory.CLASS); - - // biginteger - testProperty(graph, "bigIntegerProperty", - new BigInteger(String.valueOf(Long.MAX_VALUE)).multiply(BigInteger.TEN)); - - // bigdecimal - BigDecimal bigDecimal = new BigDecimal(Double.MAX_VALUE); - testProperty(graph, "bigDecimalProperty", bigDecimal.multiply(bigDecimal)); - } - - private <V, E> void testProperty(AtlasGraph<V, E> graph, String name, Object value) { - - AtlasVertex<V, E> vertex = graph.addVertex(); - vertex.setProperty(name, value); - assertEquals(value, vertex.getProperty(name, value.getClass())); - AtlasVertex<V, E> loaded = graph.getVertex(vertex.getId().toString()); - assertEquals(value, loaded.getProperty(name, value.getClass())); - } - - @Test - public <V, E> void testMultiplicityOnePropertySupport() { - - AtlasGraph<V, E> graph = getGraph(); - - AtlasVertex<V, E> vertex = graph.addVertex(); - vertex.setProperty("name", "Jeff"); - vertex.setProperty("location", "Littleton"); - assertEquals("Jeff", vertex.getProperty("name", String.class)); - assertEquals("Littleton", vertex.getProperty("location", String.class)); - - AtlasVertex<V, E> vertexCopy = graph.getVertex(vertex.getId().toString()); - - assertEquals("Jeff", vertexCopy.getProperty("name", String.class)); - assertEquals("Littleton", vertexCopy.getProperty("location", String.class)); - - assertTrue(vertexCopy.getPropertyKeys().contains("name")); - assertTrue(vertexCopy.getPropertyKeys().contains("location")); - - assertTrue(vertexCopy.getPropertyValues("name", String.class).contains("Jeff")); - assertTrue(vertexCopy.getPropertyValues("location", String.class).contains("Littleton")); - assertTrue(vertexCopy.getPropertyValues("test", String.class).isEmpty()); - assertNull(vertexCopy.getProperty("test", String.class)); - - vertex.removeProperty("name"); - assertFalse(vertex.getPropertyKeys().contains("name")); - assertNull(vertex.getProperty("name", String.class)); - assertTrue(vertex.getPropertyValues("name", String.class).isEmpty()); - - vertexCopy = graph.getVertex(vertex.getId().toString()); - assertFalse(vertexCopy.getPropertyKeys().contains("name")); - assertNull(vertexCopy.getProperty("name", String.class)); - assertTrue(vertexCopy.getPropertyValues("name", String.class).isEmpty()); - - } - - @Test - public <V, E> void testRemoveEdge() { - - AtlasGraph<V, E> graph = getGraph(); - AtlasVertex<V, E> v1 = graph.addVertex(); - AtlasVertex<V, E> v2 = graph.addVertex(); - - AtlasEdge<V, E> edge = graph.addEdge(v1, v2, "knows"); - - // make sure the edge exists - AtlasEdge<V, E> edgeCopy = graph.getEdge(edge.getId().toString()); - assertNotNull(edgeCopy); - assertEquals(edgeCopy, edge); - - graph.removeEdge(edge); - - edgeCopy = graph.getEdge(edge.getId().toString()); - // should return null now, since edge was deleted - assertNull(edgeCopy); - - } - - @Test - public <V, E> void testRemoveVertex() { - - AtlasGraph<V, E> graph = getGraph(); - - AtlasVertex<V, E> v1 = graph.addVertex(); - - assertNotNull(graph.getVertex(v1.getId().toString())); - - graph.removeVertex(v1); - - assertNull(graph.getVertex(v1.getId().toString())); - } - - @Test - public <V, E> void testGetEdges() { - - AtlasGraph<V, E> graph = getGraph(); - AtlasVertex<V, E> v1 = graph.addVertex(); - AtlasVertex<V, E> v2 = graph.addVertex(); - AtlasVertex<V, E> v3 = graph.addVertex(); - - AtlasEdge<V, E> knows = graph.addEdge(v2, v1, "knows"); - AtlasEdge<V, E> eats = graph.addEdge(v3, v1, "eats"); - AtlasEdge<V, E> drives = graph.addEdge(v3, v2, "drives"); - AtlasEdge<V, E> sleeps = graph.addEdge(v2, v3, "sleeps"); - - assertEdgesMatch(v1.getEdges(AtlasEdgeDirection.IN), knows, eats); - assertEdgesMatch(v1.getEdges(AtlasEdgeDirection.OUT)); - assertEdgesMatch(v1.getEdges(AtlasEdgeDirection.BOTH), knows, eats); - - assertEdgesMatch(v1.getEdges(AtlasEdgeDirection.IN, "knows"), knows); - assertEdgesMatch(v1.getEdges(AtlasEdgeDirection.OUT, "knows")); - assertEdgesMatch(v1.getEdges(AtlasEdgeDirection.BOTH, "knows"), knows); - - assertEdgesMatch(v2.getEdges(AtlasEdgeDirection.IN), drives); - assertEdgesMatch(v2.getEdges(AtlasEdgeDirection.OUT), knows, sleeps); - assertEdgesMatch(v2.getEdges(AtlasEdgeDirection.BOTH), knows, sleeps, drives); - - assertEdgesMatch(v2.getEdges(AtlasEdgeDirection.BOTH, "delivers")); - } - - private <V, E> void assertEdgesMatch(Iterable<AtlasEdge<V, E>> edgesIt, AtlasEdge<V, E>... expected) { - List<AtlasEdge<V, E>> edges = toList(edgesIt); - assertEquals(expected.length, edges.size()); - for (AtlasEdge<V, E> edge : expected) { - assertTrue(edges.contains(edge)); - } - } - - @Test - public <V, E> void testMultiplictyManyPropertySupport() { - - AtlasGraph<V, E> graph = getGraph(); - - AtlasVertex<V, E> vertex = graph.addVertex(); - String vertexId = vertex.getId().toString(); - vertex.setProperty(Constants.TRAIT_NAMES_PROPERTY_KEY, "trait1"); - vertex.setProperty(Constants.TRAIT_NAMES_PROPERTY_KEY, "trait2"); - assertEquals(vertex.getPropertyValues(Constants.TRAIT_NAMES_PROPERTY_KEY, String.class).size(), 2); - vertex.addProperty(Constants.TRAIT_NAMES_PROPERTY_KEY, "trait3"); - vertex.addProperty(Constants.TRAIT_NAMES_PROPERTY_KEY, "trait4"); - - assertTrue(vertex.getPropertyKeys().contains(Constants.TRAIT_NAMES_PROPERTY_KEY)); - validateMultManyPropertiesInVertex(vertex); - // fetch a copy of the vertex, make sure result - // is the same - - validateMultManyPropertiesInVertex(graph.getVertex(vertexId)); - - } - - private <V, E> void validateMultManyPropertiesInVertex(AtlasVertex<V, E> vertex) { - - assertTrue(vertex.getPropertyKeys().contains(Constants.TRAIT_NAMES_PROPERTY_KEY)); - Collection<String> traitNames = vertex.getPropertyValues(Constants.TRAIT_NAMES_PROPERTY_KEY, String.class); - assertTrue(traitNames.contains("trait1")); - assertTrue(traitNames.contains("trait2")); - assertTrue(traitNames.contains("trait3")); - assertTrue(traitNames.contains("trait4")); - - try { - vertex.getProperty(Constants.TRAIT_NAMES_PROPERTY_KEY, String.class); - fail("Expected exception not thrown"); - } catch (IllegalStateException expected) { - // multiple property values exist - } - } - - @Test - public <V, E> void testListProperties() throws AtlasException { - - AtlasGraph<V, E> graph = getGraph(); - AtlasVertex<V, E> vertex = graph.addVertex(); - vertex.setListProperty("colors", Arrays.asList("red", "blue", "green")); - List<String> colors = vertex.getListProperty("colors"); - assertTrue(colors.contains("red")); - assertTrue(colors.contains("blue")); - assertTrue(colors.contains("green")); - - AtlasVertex<V, E> vertexCopy = graph.getVertex(vertex.getId().toString()); - colors = vertexCopy.getListProperty("colors"); - assertTrue(colors.contains("red")); - assertTrue(colors.contains("blue")); - assertTrue(colors.contains("green")); - - } - - @Test - public <V, E> void testRemoveProperty() { - - AtlasGraph<V, E> graph = getGraph(); - AtlasVertex<V, E> vertex = graph.addVertex(); - vertex.addProperty(Constants.TRAIT_NAMES_PROPERTY_KEY, "trait1"); - vertex.addProperty(Constants.TRAIT_NAMES_PROPERTY_KEY, "trait1"); - vertex.setProperty("name", "Jeff"); - - // remove existing property - multiplicity one - vertex.removeProperty("jeff"); - - assertFalse(vertex.getPropertyKeys().contains("jeff")); - - // remove existing property - multiplicity many - vertex.removeProperty(Constants.TRAIT_NAMES_PROPERTY_KEY); - assertFalse(vertex.getPropertyKeys().contains(Constants.TRAIT_NAMES_PROPERTY_KEY)); - - AtlasVertex<V, E> vertexCopy = graph.getVertex(vertex.getId().toString()); - assertFalse(vertexCopy.getPropertyKeys().contains("jeff")); - assertFalse(vertexCopy.getPropertyKeys().contains(Constants.TRAIT_NAMES_PROPERTY_KEY)); - - // remove non-existing property - vertex.removeProperty(Constants.TRAIT_NAMES_PROPERTY_KEY); - vertex.removeProperty("jeff"); - - } - - @Test - public <V, E> void getGetGraphQueryForVertices() { - - AtlasGraph<V, E> graph = getGraph(); - - AtlasVertex<V, E> v1 = graph.addVertex(); - AtlasVertex<V, E> v2 = graph.addVertex(); - AtlasVertex<V, E> v3 = graph.addVertex(); - - v1.setProperty("name", "Jeff"); - v1.setProperty("weight", 1); - - v2.setProperty("name", "Fred"); - v2.setProperty("weight", 2); - - v3.setProperty("name", "Chris"); - v3.setProperty("weight", 3); - - AtlasEdge<V, E> knows = graph.addEdge(v2, v1, "knows"); - knows.setProperty("weight", 1); - AtlasEdge<V, E> eats = graph.addEdge(v3, v1, "eats"); - eats.setProperty("weight", 2); - AtlasEdge<V, E> drives = graph.addEdge(v3, v2, "drives"); - drives.setProperty("weight", 3); - - AtlasEdge<V, E> sleeps = graph.addEdge(v2, v3, "sleeps"); - sleeps.setProperty("weight", 4); - - testExecuteGraphQuery("name", null, "Jeff", v1); - testExecuteGraphQuery("weight", ComparisionOperator.EQUAL, 2, v2); - testExecuteGraphQuery("weight", ComparisionOperator.GREATER_THAN_EQUAL, 2, v2, v3); - testExecuteGraphQuery("weight", ComparisionOperator.LESS_THAN_EQUAL, 2, v2, v1); - - } - - private <V, E> void testExecuteGraphQuery(String property, ComparisionOperator op, Object value, - AtlasVertex<V, E>... expected) { - AtlasGraph<V, E> graph = getGraph(); - AtlasGraphQuery<V, E> query = graph.query(); - if (op != null) { - query.has(property, op, value); - } else { - query.has(property, value); - } - Iterable<? extends AtlasVertex<V, E>> result = query.vertices(); - List<AtlasVertex<V, E>> list = toList(result); - assertEquals(expected.length, list.size()); - for (AtlasVertex<V, E> vertex : expected) { - assertTrue(list.contains(vertex)); - } - } - - @Test - public <V, E> void testAddMultManyPropertyValueTwice() { - - AtlasGraph<V, E> graph = getGraph(); - String vertexId; - - AtlasVertex<V, E> vertex = graph.addVertex(); - vertexId = vertex.getId().toString(); - vertex.setProperty(Constants.TRAIT_NAMES_PROPERTY_KEY, "trait1"); - vertex.setProperty(Constants.TRAIT_NAMES_PROPERTY_KEY, "trait1"); - vertex.addProperty(Constants.TRAIT_NAMES_PROPERTY_KEY, "trait2"); - vertex.addProperty(Constants.TRAIT_NAMES_PROPERTY_KEY, "trait2"); - - validateDuplicatePropertyVertex(vertex); - - // fetch a copy of the vertex, make sure result is the same - - validateDuplicatePropertyVertex(graph.getVertex(vertexId)); - } - - private <V, E> void validateDuplicatePropertyVertex(AtlasVertex<V, E> vertex) { - assertEquals(2, vertex.getPropertyValues(Constants.TRAIT_NAMES_PROPERTY_KEY, String.class).size()); - assertTrue(vertex.getPropertyKeys().contains(Constants.TRAIT_NAMES_PROPERTY_KEY)); - Collection<String> traitNames = vertex.getPropertyValues(Constants.TRAIT_NAMES_PROPERTY_KEY, String.class); - assertTrue(traitNames.contains("trait1")); - assertTrue(traitNames.contains("trait2")); - } - - private static <T> List<T> toList(Iterable<? extends T> iterable) { - List<T> result = new ArrayList<>(); - for (T item : iterable) { - result.add(item); - } - return result; - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/test/java/org/apache/atlas/repository/graphdb/titan0/Titan0DatabaseValidationTest.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/test/java/org/apache/atlas/repository/graphdb/titan0/Titan0DatabaseValidationTest.java b/graphdb/titan0/src/test/java/org/apache/atlas/repository/graphdb/titan0/Titan0DatabaseValidationTest.java deleted file mode 100644 index b70d322..0000000 --- a/graphdb/titan0/src/test/java/org/apache/atlas/repository/graphdb/titan0/Titan0DatabaseValidationTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; - -import org.apache.atlas.ApplicationProperties; -import org.apache.atlas.AtlasException; -import org.apache.atlas.graph.GraphSandboxUtil; -import org.apache.atlas.repository.graphdb.AtlasGraph; -import org.apache.commons.configuration.Configuration; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -@Test -public class Titan0DatabaseValidationTest { - - private Configuration configuration; - private AtlasGraph<?, ?> graph; - - @BeforeTest - public void setUp() throws AtlasException { - GraphSandboxUtil.create(); - - // First get Instance - graph = new Titan0Graph(); - configuration = ApplicationProperties.getSubsetConfiguration(ApplicationProperties.get(), - Titan0GraphDatabase.GRAPH_PREFIX); - } - - @AfterClass - public void tearDown() throws Exception { - try { - graph.shutdown(); - } catch (Exception e) { - e.printStackTrace(); - } - - try { - graph.clear(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testValidate() throws AtlasException { - try { - Titan0GraphDatabase.validateIndexBackend(configuration); - } catch (Exception e) { - Assert.fail("Unexpected exception ", e); - } - - // Change backend - configuration.setProperty(Titan0GraphDatabase.INDEX_BACKEND_CONF, Titan0GraphDatabase.INDEX_BACKEND_LUCENE); - try { - Titan0GraphDatabase.validateIndexBackend(configuration); - Assert.fail("Expected exception"); - } catch (Exception e) { - Assert.assertEquals(e.getMessage(), - "Configured Index Backend lucene differs from earlier configured " - + "Index Backend elasticsearch. Aborting!"); - } - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/test/resources/atlas-application.properties ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/test/resources/atlas-application.properties b/graphdb/titan0/src/test/resources/atlas-application.properties deleted file mode 100644 index 6188873..0000000 --- a/graphdb/titan0/src/test/resources/atlas-application.properties +++ /dev/null @@ -1,100 +0,0 @@ -# -# 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. -# - -######### Graph Database to Use ######### -atlas.graphdb.backend=org.apache.atlas.repository.graphdb.titan0.Titan0GraphDatabase - -######### Atlas Server Configs ######### -atlas.rest.address=http://localhost:31000 - -######### Graph Database Configs ######### -# Graph Storage -atlas.graph.storage.backend=${graph.storage.backend} - -# Graph Search Index Backend -atlas.graph.index.search.backend=${graph.index.backend} - -#Berkeley storage directory -atlas.graph.storage.directory=${sys:atlas.data}/berkeley - -#hbase -#For standalone mode , specify localhost -#for distributed mode, specify zookeeper quorum here - For more information refer http://s3.thinkaurelius.com/docs/titan/current/hbase.html#_remote_server_mode_2 - -atlas.graph.storage.hostname=${graph.storage.hostname} -atlas.graph.storage.hbase.regions-per-server=1 -atlas.graph.storage.lock.wait-time=10000 - -#ElasticSearch -atlas.graph.index.search.directory=${sys:atlas.data}/es -atlas.graph.index.search.elasticsearch.client-only=false -atlas.graph.index.search.elasticsearch.local-mode=true -atlas.graph.index.search.elasticsearch.create.sleep=2000 - -# Solr cloud mode properties -atlas.graph.index.search.solr.mode=cloud -atlas.graph.index.search.solr.zookeeper-url=${solr.zk.address} - -# Solr-specific configuration property -atlas.graph.index.search.max-result-set-size=150 - -######### Hive Lineage Configs ######### -# This models reflects the base super types for Data and Process -#atlas.lineage.hive.table.type.name=DataSet -#atlas.lineage.hive.process.type.name=Process -#atlas.lineage.hive.process.inputs.name=inputs -#atlas.lineage.hive.process.outputs.name=outputs - -## Schema -atlas.lineage.hive.table.schema.query.hive_table=hive_table where name='%s'\, columns - -######### Notification Configs ######### -atlas.notification.embedded=true - -atlas.kafka.zookeeper.connect=localhost:19026 -atlas.kafka.bootstrap.servers=localhost:19027 -atlas.kafka.data=${sys:atlas.data}/kafka -atlas.kafka.zookeeper.session.timeout.ms=4000 -atlas.kafka.zookeeper.sync.time.ms=20 -atlas.kafka.consumer.timeout.ms=100 -atlas.kafka.auto.commit.interval.ms=100 -atlas.kafka.hook.group.id=atlas -atlas.kafka.entities.group.id=atlas_entities -atlas.kafka.offsets.topic.replication.factor=1 - -######### Entity Audit Configs ######### -atlas.audit.hbase.tablename=ATLAS_ENTITY_AUDIT_EVENTS -atlas.audit.zookeeper.session.timeout.ms=1000 -atlas.audit.hbase.zookeeper.quorum=localhost -atlas.audit.hbase.zookeeper.property.clientPort=19026 - -######### Security Properties ######### - -# SSL config -atlas.enableTLS=false -atlas.server.https.port=31443 - -######### Security Properties ######### - -hbase.security.authentication=simple - -atlas.hook.falcon.synchronous=true -######### High Availability Configuration ######## -atlas.server.ha.enabled=false -#atlas.server.ids=id1 -#atlas.server.address.id1=localhost:21000 http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/intg/src/main/resources/atlas-log4j.xml ---------------------------------------------------------------------- diff --git a/intg/src/main/resources/atlas-log4j.xml b/intg/src/main/resources/atlas-log4j.xml index 510e2cf..4f74c2a 100755 --- a/intg/src/main/resources/atlas-log4j.xml +++ b/intg/src/main/resources/atlas-log4j.xml @@ -72,7 +72,7 @@ <appender-ref ref="AUDIT"/> </logger> - <logger name="com.thinkaurelius.titan" additivity="false"> + <logger name="org.janusgraph" additivity="false"> <level value="warn"/> <appender-ref ref="console"/> </logger> http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/intg/src/test/resources/atlas-application.properties ---------------------------------------------------------------------- diff --git a/intg/src/test/resources/atlas-application.properties b/intg/src/test/resources/atlas-application.properties index af9c3d7..7e74d51 100644 --- a/intg/src/test/resources/atlas-application.properties +++ b/intg/src/test/resources/atlas-application.properties @@ -57,7 +57,7 @@ atlas.graph.storage.directory=${sys:atlas.data}/berkley #hbase #For standalone mode , specify localhost -#for distributed mode, specify zookeeper quorum here - For more information refer http://s3.thinkaurelius.com/docs/titan/current/hbase.html#_remote_server_mode_2 +#for distributed mode, specify zookeeper quorum here atlas.graph.storage.hostname=${graph.storage.hostname} atlas.graph.storage.hbase.regions-per-server=1 http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index aa675cc..501ea61 100644 --- a/pom.xml +++ b/pom.xml @@ -650,10 +650,9 @@ These profiles are mutually exclusive and should be activated by setting the system property GRAPH-PROVIDER. This can be optionally specified when invoking mvn: - e.g. mvn clean install -DGRAPH-PROVIDER=titan0 + e.g. mvn clean install -DGRAPH-PROVIDER=janus The settings for GRAPH-PROVIDER have the following effects: - * If GRAPH-PROVIDER is not specified, the graph-provider-default profile is activated. - * If GRAPH-PROVIDER is set to titan0, the graph-provider-titan0 profile is activated. + * If GRAPH-PROVIDER is not specified, the graph-provider-default profile (janus) is activated. * If GRAPH-PROVIDER is set to anything else, the build will fail. Do not activate the graph-provider selection profiles using -P. --> @@ -667,7 +666,6 @@ </property> </activation> <properties> - <!-- Define graph dependency type/version --> <graphGroup>org.apache.atlas</graphGroup> <graphArtifact>atlas-graphdb-janus</graphArtifact> <skipDocs>false</skipDocs> @@ -687,7 +685,6 @@ </property> </activation> <properties> - <!-- Define graph dependency type/version --> <graphGroup>org.apache.atlas</graphGroup> <graphArtifact>atlas-graphdb-janus</graphArtifact> <skipDocs>false</skipDocs> @@ -699,26 +696,6 @@ </profile> <profile> - <id>graph-provider-titan0</id> - <activation> - <property> - <name>GRAPH-PROVIDER</name> - <value>titan0</value> - </property> - </activation> - <properties> - <!-- Define graph dependency type/version --> - <graphGroup>org.apache.atlas</graphGroup> - <graphArtifact>atlas-graphdb-titan0</graphArtifact> - <skipDocs>false</skipDocs> - <graphdb.backend.impl>org.apache.atlas.repository.graphdb.titan0.Titan0GraphDatabase</graphdb.backend.impl> - <graph.index.backend>elasticsearch</graph.index.backend> - <tests.solr.embedded>false</tests.solr.embedded> - <distro.exclude.packages>WEB-INF/lib/titan-*.jar,WEB-INF/lib/je-*.jar,WEB-INF/lib/elasticsearch-*.jar,WEB-INF/lib/lucene-*.jar</distro.exclude.packages> - </properties> - </profile> - - <profile> <id>skipMinify</id> <properties> <project.build.dashboardv2.gruntBuild>build</project.build.dashboardv2.gruntBuild> http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/repository/pom.xml ---------------------------------------------------------------------- diff --git a/repository/pom.xml b/repository/pom.xml index 4c39b28..a6ee43f 100755 --- a/repository/pom.xml +++ b/repository/pom.xml @@ -251,30 +251,6 @@ </dependency> </dependencies> </profile> - - <profile> - <id>graph-provider-titan0</id> - <activation> - <property> - <name>GRAPH-PROVIDER</name> - <value>titan0</value> - </property> - </activation> - <dependencies> - <dependency> - <groupId>org.apache.atlas</groupId> - <artifactId>atlas-testtools</artifactId> - <version>${project.version}</version> - <exclusions> - <exclusion> - <groupId>org.apache.lucene</groupId> - <artifactId>*</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - </profile> - </profiles> <build> http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java index f517445..f75f786 100755 --- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java @@ -116,7 +116,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang } /** - * Initialize global indices for Titan graph on server activation. + * Initialize global indices for JanusGraph on server activation. * * Since the indices are shared state, we need to do this only from an active instance. */ http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java index 40154d9..d79d914 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java @@ -761,7 +761,7 @@ public abstract class DeleteHandlerV1 { List<String> elements = GraphHelper.getListProperty(outVertex, propertyName); if (elements != null) { - elements = new ArrayList<>(elements); //Make a copy, else list.remove reflects on titan.getProperty() + elements = new ArrayList<>(elements); for (String elementEdgeId : elements) { AtlasEdge elementEdge = graphHelper.getEdgeByEdgeId(outVertex, edgeLabel, elementEdgeId); @@ -807,7 +807,7 @@ public abstract class DeleteHandlerV1 { List<String> keys = GraphHelper.getListProperty(outVertex, propertyName); if (keys != null) { - keys = new ArrayList<>(keys); //Make a copy, else list.remove reflects on titan.getProperty() + keys = new ArrayList<>(keys); for (String key : keys) { String keyPropertyName = GraphHelper.getQualifiedNameForMapKey(propertyName, key); http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/tools/atlas-migration-exporter/pom.xml ---------------------------------------------------------------------- diff --git a/tools/atlas-migration-exporter/pom.xml b/tools/atlas-migration-exporter/pom.xml index 71a529f..6880f38 100644 --- a/tools/atlas-migration-exporter/pom.xml +++ b/tools/atlas-migration-exporter/pom.xml @@ -61,15 +61,5 @@ <artifactId>blueprints-core</artifactId> <version>${tinkerpop.version}</version> </dependency> - <dependency> - <groupId>com.thinkaurelius.titan</groupId> - <artifactId>titan-core</artifactId> - <version>${titan.version}</version> - </dependency> - <dependency> - <groupId>org.apache.atlas</groupId> - <artifactId>atlas-graphdb-titan0</artifactId> - <version>${project.version}</version> - </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/tools/atlas-migration-exporter/src/main/java/org/apache/atlas/migration/Exporter.java ---------------------------------------------------------------------- diff --git a/tools/atlas-migration-exporter/src/main/java/org/apache/atlas/migration/Exporter.java b/tools/atlas-migration-exporter/src/main/java/org/apache/atlas/migration/Exporter.java index 2af8b7d..d8f8def 100644 --- a/tools/atlas-migration-exporter/src/main/java/org/apache/atlas/migration/Exporter.java +++ b/tools/atlas-migration-exporter/src/main/java/org/apache/atlas/migration/Exporter.java @@ -18,12 +18,7 @@ package org.apache.atlas.migration; -import com.thinkaurelius.titan.core.TitanGraph; -import com.tinkerpop.blueprints.Graph; -import com.tinkerpop.blueprints.util.io.graphson.GraphSONMode; -import com.tinkerpop.blueprints.util.io.graphson.GraphSONWriter; import org.apache.atlas.model.typedef.AtlasTypesDef; -import org.apache.atlas.repository.graphdb.titan0.Titan0GraphDatabase; import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.commons.cli.BasicParser; @@ -143,10 +138,6 @@ public class Exporter { try { os = new FileOutputStream(dataFileName); - - Graph graph = getTitan0GraphDatabase(); - - GraphSONWriter.outputGraph(graph, os, GraphSONMode.EXTENDED); } finally { if (os != null) { try { @@ -167,10 +158,6 @@ public class Exporter { new ArrayList<>(registry.getAllEntityDefs())); } - private TitanGraph getTitan0GraphDatabase() { - return Titan0GraphDatabase.getGraphInstance(); - } - private static void displayMessage(String msg) { LOG.info(LOG_MSG_PREFIX + msg); http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/webapp/pom.xml ---------------------------------------------------------------------- diff --git a/webapp/pom.xml b/webapp/pom.xml index 284f538..03b8408 100755 --- a/webapp/pom.xml +++ b/webapp/pom.xml @@ -460,9 +460,9 @@ </manifest> </archive> <packagingExcludes> - <!-- Titan and hbase jars should be excluded because an uber jar with shaded dependencies is created. + <!-- HBase jars should be excluded because an uber jar with shaded dependencies is created. But mvn 3.3.x includes them for some reason. So, excluding them explicitly here --> - WEB-INF/lib/titan*.jar,WEB-INF/lib/hbase*.jar,WEB-INF/lib/junit*.jar,${packages.to.exclude} + WEB-INF/lib/hbase*.jar,WEB-INF/lib/junit*.jar,${packages.to.exclude} </packagingExcludes> </configuration> </plugin> http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/webapp/src/test/resources/atlas-application.properties ---------------------------------------------------------------------- diff --git a/webapp/src/test/resources/atlas-application.properties b/webapp/src/test/resources/atlas-application.properties index 275ac33..3847a3d 100644 --- a/webapp/src/test/resources/atlas-application.properties +++ b/webapp/src/test/resources/atlas-application.properties @@ -39,7 +39,7 @@ atlas.graph.storage.directory=${sys:atlas.data}/berkley #hbase #For standalone mode , specify localhost -#for distributed mode, specify zookeeper quorum here - For more information refer http://s3.thinkaurelius.com/docs/titan/current/hbase.html#_remote_server_mode_2 +#for distributed mode, specify zookeeper quorum here atlas.graph.storage.hostname=${graph.storage.hostname} atlas.graph.storage.hbase.regions-per-server=1