use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class JanusGraphTest method testVertexCentricEdgeIndexOnSimpleMultiplicityShouldWork.
@Test
public void testVertexCentricEdgeIndexOnSimpleMultiplicityShouldWork() {
clopen(option(LOG_SEND_DELAY, MANAGEMENT_LOG), Duration.ofMillis(0), option(KCVSLog.LOG_READ_LAG_TIME, MANAGEMENT_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, MANAGEMENT_LOG), Duration.ofMillis(250));
PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
EdgeLabel friend = mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.SIMPLE).make();
mgmt.buildEdgeIndex(friend, "byTime", Direction.OUT, decr, time);
finishSchema();
assertEquals(SchemaStatus.ENABLED, mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime").getIndexStatus());
JanusGraphVertex v = tx.addVertex();
v = getV(tx, v);
for (int i = 200; i < 210; i++) {
JanusGraphVertex o = tx.addVertex();
v.addEdge("friend", o, "time", i);
}
evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 199, 210).orderBy("time", decr), EDGE, 10, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC);
tx.commit();
finishSchema();
}
use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testEdgeTTLWithMixedIndices.
@Test
public void testEdgeTTLWithMixedIndices() throws Exception {
if (!features.hasCellTTL() || !indexFeatures.supportsDocumentTTL()) {
return;
}
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
PropertyKey text = mgmt.makePropertyKey("text").dataType(String.class).make();
PropertyKey time = makeKey("time", Long.class);
EdgeLabel label = mgmt.makeEdgeLabel("likes").make();
final int likesTTLSeconds = (int) TestGraphConfigs.getTTL(TimeUnit.SECONDS);
mgmt.setTTL(label, Duration.ofSeconds(likesTTLSeconds));
mgmt.buildIndex("index1", Edge.class).addKey(name, getStringMapping()).addKey(time).buildMixedIndex(INDEX);
mgmt.buildIndex("index2", Edge.class).indexOnly(label).addKey(text, getTextMapping()).buildMixedIndex(INDEX);
assertEquals(Duration.ZERO, mgmt.getTTL(name));
assertEquals(Duration.ofSeconds(likesTTLSeconds), mgmt.getTTL(label));
finishSchema();
JanusGraphVertex v1 = tx.addVertex(), v2 = tx.addVertex(), v3 = tx.addVertex();
Edge e1 = v1.addEdge("likes", v2, "name", "v1 likes v2", "text", "this will help to identify the edge");
long time1 = System.currentTimeMillis();
e1.property("time", time1);
Edge e2 = v2.addEdge("likes", v3, "name", "v2 likes v3", "text", "this won't match anything");
long time2 = time1 + 1;
e2.property("time", time2);
tx.commit();
clopen();
Object e1Id = e1.id();
e2.id();
evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "likes"), ElementCategory.EDGE, 1, new boolean[] { true, true }, "index2");
evaluateQuery(tx.query().has("name", "v2 likes v3").orderBy("time", decr), ElementCategory.EDGE, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC, "index1");
v1 = getV(tx, v1.id());
v2 = getV(tx, v2.id());
v3 = getV(tx, v3.id());
e1 = getE(tx, e1Id);
e2 = getE(tx, e1Id);
assertNotNull(v1);
assertNotNull(v2);
assertNotNull(v3);
assertNotNull(e1);
assertNotNull(e2);
assertNotEmpty(v1.query().direction(Direction.OUT).edges());
assertNotEmpty(v2.query().direction(Direction.OUT).edges());
Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(likesTTLSeconds * 1.25), TimeUnit.SECONDS));
clopen();
// ...indexes have expired
evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "likes"), ElementCategory.EDGE, 0, new boolean[] { true, true }, "index2");
evaluateQuery(tx.query().has("name", "v2 likes v3").orderBy("time", decr), ElementCategory.EDGE, 0, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC, "index1");
v1 = getV(tx, v1.id());
v2 = getV(tx, v2.id());
v3 = getV(tx, v3.id());
e1 = getE(tx, e1Id);
e2 = getE(tx, e1Id);
assertNotNull(v1);
assertNotNull(v2);
assertNotNull(v3);
// edges have expired from the graph...
assertNull(e1);
assertNull(e2);
assertEmpty(v1.query().direction(Direction.OUT).edges());
assertEmpty(v2.query().direction(Direction.OUT).edges());
}
use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testBooleanIndexing.
/**
* Tests indexing boolean
*/
@Test
public void testBooleanIndexing() {
PropertyKey name = makeKey("visible", Boolean.class);
mgmt.buildIndex("booleanIndex", Vertex.class).addKey(name).buildMixedIndex(INDEX);
finishSchema();
clopen();
JanusGraphVertex v1 = graph.addVertex();
v1.property("visible", true);
JanusGraphVertex v2 = graph.addVertex();
v2.property("visible", false);
assertCount(2, graph.vertices());
assertEquals(v1, getOnlyVertex(graph.query().has("visible", true)));
assertEquals(v2, getOnlyVertex(graph.query().has("visible", false)));
assertEquals(v2, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, true)));
assertEquals(v1, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, false)));
// Flush the index
clopen();
assertCount(2, graph.vertices());
assertEquals(v1, getOnlyVertex(graph.query().has("visible", true)));
assertEquals(v2, getOnlyVertex(graph.query().has("visible", false)));
assertEquals(v2, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, true)));
assertEquals(v1, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, false)));
}
use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class JanusGraphAbstractAuthenticator method setup.
@Override
public void setup(final Map<String, Object> config) {
logger.info("Initializing authentication with the {}", this.getClass().getName());
Preconditions.checkArgument(config != null, String.format("Could not configure a %s - provide a 'config' in the 'authentication' settings", this.getClass().getName()));
Preconditions.checkState(config.containsKey(CONFIG_CREDENTIALS_DB), String.format("Credential configuration missing the %s key that points to a graph config file or graph name", CONFIG_CREDENTIALS_DB));
if (!config.containsKey(CONFIG_DEFAULT_USER) || !config.containsKey(CONFIG_DEFAULT_PASSWORD)) {
logger.warn(String.format("%s and %s should be defined to bootstrap authentication", CONFIG_DEFAULT_USER, CONFIG_DEFAULT_PASSWORD));
}
final JanusGraph graph = openGraph(config.get(CONFIG_CREDENTIALS_DB).toString());
backingGraph = graph;
credentialStore = createCredentialGraph(graph);
graph.tx().rollback();
ManagementSystem mgmt = (ManagementSystem) graph.openManagement();
if (!mgmt.containsGraphIndex(USERNAME_INDEX_NAME)) {
final PropertyKey username = mgmt.makePropertyKey(PROPERTY_USERNAME).dataType(String.class).cardinality(Cardinality.SINGLE).make();
mgmt.buildIndex(USERNAME_INDEX_NAME, Vertex.class).addKey(username).unique().buildCompositeIndex();
mgmt.commit();
mgmt = (ManagementSystem) graph.openManagement();
final JanusGraphIndex index = mgmt.getGraphIndex(USERNAME_INDEX_NAME);
if (!index.getIndexStatus(username).equals(SchemaStatus.ENABLED)) {
try {
mgmt = (ManagementSystem) graph.openManagement();
mgmt.updateIndex(mgmt.getGraphIndex(USERNAME_INDEX_NAME), SchemaAction.REINDEX);
ManagementSystem.awaitGraphIndexStatus(graph, USERNAME_INDEX_NAME).status(SchemaStatus.ENABLED).call();
mgmt.commit();
} catch (InterruptedException rude) {
mgmt.rollback();
throw new RuntimeException("Timed out waiting for byUsername index to be created on credential graph", rude);
}
}
}
final String defaultUser = config.get(CONFIG_DEFAULT_USER).toString();
if (credentialStore.findUser(defaultUser) == null) {
credentialStore.createUser(defaultUser, config.get(CONFIG_DEFAULT_PASSWORD).toString());
}
}
use of org.janusgraph.core.PropertyKey in project janusgraph by JanusGraph.
the class HMACAuthenticatorTest method testSetupEmptyCredGraphNoUserIndex.
@Test
public void testSetupEmptyCredGraphNoUserIndex() {
final HMACAuthenticator authenticator = createMockBuilder(HMACAuthenticator.class).addMockedMethod("openGraph").addMockedMethod("createCredentialGraph").createMock();
final Map<String, Object> configMap = new HashMap<String, Object>();
configMap.put(CONFIG_CREDENTIALS_DB, "configCredDb");
configMap.put(HMACAuthenticator.CONFIG_HMAC_SECRET, "secret");
configMap.put(HMACAuthenticator.CONFIG_DEFAULT_PASSWORD, "pass");
configMap.put(HMACAuthenticator.CONFIG_DEFAULT_USER, "user");
final JanusGraph graph = createMock(JanusGraph.class);
final CredentialGraph credentialGraph = createMock(CredentialGraph.class);
final ManagementSystem mgmt = createMock(ManagementSystem.class);
final Transaction tx = createMock(Transaction.class);
final PropertyKey pk = createMock(PropertyKey.class);
final PropertyKeyMaker pkm = createMock(PropertyKeyMaker.class);
final JanusGraphManagement.IndexBuilder indexBuilder = createMock(JanusGraphManagement.IndexBuilder.class);
final JanusGraphIndex index = createMock(JanusGraphIndex.class);
final PropertyKey[] pks = { pk };
expect(authenticator.openGraph(isA(String.class))).andReturn(graph);
expect(authenticator.createCredentialGraph(isA(JanusGraph.class))).andReturn(credentialGraph);
expect(credentialGraph.findUser("user")).andReturn(null);
expect(credentialGraph.createUser(eq("user"), eq("pass"))).andReturn(null);
expect(graph.openManagement()).andReturn(mgmt).times(2);
expect(graph.tx()).andReturn(tx);
expect(index.getFieldKeys()).andReturn(pks);
expect(index.getIndexStatus(eq(pk))).andReturn(SchemaStatus.ENABLED);
tx.rollback();
expectLastCall();
expect(mgmt.containsGraphIndex(eq("byUsername"))).andReturn(false);
expect(mgmt.makePropertyKey(PROPERTY_USERNAME)).andReturn(pkm);
expect(pkm.dataType(eq(String.class))).andReturn(pkm);
expect(pkm.cardinality(Cardinality.SINGLE)).andReturn(pkm);
expect(pkm.make()).andReturn(pk);
expect(mgmt.buildIndex(eq("byUsername"), eq(Vertex.class))).andReturn(indexBuilder);
expect(mgmt.getGraphIndex(eq("byUsername"))).andReturn(index);
expect(indexBuilder.addKey(eq(pk))).andReturn(indexBuilder);
expect(indexBuilder.unique()).andReturn(indexBuilder);
expect(indexBuilder.buildCompositeIndex()).andReturn(index);
mgmt.commit();
expectLastCall();
mgmt.rollback();
expectLastCall();
replayAll();
authenticator.setup(configMap);
}
Aggregations