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"));
}
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);
}
}
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());
}
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);
}
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);
}
Aggregations