本文整理汇总了Java中com.thinkaurelius.titan.testcategory.BrittleTests类的典型用法代码示例。如果您正苦于以下问题:Java BrittleTests类的具体用法?Java BrittleTests怎么用?Java BrittleTests使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BrittleTests类属于com.thinkaurelius.titan.testcategory包,在下文中一共展示了BrittleTests类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEdgeTTLWithIndex
import com.thinkaurelius.titan.testcategory.BrittleTests; //导入依赖的package包/类
@Category({BrittleTests.class})
@Test
public void testEdgeTTLWithIndex() throws Exception {
if (!features.hasCellTTL()) {
return;
}
int ttl = 1; // artificially low TTL for test
final PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make();
EdgeLabel wavedAt = mgmt.makeEdgeLabel("wavedAt").signature(time).make();
mgmt.buildEdgeIndex(wavedAt, "timeindex", Direction.BOTH, decr, time);
mgmt.buildIndex("edge-time", Edge.class).addKey(time).buildCompositeIndex();
mgmt.setTTL(wavedAt, Duration.ofSeconds(ttl));
assertEquals(Duration.ZERO, mgmt.getTTL(time));
assertEquals(Duration.ofSeconds(ttl), mgmt.getTTL(wavedAt));
mgmt.commit();
TitanVertex v1 = graph.addVertex(), v2 = graph.addVertex();
v1.addEdge("wavedAt", v2, "time", 42);
assertTrue(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext());
assertNotEmpty(v1.query().direction(Direction.OUT).edges());
assertNotEmpty(graph.query().has("time", 42).edges());
graph.tx().commit();
long commitTime = System.currentTimeMillis();
assertTrue(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext());
assertNotEmpty(v1.query().direction(Direction.OUT).edges());
assertNotEmpty(graph.query().has("time", 42).edges());
Thread.sleep(commitTime + (ttl * 1000L + 100) - System.currentTimeMillis());
graph.tx().rollback();
assertFalse(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext());
assertEmpty(v1.query().direction(Direction.OUT).edges());
assertEmpty(graph.query().has("time", 42).edges());
}
示例2: testEdgeTTLWithVertexCentricIndex
import com.thinkaurelius.titan.testcategory.BrittleTests; //导入依赖的package包/类
@Category({ BrittleTests.class })
@Test
public void testEdgeTTLWithVertexCentricIndex() throws Exception {
if (!features.hasCellTTL()) {
return;
}
int ttl = 1; // artificially low TTL for test
final PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make();
EdgeLabel wavedAt = mgmt.makeEdgeLabel("wavedAt").signature(time).make();
mgmt.buildEdgeIndex(wavedAt, "timeindex", Direction.BOTH, Order.DESC, time);
mgmt.setTTL(wavedAt, ttl, TimeUnit.SECONDS);
assertEquals(0, mgmt.getTTL(time).getLength(TimeUnit.SECONDS));
assertEquals(ttl, mgmt.getTTL(wavedAt).getLength(TimeUnit.SECONDS));
mgmt.commit();
Vertex v1 = graph.addVertex(null), v2 = graph.addVertex(null);
Edge e1 = graph.addEdge(null, v1, v2, "wavedAt");
e1.setProperty("time", 42);
assertTrue(v1.getEdges(Direction.OUT).iterator().hasNext());
assertTrue(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext());
graph.commit();
long commitTime = System.currentTimeMillis();
assertTrue(v1.getEdges(Direction.OUT).iterator().hasNext());
assertTrue(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext());
Thread.sleep(commitTime + (ttl * 1000L + 100) - System.currentTimeMillis());
graph.rollback();
assertFalse(v1.getEdges(Direction.OUT).iterator().hasNext());
assertFalse(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext());
}
示例3: testTtl
import com.thinkaurelius.titan.testcategory.BrittleTests; //导入依赖的package包/类
@Category({ BrittleTests.class })
@Test
public void testTtl() throws Exception {
if (!manager.getFeatures().hasCellTTL()) {
return;
}
StaticBuffer key = KeyColumnValueStoreUtil.longToByteBuffer(0);
int ttls[] = new int[]{0, 1, 2};
List<Entry> additions = new LinkedList<Entry>();
for (int i = 0; i < ttls.length; i++) {
StaticBuffer col = KeyColumnValueStoreUtil.longToByteBuffer(i);
StaticArrayEntry entry = (StaticArrayEntry) StaticArrayEntry.of(col, col);
entry.setMetaData(EntryMetaData.TTL, ttls[i]);
additions.add(entry);
}
store.mutate(key, additions, KeyColumnValueStore.NO_DELETIONS, tx);
tx.commit();
// commitTime starts just after the commit, so we won't check for expiration too early
long commitTime = System.currentTimeMillis();
tx = startTx();
StaticBuffer columnStart = KeyColumnValueStoreUtil.longToByteBuffer(0);
StaticBuffer columnEnd = KeyColumnValueStoreUtil.longToByteBuffer(ttls.length);
List<Entry> result =
store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(ttls.length), tx);
Assert.assertEquals(ttls.length, result.size());
// wait for one cell to expire
Thread.sleep(commitTime + 1001 - System.currentTimeMillis());
// cells immediately expire upon TTL, even before rollback()
result =
store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(ttls.length), tx);
Assert.assertEquals(ttls.length - 1, result.size());
tx.rollback();
result =
store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(ttls.length), tx);
Assert.assertEquals(ttls.length - 1, result.size());
Thread.sleep(commitTime + 2001 - System.currentTimeMillis());
tx.rollback();
result =
store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(ttls.length), tx);
Assert.assertEquals(ttls.length - 2, result.size());
// cell 0 doesn't expire due to TTL of 0 (infinite)
Thread.sleep(commitTime + 4001 - System.currentTimeMillis());
tx.rollback();
result =
store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(ttls.length), tx);
Assert.assertEquals(ttls.length - 2, result.size());
}
示例4: testPropertyTTLTiming
import com.thinkaurelius.titan.testcategory.BrittleTests; //导入依赖的package包/类
@Category({BrittleTests.class})
@Test
public void testPropertyTTLTiming() throws Exception {
if (!features.hasCellTTL()) {
return;
}
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
PropertyKey place = mgmt.makePropertyKey("place").dataType(String.class).make();
mgmt.setTTL(name, Duration.ofSeconds(42));
mgmt.setTTL(place, Duration.ofSeconds(1));
TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex();
TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(place).buildCompositeIndex();
VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
mgmt.setTTL(label1, Duration.ofSeconds(2));
assertEquals(Duration.ofSeconds(42), mgmt.getTTL(name));
assertEquals(Duration.ofSeconds(1), mgmt.getTTL(place));
assertEquals(Duration.ofSeconds(2), mgmt.getTTL(label1));
mgmt.commit();
TitanVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "place", "somewhere");
tx.commit();
Object id = v1.id();
v1 = getV(graph, id);
assertNotNull(v1);
assertNotEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
assertNotEmpty(graph.query().has("name", "some event").vertices());
Thread.sleep(1001);
graph.tx().rollback();
// short-lived property expires first
v1 = getV(graph, id);
assertNotNull(v1);
assertEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
assertNotEmpty(graph.query().has("name", "some event").vertices());
Thread.sleep(1001);
graph.tx().rollback();
// vertex expires before defined TTL of the long-lived property
assertEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
assertEmpty(graph.query().has("name", "some event").vertices());
v1 = getV(graph, id);
assertNull(v1);
}
示例5: testIndexReplay
import com.thinkaurelius.titan.testcategory.BrittleTests; //导入依赖的package包/类
@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");
assertEquals(1, recoveryStats[0]); //schema transaction was successful
assertEquals(4, recoveryStats[1]); //all 4 index transaction had provoked errors in the indexing backend
}
示例6: testPropertyTTLTiming
import com.thinkaurelius.titan.testcategory.BrittleTests; //导入依赖的package包/类
@Category({ BrittleTests.class })
@Test
public void testPropertyTTLTiming() throws Exception {
if (!features.hasCellTTL()) {
return;
}
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
PropertyKey place = mgmt.makePropertyKey("place").dataType(String.class).make();
mgmt.setTTL(name, 42, TimeUnit.SECONDS);
mgmt.setTTL(place, 1, TimeUnit.SECONDS);
TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex();
TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(place).buildCompositeIndex();
VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
mgmt.setTTL(label1, 2, TimeUnit.SECONDS);
assertEquals(42, mgmt.getTTL(name).getLength(TimeUnit.SECONDS));
assertEquals(1, mgmt.getTTL(place).getLength(TimeUnit.SECONDS));
assertEquals(2, mgmt.getTTL(label1).getLength(TimeUnit.SECONDS));
mgmt.commit();
Vertex v1 = tx.addVertexWithLabel("event");
v1.setProperty("name", "some event");
v1.setProperty("place", "somewhere");
tx.commit();
Object id = v1.getId();
v1 = graph.getVertex(id);
assertNotNull(v1);
assertTrue(graph.query().has("name","some event").has("place","somewhere").vertices().iterator().hasNext());
assertTrue(graph.getVertices("name", "some event").iterator().hasNext());
Thread.sleep(1001);
graph.rollback();
// short-lived property expires first
v1 = graph.getVertex(id);
assertNotNull(v1);
assertFalse(graph.query().has("name","some event").has("place","somewhere").vertices().iterator().hasNext());
assertTrue(graph.getVertices("name", "some event").iterator().hasNext());
Thread.sleep(1001);
graph.rollback();
// vertex expires before defined TTL of the long-lived property
assertFalse(graph.query().has("name","some event").has("place","somewhere").vertices().iterator().hasNext());
assertFalse(graph.getVertices("place", "somewhere").iterator().hasNext());
v1 = graph.getVertex(id);
assertNull(v1);
}
示例7: testIndexReplay
import com.thinkaurelius.titan.testcategory.BrittleTests; //导入依赖的package包/类
@Category({ BrittleTests.class })
@Test
public void testIndexReplay() throws Exception {
final TimestampProvider times = graph.getConfiguration().getTimestampProvider();
final long startTime = times.getTime().getTimestamp(TimeUnit.MILLISECONDS);
clopen( option(SYSTEM_LOG_TRANSACTIONS), true
,option(KCVSLog.LOG_READ_LAG_TIME,TRANSACTION_LOG),new StandardDuration(50,TimeUnit.MILLISECONDS)
,option(LOG_READ_INTERVAL,TRANSACTION_LOG),new StandardDuration(250,TimeUnit.MILLISECONDS)
,option(MAX_COMMIT_TIME),new StandardDuration(1,TimeUnit.SECONDS)
,option(STORAGE_WRITE_WAITTIME), new StandardDuration(300, TimeUnit.MILLISECONDS)
,option(TestMockIndexProvider.INDEX_BACKEND_PROXY,INDEX), adjustedConfig.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();
TitanVertex vs[] = new TitanVertex[4];
vs[0] = tx.addVertex();
ElementHelper.setProperties(vs[0],"name","Big Boy Bobson","age",55);
newTx();
vs[1] = tx.addVertex();
vs[2] = tx.addVertex();
vs[3] = tx.addVertex();
ElementHelper.setProperties(vs[1],"name","Long Little Lewis","age",35);
ElementHelper.setProperties(vs[2],"name","Tall Long Tiger","age",75);
ElementHelper.setProperties(vs[3],"name","Long John Don","age",15);
newTx();
vs[2] = tx.getVertex(vs[2].getLongId());
vs[2].remove();
vs[3] = tx.getVertex(vs[3].getLongId());
vs[3].setProperty("name","Bad Boy Badsy");
vs[3].removeProperty("age");
newTx();
vs[0] = tx.getVertex(vs[0].getLongId());
vs[0].setProperty("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,TimeUnit.MILLISECONDS);
//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");
// Vertex 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");
assertEquals(1,recoveryStats[0]); //schema transaction was successful
assertEquals(4,recoveryStats[1]); //all 4 index transaction had provoked errors in the indexing backend
}