Search in sources :

Example 1 with FakeObjects

use of com.baidu.hugegraph.unit.FakeObjects in project incubator-hugegraph by apache.

the class CachedSchemaTransactionTest method testEventClear.

@Test
public void testEventClear() throws Exception {
    CachedSchemaTransaction cache = this.cache();
    FakeObjects objects = new FakeObjects("unit-test");
    cache.addPropertyKey(objects.newPropertyKey(IdGenerator.of(1), "fake-pk-1"));
    cache.addPropertyKey(objects.newPropertyKey(IdGenerator.of(2), "fake-pk-2"));
    Assert.assertEquals(2L, Whitebox.invoke(cache, "idCache", "size"));
    Assert.assertEquals(2L, Whitebox.invoke(cache, "nameCache", "size"));
    Assert.assertEquals("fake-pk-1", cache.getPropertyKey(IdGenerator.of(1)).name());
    Assert.assertEquals(IdGenerator.of(1), cache.getPropertyKey("fake-pk-1").id());
    Assert.assertEquals("fake-pk-2", cache.getPropertyKey(IdGenerator.of(2)).name());
    Assert.assertEquals(IdGenerator.of(2), cache.getPropertyKey("fake-pk-2").id());
    this.params.schemaEventHub().notify(Events.CACHE, "clear", null).get();
    Assert.assertEquals(0L, Whitebox.invoke(cache, "idCache", "size"));
    Assert.assertEquals(0L, Whitebox.invoke(cache, "nameCache", "size"));
    Assert.assertEquals("fake-pk-1", cache.getPropertyKey(IdGenerator.of(1)).name());
    Assert.assertEquals(IdGenerator.of(1), cache.getPropertyKey("fake-pk-1").id());
    Assert.assertEquals("fake-pk-2", cache.getPropertyKey(IdGenerator.of(2)).name());
    Assert.assertEquals(IdGenerator.of(2), cache.getPropertyKey("fake-pk-2").id());
    Assert.assertEquals(2L, Whitebox.invoke(cache, "idCache", "size"));
    Assert.assertEquals(2L, Whitebox.invoke(cache, "nameCache", "size"));
}
Also used : FakeObjects(com.baidu.hugegraph.unit.FakeObjects) CachedSchemaTransaction(com.baidu.hugegraph.backend.cache.CachedSchemaTransaction) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 2 with FakeObjects

use of com.baidu.hugegraph.unit.FakeObjects in project incubator-hugegraph by apache.

the class BinaryScatterSerializerTest method testVertex.

@Test
public void testVertex() {
    HugeConfig config = FakeObjects.newConfig();
    BinaryScatterSerializer ser = new BinaryScatterSerializer(config);
    HugeEdge edge = new FakeObjects().newEdge(123, 456);
    BackendEntry entry1 = ser.writeVertex(edge.sourceVertex());
    HugeVertex vertex1 = ser.readVertex(edge.graph(), entry1);
    Assert.assertEquals(edge.sourceVertex(), vertex1);
    assertCollectionEquals(edge.sourceVertex().getProperties(), vertex1.getProperties());
    BackendEntry entry2 = ser.writeVertex(edge.targetVertex());
    HugeVertex vertex2 = ser.readVertex(edge.graph(), entry2);
    Assert.assertEquals(edge.targetVertex(), vertex2);
    assertCollectionEquals(edge.targetVertex().getProperties(), vertex2.getProperties());
    Whitebox.setInternalState(vertex2, "removed", true);
    Assert.assertTrue(vertex2.removed());
    BackendEntry entry3 = ser.writeVertex(vertex2);
    Assert.assertEquals(0, entry3.columnsSize());
    Assert.assertNull(ser.readVertex(edge.graph(), null));
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) BinaryScatterSerializer(com.baidu.hugegraph.backend.serializer.BinaryScatterSerializer) FakeObjects(com.baidu.hugegraph.unit.FakeObjects) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeConfig(com.baidu.hugegraph.config.HugeConfig) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 3 with FakeObjects

use of com.baidu.hugegraph.unit.FakeObjects in project incubator-hugegraph by apache.

the class RolePermissionTest method testHugeResourceFilterSchema.

