use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class GraphDatabaseConfigurationInstanceIdTest method graphShouldNotOpenWithSameInstanceId.
@Disabled("Not working anymore. The bug is tracked here: https://github.com/JanusGraph/janusgraph/issues/2696")
@Test
public void graphShouldNotOpenWithSameInstanceId() {
final Map<String, Object> map = getStorageConfiguration();
map.put(UNIQUE_INSTANCE_ID.toStringWithoutRoot(), NON_UNIQUE_INSTANCE_ID);
final MapConfiguration config = ConfigurationUtil.loadMapConfiguration(map);
final StandardJanusGraph graph1 = new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(new CommonsConfiguration(config)));
assertEquals(1, graph1.openManagement().getOpenInstances().size());
assertEquals(NON_UNIQUE_CURRENT_INSTANCE_ID, graph1.openManagement().getOpenInstances().iterator().next());
JanusGraphException janusGraphException = assertThrows(JanusGraphException.class, () -> {
final StandardJanusGraph graph2 = new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(new CommonsConfiguration(config)));
graph1.close();
});
assertEquals("A JanusGraph graph with the same instance id [" + NON_UNIQUE_INSTANCE_ID + "] is already open. Might required forced shutdown.", janusGraphException.getMessage());
}
use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class StandardJanusGraphTxTest method createTxWithMockedInternals.
private StandardJanusGraphTx createTxWithMockedInternals() throws BackendException {
StandardJanusGraph mockGraph = createMock(StandardJanusGraph.class);
TransactionConfiguration txConfig = createMock(TransactionConfiguration.class);
GraphDatabaseConfiguration gdbConfig = createMock(GraphDatabaseConfiguration.class);
BackendTransaction txHandle = createMock(BackendTransaction.class);
TimestampProvider tsProvider = createMock(TimestampProvider.class);
Serializer mockSerializer = createMock(Serializer.class);
EdgeSerializer mockEdgeSerializer = createMock(EdgeSerializer.class);
IndexSerializer mockIndexSerializer = createMock(IndexSerializer.class);
RelationType relationType = createMock(RelationType.class);
IDManager idManager = createMock(IDManager.class);
PropertyKey propertyKey = createMock(PropertyKey.class);
DefaultSchemaMaker defaultSchemaMaker = createMock(DefaultSchemaMaker.class);
IndexSelectionStrategy indexSelectionStrategy = createMock(ThresholdBasedIndexSelectionStrategy.class);
expect(mockGraph.getConfiguration()).andReturn(gdbConfig);
expect(mockGraph.isOpen()).andReturn(true).anyTimes();
expect(mockGraph.getDataSerializer()).andReturn(mockSerializer);
expect(mockGraph.getEdgeSerializer()).andReturn(mockEdgeSerializer);
expect(mockGraph.getIndexSerializer()).andReturn(mockIndexSerializer);
expect(mockGraph.getIDManager()).andReturn(idManager);
expect(mockGraph.getIndexSelector()).andReturn(indexSelectionStrategy);
mockGraph.closeTransaction(isA(StandardJanusGraphTx.class));
EasyMock.expectLastCall().anyTimes();
expect(gdbConfig.getTimestampProvider()).andReturn(tsProvider);
expect(txConfig.isSingleThreaded()).andReturn(true);
expect(txConfig.hasPreloadedData()).andReturn(false);
expect(txConfig.hasVerifyExternalVertexExistence()).andReturn(false);
expect(txConfig.hasVerifyInternalVertexExistence()).andReturn(false);
expect(txConfig.getVertexCacheSize()).andReturn(6);
expect(txConfig.isReadOnly()).andReturn(true);
expect(txConfig.getDirtyVertexSize()).andReturn(2);
expect(txConfig.getIndexCacheWeight()).andReturn(2L);
expect(txConfig.getGroupName()).andReturn(null).anyTimes();
expect(txConfig.getAutoSchemaMaker()).andReturn(defaultSchemaMaker);
expect(defaultSchemaMaker.makePropertyKey(isA(PropertyKeyMaker.class), notNull())).andReturn(propertyKey);
expect(relationType.isPropertyKey()).andReturn(false);
expect(propertyKey.isPropertyKey()).andReturn(true);
txHandle.rollback();
EasyMock.expectLastCall().anyTimes();
replayAll();
StandardJanusGraphTx partialMock = createMockBuilder(StandardJanusGraphTx.class).withConstructor(mockGraph, txConfig).addMockedMethod("getRelationType").createMock();
partialMock.setBackendTransaction(txHandle);
expect(partialMock.getRelationType("Foo")).andReturn(null);
expect(partialMock.getRelationType("Qux")).andReturn(propertyKey);
expect(partialMock.getRelationType("Baz")).andReturn(relationType);
replay(partialMock);
return partialMock;
}
use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class StandardVertexTest method modifiedVertexShouldNotEvictedFromCache.
@Test
public void modifiedVertexShouldNotEvictedFromCache() {
for (int i = 0; i < 50; i++) {
try (StandardJanusGraph g = (StandardJanusGraph) JanusGraphFactory.build().set("storage.backend", "inmemory").set("cache.tx-cache-size", 0).open()) {
Vertex v1 = g.traversal().addV().next();
Vertex v2 = g.traversal().addV().next();
v1.addEdge("E", v2);
g.tx().commit();
g.tx().close();
for (int k = 0; k < 120; k++) {
g.traversal().addV().next();
}
g.tx().commit();
g.tx().close();
g.traversal().E().drop().iterate();
g.traversal().E().drop().iterate();
}
}
}
use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class CQLConfigTest method shouldGracefullyCloseGraphWhichLostAConnection.
@Test
public void shouldGracefullyCloseGraphWhichLostAConnection() {
WriteConfiguration wc = getConfiguration();
wc.set(ConfigElement.getPath(EXECUTOR_SERVICE_MAX_SHUTDOWN_WAIT_TIME), 60000);
wc.set(ConfigElement.getPath(PARALLEL_BACKEND_EXECUTOR_SERVICE_MAX_SHUTDOWN_WAIT_TIME), 60000);
wc.set(ConfigElement.getPath(IDS_RENEW_TIMEOUT), 10000);
wc.set(ConfigElement.getPath(CONNECTION_TIMEOUT), 10000);
wc.set(ConfigElement.getPath(HEARTBEAT_TIMEOUT), 10000);
if (graph != null && graph.isOpen()) {
graph.close();
}
Set<Thread> threadsFromPossibleOtherOpenedConnections = Thread.getAllStackTraces().keySet().stream().filter(thread -> {
String threadNameLowercase = thread.getName().toLowerCase();
return thread.isAlive() && (threadNameLowercase.startsWith("cql") || threadNameLowercase.startsWith("janusgraph"));
}).collect(Collectors.toSet());
boolean flakyTest = !threadsFromPossibleOtherOpenedConnections.isEmpty();
graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
assertDoesNotThrow(() -> {
graph.traversal().V().hasNext();
graph.tx().rollback();
});
Set<Thread> threadsToAwait = Thread.getAllStackTraces().keySet().stream().filter(thread -> {
String threadNameLowercase = thread.getName().toLowerCase();
return thread.isAlive() && !threadsFromPossibleOtherOpenedConnections.contains(thread) && (threadNameLowercase.startsWith("cql") || threadNameLowercase.startsWith("janusgraph"));
}).collect(Collectors.toSet());
cqlContainer.stop();
graph.close();
for (Thread thread : threadsToAwait) {
if (thread.isAlive()) {
if (flakyTest) {
log.warn("Test shouldGracefullyCloseGraphWhichLostAConnection is currently running in flaky mode " + "because there were open instances available before the test started. " + "Thus, we don't fail this test because we can't be sure that current thread {} " + "is leaked or were created by other JanusGraph instances.", thread.getName());
} else {
fail("Thread " + thread.getName() + " was alive but expected to be terminated");
}
}
}
}
use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.
the class CQLConfigTest method shouldFailDueToSmallTimeout.
@Test
public void shouldFailDueToSmallTimeout() {
try {
WriteConfiguration wc = getConfiguration();
wc.set(ConfigElement.getPath(REQUEST_TIMEOUT), 1);
wc.set(ConfigElement.getPath(NETTY_TIMER_TICK_DURATION), 1);
try (StandardJanusGraph graph = (StandardJanusGraph) JanusGraphFactory.open(wc)) {
GraphTraversalSource graphTraversalSource = graph.traversal();
for (int i = 0; i < 200; i++) {
graphTraversalSource.addV().property("name", "world").property("age", 123).property("id", i);
}
graphTraversalSource.tx().commit();
graphTraversalSource.V().has("id", P.lte(195)).valueMap().with(WithOptions.tokens, WithOptions.ids).toList();
graphTraversalSource.tx().rollback();
}
// This test should fail, but it is very flaky, thus, we don't fail it even if we reached this point.
// fail()
} catch (Throwable throwable) {
// the throwable is expected
}
}
Aggregations