Search in sources :

Example 11 with FakeObjects

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

the class CachedSchemaTransactionTest method testEventInvalid.

@Test
public void testEventInvalid() 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, "invalid", HugeType.PROPERTY_KEY, IdGenerator.of(1)).get();
    Assert.assertEquals(1L, Whitebox.invoke(cache, "idCache", "size"));
    Assert.assertEquals(1L, 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 12 with FakeObjects

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

the class CachedSchemaTransactionTest method testResetCachedAllIfReachedCapacity.

@Test
public void testResetCachedAllIfReachedCapacity() throws Exception {
    CachedSchemaTransaction cache = this.cache();
    Object old = Whitebox.getInternalState(cache, "idCache.capacity");
    Whitebox.setInternalState(cache, "idCache.capacity", 2);
    try {
        Assert.assertEquals(0L, Whitebox.invoke(cache, "idCache", "size"));
        FakeObjects objects = new FakeObjects("unit-test");
        cache.addPropertyKey(objects.newPropertyKey(IdGenerator.of(1), "fake-pk-1"));
        Assert.assertEquals(1L, Whitebox.invoke(cache, "idCache", "size"));
        Assert.assertEquals(1, cache.getPropertyKeys().size());
        Whitebox.invoke(CachedSchemaTransaction.class, "cachedTypes", cache);
        Assert.assertEquals(ImmutableMap.of(HugeType.PROPERTY_KEY, true), Whitebox.invoke(CachedSchemaTransaction.class, "cachedTypes", cache));
        cache.addPropertyKey(objects.newPropertyKey(IdGenerator.of(3), "fake-pk-2"));
        cache.addPropertyKey(objects.newPropertyKey(IdGenerator.of(2), "fake-pk-3"));
        Assert.assertEquals(2L, Whitebox.invoke(cache, "idCache", "size"));
        Assert.assertEquals(3, cache.getPropertyKeys().size());
        Assert.assertEquals(ImmutableMap.of(), Whitebox.invoke(CachedSchemaTransaction.class, "cachedTypes", cache));
    } finally {
        Whitebox.setInternalState(cache, "idCache.capacity", old);
    }
}
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 13 with FakeObjects

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

the class CachedSchemaTransactionTest method testGetSchema.

@Test
public void testGetSchema() throws Exception {
    CachedSchemaTransaction cache = this.cache();
    FakeObjects objects = new FakeObjects("unit-test");
    cache.addPropertyKey(objects.newPropertyKey(IdGenerator.of(1), "fake-pk-1"));
    this.params.schemaEventHub().notify(Events.CACHE, "clear", null).get();
    Assert.assertEquals("fake-pk-1", cache.getPropertyKey(IdGenerator.of(1)).name());
    Assert.assertEquals(IdGenerator.of(1), cache.getPropertyKey("fake-pk-1").id());
    this.params.schemaEventHub().notify(Events.CACHE, "clear", null).get();
    Assert.assertEquals(IdGenerator.of(1), cache.getPropertyKey("fake-pk-1").id());
    Assert.assertEquals("fake-pk-1", cache.getPropertyKey(IdGenerator.of(1)).name());
}
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 14 with FakeObjects

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

the class JsonUtilTest method testSerializeEdge.

@Test
public void testSerializeEdge() {
    FakeObjects fakeObject = new FakeObjects();
    PropertyKey name = fakeObject.newPropertyKey(IdGenerator.of(1), "name");
    PropertyKey age = fakeObject.newPropertyKey(IdGenerator.of(2), "age", DataType.INT, Cardinality.SINGLE);
    PropertyKey city = fakeObject.newPropertyKey(IdGenerator.of(3), "city");
    PropertyKey date = fakeObject.newPropertyKey(IdGenerator.of(4), "date", DataType.DATE);
    PropertyKey weight = fakeObject.newPropertyKey(IdGenerator.of(5), "weight", DataType.DOUBLE);
    VertexLabel vl = fakeObject.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
    EdgeLabel el = fakeObject.newEdgeLabel(IdGenerator.of(1), "knows", Frequency.SINGLE, vl.id(), vl.id(), date.id(), weight.id());
    HugeVertex source = new HugeVertex(fakeObject.graph(), IdGenerator.of(123456), vl);
    HugeVertex target = new HugeVertex(fakeObject.graph(), IdGenerator.of(987654), vl);
    Id id = EdgeId.parse("L123456>1>>L987654");
    HugeEdge edge = new HugeEdge(fakeObject.graph(), id, el);
    Whitebox.setInternalState(edge, "sourceVertex", source);
    Whitebox.setInternalState(edge, "targetVertex", target);
    Date dateValue = Utils.date("2019-03-12");
    MutableIntObjectMap<HugeProperty<?>> properties = CollectionFactory.newIntObjectMap(date.id(), new HugeEdgeProperty<>(edge, date, dateValue), weight.id(), new HugeEdgeProperty<>(edge, weight, 0.8));
    Whitebox.setInternalState(edge, "properties", properties);
    String json = JsonUtil.toJson(edge);
    Assert.assertEquals("{\"id\":\"L123456>1>>L987654\"," + "\"label\":\"knows\",\"type\":\"edge\"," + "\"outV\":123456,\"outVLabel\":\"person\"," + "\"inV\":987654,\"inVLabel\":\"person\"," + "\"properties\":{\"date\":" + "\"2019-03-12 00:00:00.000\"," + "\"weight\":0.8}}", json);
}
Also used : HugeProperty(com.baidu.hugegraph.structure.HugeProperty) FakeObjects(com.baidu.hugegraph.unit.FakeObjects) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Date(java.util.Date) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 15 with FakeObjects

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

the class JsonUtilTest method testSerializeVertexLabel.

@Test
public void testSerializeVertexLabel() {
    FakeObjects fakeObject = new FakeObjects();
    PropertyKey name = fakeObject.newPropertyKey(IdGenerator.of(1), "name");
    PropertyKey age = fakeObject.newPropertyKey(IdGenerator.of(2), "age", DataType.INT, Cardinality.SINGLE);
    PropertyKey city = fakeObject.newPropertyKey(IdGenerator.of(3), "city");
    VertexLabel vl = fakeObject.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
    Mockito.when(fakeObject.graph().mapPkId2Name(vl.properties())).thenReturn(Arrays.asList(name.name(), age.name(), city.name()));
    String json = JsonUtil.toJson(vl);
    Assert.assertEquals("{\"id\":1,\"name\":\"person\"," + "\"id_strategy\":\"CUSTOMIZE_NUMBER\"," + "\"primary_keys\":[],\"nullable_keys\":[]," + "\"index_labels\":[]," + "\"properties\":[\"name\",\"age\",\"city\"]," + "\"status\":\"CREATED\"," + "\"ttl\":0,\"enable_label_index\":true," + "\"user_data\":{}}", json);
}
Also used : FakeObjects(com.baidu.hugegraph.unit.FakeObjects) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) 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