@Test
public void testHugeResourceFilterSchema() {
    HugeResource all = HugeResource.ALL;
    HugeResource schema = new HugeResource(ResourceType.SCHEMA, HugeResource.ANY, null);
    HugeResource vlPrefix = new HugeResource(ResourceType.VERTEX_LABEL, "p-.*", null);
    ResourceObject<?> r3 = ResourceObject.of("g1", ResourceType.VERTEX_LABEL, NameObject.of("test"));
    Assert.assertTrue(all.filter(r3));
    Assert.assertTrue(schema.filter(r3));
    Assert.assertFalse(vlPrefix.filter(r3));
    ResourceObject<?> r4 = ResourceObject.of("g1", ResourceType.VERTEX_LABEL, NameObject.of("p-test"));
    Assert.assertTrue(all.filter(r4));
    Assert.assertTrue(schema.filter(r4));
    Assert.assertTrue(vlPrefix.filter(r4));
    FakeObjects fo = new FakeObjects();
    VertexLabel vl1 = fo.newVertexLabel(IdGenerator.of("id1"), "person", IdStrategy.PRIMARY_KEY, IdGenerator.of("1"));
    ResourceObject<?> r5 = ResourceObject.of("g1", vl1);
    Assert.assertTrue(all.filter(r5));
    Assert.assertTrue(schema.filter(r5));
    Assert.assertFalse(vlPrefix.filter(r5));
    VertexLabel vl2 = fo.newVertexLabel(IdGenerator.of("id1"), "p-person", IdStrategy.PRIMARY_KEY, IdGenerator.of("1"));
    ResourceObject<?> r6 = ResourceObject.of("g1", vl2);
    Assert.assertTrue(all.filter(r6));
    Assert.assertTrue(schema.filter(r6));
    Assert.assertTrue(vlPrefix.filter(r6));
}
Also used : FakeObjects(com.baidu.hugegraph.unit.FakeObjects) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) HugeResource(com.baidu.hugegraph.auth.HugeResource) Test(org.junit.Test)

Example 4 with FakeObjects

use of com.baidu.hugegraph.unit.FakeObjects in project incubator-hugegraph by apache.

the class RolePermissionTest method testHugeResourceFilterVertexOrEdge.

@Test
public void testHugeResourceFilterVertexOrEdge() {
    HugeResource all = HugeResource.ALL;
    // vertex & edge
    FakeObjects fo = new FakeObjects();
    HugeEdge edge = fo.newEdge(1, 2);
    ResourceObject<?> r1 = ResourceObject.of("g1", edge.sourceVertex());
    ResourceObject<?> r2 = ResourceObject.of("g1", edge.targetVertex());
    ResourceObject<?> r3 = ResourceObject.of("g1", edge);
    Assert.assertTrue(all.filter(r1));
    Assert.assertTrue(all.filter(r2));
    Assert.assertTrue(all.filter(r3));
    HugeResource vr = new HugeResource(ResourceType.VERTEX, HugeResource.ANY, null);
    Assert.assertTrue(vr.filter(r1));
    Assert.assertTrue(vr.filter(r2));
    Assert.assertFalse(vr.filter(r3));
    vr = new HugeResource(ResourceType.VERTEX, "person", null);
    Assert.assertTrue(vr.filter(r1));
    Assert.assertTrue(vr.filter(r2));
    Assert.assertFalse(vr.filter(r3));
    vr = new HugeResource(ResourceType.VERTEX, "person", ImmutableMap.of("city", "Beijing"));
    Assert.assertTrue(vr.filter(r1));
    Assert.assertFalse(vr.filter(r2));
    Assert.assertFalse(vr.filter(r3));
    vr = new HugeResource(ResourceType.VERTEX, "person", ImmutableMap.of("city", "Shanghai"));
    Assert.assertFalse(vr.filter(r1));
    Assert.assertTrue(vr.filter(r2));
    Assert.assertFalse(vr.filter(r3));
    vr = new HugeResource(ResourceType.VERTEX, "person", ImmutableMap.of("city", "P.within(\"Beijing\", \"Shanghai\")"));
    Assert.assertTrue(vr.filter(r1));
    Assert.assertTrue(vr.filter(r2));
    Assert.assertFalse(vr.filter(r3));
    vr = new HugeResource(ResourceType.VERTEX, "person", ImmutableMap.of("age", "P.gt(18)"));
    Assert.assertFalse(vr.filter(r1));
    Assert.assertTrue(vr.filter(r2));
    Assert.assertFalse(vr.filter(r3));
    vr = new HugeResource(ResourceType.VERTEX, "person", ImmutableMap.of("age", "P.between(20, 21)"));
    Assert.assertFalse(vr.filter(r1));
    Assert.assertTrue(vr.filter(r2));
    Assert.assertFalse(vr.filter(r3));
    vr = new HugeResource(ResourceType.VERTEX, "person", ImmutableMap.of("age", "P.between(18, 21)"));
    Assert.assertTrue(vr.filter(r1));
    Assert.assertTrue(vr.filter(r2));
    Assert.assertFalse(vr.filter(r3));
    HugeResource er = new HugeResource(ResourceType.EDGE, "knows", null);
    Assert.assertFalse(er.filter(r1));
    Assert.assertFalse(er.filter(r2));
    Assert.assertTrue(er.filter(r3));
    er = new HugeResource(ResourceType.EDGE, "knows", ImmutableMap.of("weight", "P.gt(0.7)"));
    Assert.assertFalse(er.filter(r1));
    Assert.assertFalse(er.filter(r2));
    Assert.assertTrue(er.filter(r3));
    er = new HugeResource(ResourceType.EDGE, "knows", ImmutableMap.of("weight", "P.gt(0.8)"));
    Assert.assertFalse(er.filter(r1));
    Assert.assertFalse(er.filter(r2));
    Assert.assertFalse(er.filter(r3));
    er = new HugeResource(ResourceType.EDGE, "knows", ImmutableMap.of("weight", "P.lt(0.8)"));
    Assert.assertFalse(er.filter(r1));
    Assert.assertFalse(er.filter(r2));
    Assert.assertTrue(er.filter(r3));
}
Also used : FakeObjects(com.baidu.hugegraph.unit.FakeObjects) HugeResource(com.baidu.hugegraph.auth.HugeResource) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Test(org.junit.Test)

