Search in sources :

Example 6 with TimestampProvider

use of com.thinkaurelius.titan.diskstorage.util.time.TimestampProvider in project titan by thinkaurelius.

the class TitanIndexTest method testIndexReplay.

@Category({ BrittleTests.class })
@Test
public void testIndexReplay() throws Exception {
    final TimestampProvider times = graph.getConfiguration().getTimestampProvider();
    final Instant startTime = times.getTime();
    clopen(option(SYSTEM_LOG_TRANSACTIONS), true, option(KCVSLog.LOG_READ_LAG_TIME, TRANSACTION_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, TRANSACTION_LOG), Duration.ofMillis(250), option(MAX_COMMIT_TIME), Duration.ofSeconds(1), option(STORAGE_WRITE_WAITTIME), Duration.ofMillis(300), option(TestMockIndexProvider.INDEX_BACKEND_PROXY, INDEX), readConfig.get(INDEX_BACKEND, INDEX), option(INDEX_BACKEND, INDEX), TestMockIndexProvider.class.getName(), option(TestMockIndexProvider.INDEX_MOCK_FAILADD, INDEX), true);
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make();
    mgmt.buildIndex("mi", Vertex.class).addKey(name, getTextMapping()).addKey(age).buildMixedIndex(INDEX);
    finishSchema();
    Vertex[] vs = new TitanVertex[4];
    vs[0] = tx.addVertex("name", "Big Boy Bobson", "age", 55);
    newTx();
    vs[1] = tx.addVertex("name", "Long Little Lewis", "age", 35);
    vs[2] = tx.addVertex("name", "Tall Long Tiger", "age", 75);
    vs[3] = tx.addVertex("name", "Long John Don", "age", 15);
    newTx();
    vs[2] = getV(tx, vs[2]);
    vs[2].remove();
    vs[3] = getV(tx, vs[3]);
    vs[3].property(VertexProperty.Cardinality.single, "name", "Bad Boy Badsy");
    vs[3].property("age").remove();
    newTx();
    vs[0] = getV(tx, vs[0]);
    vs[0].property(VertexProperty.Cardinality.single, "age", 66);
    newTx();
    clopen();
    //Just to make sure nothing has been persisted to index
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "boy"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "mi");
    /*
        Transaction Recovery
         */
    TransactionRecovery recovery = TitanFactory.startTransactionRecovery(graph, startTime);
    //wait
    Thread.sleep(12000L);
    recovery.shutdown();
    long[] recoveryStats = ((StandardTransactionLogProcessor) recovery).getStatistics();
    clopen();
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "boy"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "mi");
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "long"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mi");
    //        TitanVertex v = Iterables.getOnlyElement(tx.query().has("name",Text.CONTAINS,"long").vertices());
    //        System.out.println(v.getProperty("age"));
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "long").interval("age", 30, 40), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mi");
    evaluateQuery(tx.query().has("age", 75), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "mi");
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "boy").interval("age", 60, 70), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mi");
    evaluateQuery(tx.query().interval("age", 0, 100), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "mi");
    //schema transaction was successful
    assertEquals(1, recoveryStats[0]);
    //all 4 index transaction had provoked errors in the indexing backend
    assertEquals(4, recoveryStats[1]);
}
Also used : TransactionRecovery(com.thinkaurelius.titan.core.log.TransactionRecovery) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) TimestampProvider(com.thinkaurelius.titan.diskstorage.util.time.TimestampProvider) Instant(java.time.Instant) StandardTransactionLogProcessor(com.thinkaurelius.titan.graphdb.log.StandardTransactionLogProcessor) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) ElementCategory(com.thinkaurelius.titan.graphdb.internal.ElementCategory) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

TimestampProvider (com.thinkaurelius.titan.diskstorage.util.time.TimestampProvider)6 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)3 Instant (java.time.Instant)3 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)2 TransactionRecovery (com.thinkaurelius.titan.core.log.TransactionRecovery)2 StandardTransactionLogProcessor (com.thinkaurelius.titan.graphdb.log.StandardTransactionLogProcessor)2 Test (org.junit.Test)2 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)1 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)1 TitanException (com.thinkaurelius.titan.core.TitanException)1 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)1 TitanVertexProperty (com.thinkaurelius.titan.core.TitanVertexProperty)1 Change (com.thinkaurelius.titan.core.log.Change)1 ChangeProcessor (com.thinkaurelius.titan.core.log.ChangeProcessor)1 ChangeState (com.thinkaurelius.titan.core.log.ChangeState)1 LogProcessorFramework (com.thinkaurelius.titan.core.log.LogProcessorFramework)1 TransactionId (com.thinkaurelius.titan.core.log.TransactionId)1 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)1 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)1 TitanManagement (com.thinkaurelius.titan.core.schema.TitanManagement)1