Example 5 with FakeObjects

use of com.baidu.hugegraph.unit.FakeObjects in project incubator-hugegraph by apache.

the class BinarySerializerTest method testVertexForPartition.

@Test
public void testVertexForPartition() {
    BinarySerializer ser = new BinarySerializer(true, true, true);
    HugeEdge edge = new FakeObjects().newEdge("123", "456");
    BackendEntry entry1 = ser.writeVertex(edge.sourceVertex());
    HugeVertex vertex1 = ser.readVertex(edge.graph(), entry1);
    Assert.assertEquals(edge.sourceVertex(), vertex1);
    assertCollectionEquals(edge.sourceVertex().getProperties(), vertex1.getProperties());
    BackendEntry entry2 = ser.writeVertex(edge.targetVertex());
    HugeVertex vertex2 = ser.readVertex(edge.graph(), entry2);
    Assert.assertEquals(edge.targetVertex(), vertex2);
    assertCollectionEquals(edge.targetVertex().getProperties(), vertex2.getProperties());
    Whitebox.setInternalState(vertex2, "removed", true);
    Assert.assertTrue(vertex2.removed());
    BackendEntry entry3 = ser.writeVertex(vertex2);
    Assert.assertEquals(0, entry3.columnsSize());
    Assert.assertNull(ser.readVertex(edge.graph(), null));
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) FakeObjects(com.baidu.hugegraph.unit.FakeObjects) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) BinarySerializer(com.baidu.hugegraph.backend.serializer.BinarySerializer) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Aggregations

FakeObjects (com.baidu.hugegraph.unit.FakeObjects)19 Test (org.junit.Test)19 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)16 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)9 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)8 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)7 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)7 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)6 CachedSchemaTransaction (com.baidu.hugegraph.backend.cache.CachedSchemaTransaction)4 BinarySerializer (com.baidu.hugegraph.backend.serializer.BinarySerializer)4 HugeConfig (com.baidu.hugegraph.config.HugeConfig)4 Id (com.baidu.hugegraph.backend.id.Id)3 HugeResource (com.baidu.hugegraph.auth.HugeResource)2 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)2 BinaryBackendEntry (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)2 BinaryScatterSerializer (com.baidu.hugegraph.backend.serializer.BinaryScatterSerializer)2 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)2 HugeProperty (com.baidu.hugegraph.structure.HugeProperty)2 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)1 Date (java.util.Date)1