com.baidu.hugegraph.testutil.Assert Java Examples
The following examples show how to use
com.baidu.hugegraph.testutil.Assert.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VertexApiTest.java From hugegraph-client with Apache License 2.0 | 6 votes |
@Test public void testGetWithCustomizeNumberId() { schema().vertexLabel("log") .useCustomizeNumberId() .properties("date") .ifNotExist() .create(); Vertex vertex1 = new Vertex("log"); vertex1.id(123456); vertex1.property("date", "2018-01-01"); vertex1 = vertexAPI.create(vertex1); Vertex vertex2 = vertexAPI.get(123456); Assert.assertEquals(vertex1.id(), vertex2.id()); Assert.assertEquals(vertex1.label(), vertex2.label()); Assert.assertEquals(vertex1.properties(), vertex2.properties()); }
Example #2
Source File: PropertyKeyCoreTest.java From hugegraph with Apache License 2.0 | 6 votes |
@Test public void testEliminatePropertyKeyWithUserdata() { SchemaManager schema = graph().schema(); PropertyKey age = schema.propertyKey("age") .userdata("min", 0) .userdata("max", 100) .create(); Assert.assertEquals(3, age.userdata().size()); Assert.assertEquals(0, age.userdata().get("min")); Assert.assertEquals(100, age.userdata().get("max")); age = schema.propertyKey("age") .userdata("max", "") .eliminate(); Assert.assertEquals(2, age.userdata().size()); Assert.assertEquals(0, age.userdata().get("min")); }
Example #3
Source File: EdgeApiTest.java From hugegraph-client with Apache License 2.0 | 6 votes |
@Test public void testGet() { Object outVId = getVertexId("person", "name", "peter"); Object inVId = getVertexId("software", "name", "lop"); Edge edge1 = new Edge("created"); edge1.sourceLabel("person"); edge1.targetLabel("software"); edge1.sourceId(outVId); edge1.targetId(inVId); edge1.property("date", "2017-03-24"); edge1.property("city", "Hongkong"); edge1 = edgeAPI.create(edge1); Edge edge2 = edgeAPI.get(edge1.id()); Assert.assertEquals(edge1.label(), edge2.label()); Assert.assertEquals(edge1.sourceLabel(), edge2.sourceLabel()); Assert.assertEquals(edge1.targetLabel(), edge2.targetLabel()); Assert.assertEquals(edge1.sourceId(), edge2.sourceId()); Assert.assertEquals(edge1.targetId(), edge2.targetId()); Assert.assertEquals(edge1.properties(), edge2.properties()); }
Example #4
Source File: CachedGraphTransactionTest.java From hugegraph with Apache License 2.0 | 6 votes |
@Test public void testEventInvalid() throws Exception { CachedGraphTransaction cache = this.cache(); cache.addVertex(this.newVertex(IdGenerator.of(1))); cache.addVertex(this.newVertex(IdGenerator.of(2))); cache.commit(); Assert.assertTrue(cache.queryVertices(IdGenerator.of(1)).hasNext()); Assert.assertTrue(cache.queryVertices(IdGenerator.of(2)).hasNext()); Assert.assertEquals(2L, Whitebox.invoke(cache, "verticesCache", "size")); this.params.graphEventHub().notify(Events.CACHE, "invalid", IdGenerator.of(1)).get(); Assert.assertEquals(1L, Whitebox.invoke(cache, "verticesCache", "size")); Assert.assertTrue(cache.queryVertices(IdGenerator.of(2)).hasNext()); Assert.assertEquals(1L, Whitebox.invoke(cache, "verticesCache", "size")); Assert.assertTrue(cache.queryVertices(IdGenerator.of(1)).hasNext()); Assert.assertEquals(2L, Whitebox.invoke(cache, "verticesCache", "size")); }
Example #5
Source File: GroupApiTest.java From hugegraph-client with Apache License 2.0 | 6 votes |
@Test public void testGet() { Group group1 = createGroup("test1", "description 1"); Group group2 = createGroup("test2", "description 2"); Assert.assertEquals("description 1", group1.description()); Assert.assertEquals("description 2", group2.description()); group1 = api.get(group1.id()); group2 = api.get(group2.id()); Assert.assertEquals("test1", group1.name()); Assert.assertEquals("description 1", group1.description()); Assert.assertEquals("test2", group2.name()); Assert.assertEquals("description 2", group2.description()); }
Example #6
Source File: AllShortestPathsApiTest.java From hugegraph-client with Apache License 2.0 | 6 votes |
@Test public void testAllShortestPathWithLabel() { List<Path> paths = allShortestPathsAPI.get(1, 6, Direction.BOTH, "link", 6, -1L, 0L, -1L); Assert.assertEquals(4, paths.size()); List<List<Object>> expected = ImmutableList.of( ImmutableList.of(1, 10, 11, 6), ImmutableList.of(1, 19, 20, 6), ImmutableList.of(1, 21, 22, 6), ImmutableList.of(1, 23, 24, 6) ); for (Path path : paths){ Assert.assertTrue(expected.contains(path.objects())); } }
Example #7
Source File: AccessApiTest.java From hugegraph-client with Apache License 2.0 | 6 votes |
@Test public void testGet() { Access access1 = createAccess(HugePermission.WRITE, "description 1"); Access access2 = createAccess(HugePermission.READ, "description 2"); Assert.assertEquals("description 1", access1.description()); Assert.assertEquals("description 2", access2.description()); access1 = api.get(access1.id()); access2 = api.get(access2.id()); Assert.assertEquals(group.id(), access1.group()); Assert.assertEquals(gremlin.id(), access1.target()); Assert.assertEquals(HugePermission.WRITE, access1.permission()); Assert.assertEquals("description 1", access1.description()); Assert.assertEquals(group.id(), access2.group()); Assert.assertEquals(gremlin.id(), access2.target()); Assert.assertEquals(HugePermission.READ, access2.permission()); Assert.assertEquals("description 2", access2.description()); }
Example #8
Source File: VertexLabelTest.java From hugegraph-client with Apache License 2.0 | 6 votes |
@Test public void testAddVertexLabelWithUserData() { SchemaManager schema = schema(); VertexLabel player = schema.vertexLabel("player") .properties("name") .userdata("super_vl", "person") .create(); Assert.assertEquals(2, player.userdata().size()); Assert.assertEquals("person", player.userdata().get("super_vl")); String time = (String) player.userdata().get("~create_time"); Date createTime = DateUtil.parse(time); Assert.assertTrue(createTime.before(DateUtil.now())); VertexLabel runner = schema.vertexLabel("runner") .properties("name") .userdata("super_vl", "person") .userdata("super_vl", "player") .create(); // The same key user data will be overwritten Assert.assertEquals(2, runner.userdata().size()); Assert.assertEquals("player", runner.userdata().get("super_vl")); time = (String) runner.userdata().get("~create_time"); createTime = DateUtil.parse(time); Assert.assertTrue(createTime.before(DateUtil.now())); }
Example #9
Source File: HDFSLoadTest.java From hugegraph-loader with Apache License 2.0 | 6 votes |
@Test public void testHDFSWithCoreSitePath() { ioUtil.write("vertex_person.csv", "name,age,city", "marko,29,Beijing", "vadas,27,Hongkong", "josh,32,Beijing", "peter,35,Shanghai", "\"li,nary\",26,\"Wu,han\""); String[] args = new String[]{ "-f", structPath("hdfs_with_core_site_path/struct.json"), "-s", configPath("hdfs_with_core_site_path/schema.groovy"), "-g", GRAPH, "-h", SERVER, "--batch-insert-threads", "2", "--test-mode", "true" }; HugeGraphLoader loader = new HugeGraphLoader(args); loader.load(); List<Vertex> vertices = CLIENT.graph().listVertices(); Assert.assertEquals(5, vertices.size()); }
Example #10
Source File: EventHubTest.java From hugegraph-common with Apache License 2.0 | 6 votes |
@Test public void testEventRemoveListenerButNonResult() { final String event = "event-test"; EventListener listener = new EventListener() { @Override public Object event(Event arg0) { return null; } }; this.eventHub.listen(event, listener); Assert.assertTrue(this.eventHub.containsListener(event)); Assert.assertEquals(1, this.eventHub.listeners(event).size()); Assert.assertEquals(listener, this.eventHub.listeners(event).get(0)); Assert.assertEquals(0, this.eventHub.unlisten(event, null)); Assert.assertEquals(0, this.eventHub.unlisten("event-fake", listener)); Assert.assertTrue(this.eventHub.containsListener(event)); Assert.assertEquals(1, this.eventHub.listeners(event).size()); Assert.assertEquals(listener, this.eventHub.listeners(event).get(0)); }
Example #11
Source File: FileLoadTest.java From hugegraph-loader with Apache License 2.0 | 6 votes |
@Test public void testParseEmptyCsvLine() { ioUtil.write("vertex_person.csv", "name,age,city", ""); String[] args = new String[]{ "-f", structPath("parse_empty_csv_line/struct.json"), "-s", configPath("parse_empty_csv_line/schema.groovy"), "-g", GRAPH, "-h", SERVER, "--batch-insert-threads", "2", "--test-mode", "true" }; Assert.assertThrows(ParseException.class, () -> { HugeGraphLoader.main(args); }, (e) -> { Assert.assertTrue(e.getMessage().contains("Parse line '' error")); }); }
Example #12
Source File: CassandraTest.java From hugegraph with Apache License 2.0 | 6 votes |
@Test public void testParseRepilcaWithNetworkTopologyStrategy() { String strategy = CassandraOptions.CASSANDRA_STRATEGY.name(); String replica = CassandraOptions.CASSANDRA_REPLICATION.name(); Configuration conf = Mockito.mock(PropertiesConfiguration.class); Mockito.when(conf.getKeys()) .thenReturn(ImmutableList.of(strategy, replica).iterator()); Mockito.when(conf.getProperty(strategy)) .thenReturn("NetworkTopologyStrategy"); Mockito.when(conf.getProperty(replica)) .thenReturn(ImmutableList.of("dc1:2", "dc2:1")); HugeConfig config = new HugeConfig(conf); Map<String, Object> result = Whitebox.invokeStatic(CassandraStore.class, "parseReplica", config); Map<String, Object> expected = ImmutableMap.of( "class", "NetworkTopologyStrategy", "dc1", 2, "dc2", 1); Assert.assertEquals(expected, result); }
Example #13
Source File: EdgeLabelTest.java From hugegraph-client with Apache License 2.0 | 6 votes |
@Test public void testListByNames() { SchemaManager schema = schema(); EdgeLabel father = schema.edgeLabel("father") .link("person", "person") .create(); EdgeLabel write = schema.edgeLabel("write") .link("person", "book") .create(); List<EdgeLabel> edgeLabels; edgeLabels = schema.getEdgeLabels(ImmutableList.of("father")); Assert.assertEquals(1, edgeLabels.size()); assertContains(edgeLabels, father); edgeLabels = schema.getEdgeLabels(ImmutableList.of("write")); Assert.assertEquals(1, edgeLabels.size()); assertContains(edgeLabels, write); edgeLabels = schema.getEdgeLabels(ImmutableList.of("father", "write")); Assert.assertEquals(2, edgeLabels.size()); assertContains(edgeLabels, father); assertContains(edgeLabels, write); }
Example #14
Source File: EventHubTest.java From hugegraph-common with Apache License 2.0 | 6 votes |
@Test public void testEventAddListenerTwice() { final String event = "event-test"; EventListener listener = new EventListener() { @Override public Object event(Event arg0) { return null; } }; this.eventHub.listen(event, listener); this.eventHub.listen(event, listener); Assert.assertTrue(this.eventHub.containsListener(event)); Assert.assertEquals(2, this.eventHub.listeners(event).size()); Assert.assertEquals(listener, this.eventHub.listeners(event).get(0)); Assert.assertEquals(listener, this.eventHub.listeners(event).get(1)); }
Example #15
Source File: EdgeLabelCoreTest.java From hugegraph with Apache License 2.0 | 6 votes |
@Test public void testAddEdgeLabelMultipleWithoutSortKey() { super.initPropertyKeys(); SchemaManager schema = graph().schema(); schema.vertexLabel("person") .properties("name", "age", "city") .primaryKeys("name") .create(); schema.vertexLabel("author").properties("id", "name") .primaryKeys("id").create(); Assert.assertThrows(IllegalArgumentException.class, () -> { schema.edgeLabel("look").multiTimes().properties("date") .link("person", "book") .create(); }); }
Example #16
Source File: RocksDBSessionsTest.java From hugegraph with Apache License 2.0 | 6 votes |
@Test public void testDeleteByKey() throws RocksDBException { put("person:1gname", "James"); put("person:1gage", "19"); put("person:1gcity", "Beijing"); Assert.assertEquals("James", get("person:1gname")); Assert.assertEquals("19", get("person:1gage")); Assert.assertEquals("Beijing", get("person:1gcity")); this.rocks.session().remove(TABLE, b("person:1gage")); this.commit(); Assert.assertEquals("James", get("person:1gname")); Assert.assertEquals(null, get("person:1gage")); Assert.assertEquals("Beijing", get("person:1gcity")); }
Example #17
Source File: CacheTest.java From hugegraph with Apache License 2.0 | 6 votes |
@Test public void testCapacity() { Cache<Id, Object> cache = newCache(10); Assert.assertEquals(10, cache.capacity()); cache = newCache(1024); Assert.assertEquals(1024, cache.capacity()); cache = newCache(8); Assert.assertEquals(8, cache.capacity()); cache = newCache(1); Assert.assertEquals(1, cache.capacity()); cache = newCache(0); Assert.assertEquals(0, cache.capacity()); int huge = (int) (200 * Bytes.GB); cache = newCache(huge); Assert.assertEquals(huge, cache.capacity()); // The min capacity is 0 cache = newCache(-1); Assert.assertEquals(0, cache.capacity()); }
Example #18
Source File: VertexTest.java From hugegraph-client with Apache License 2.0 | 6 votes |
@Test public void testGetAllVertices() { BaseClientTest.initVertex(); List<Vertex> vertices = graph().listVertices(); Assert.assertEquals(6, vertices.size()); assertContains(vertices, T.label, "person", "name", "marko", "age", 29, "city", "Beijing"); assertContains(vertices, T.label, "person", "name", "vadas", "age", 27, "city", "Hongkong"); assertContains(vertices, T.label, "software", "name", "lop", "lang", "java", "price", 328); assertContains(vertices, T.label, "person", "name", "josh", "age", 32, "city", "Beijing"); assertContains(vertices, T.label, "software", "name", "ripple", "lang", "java", "price", 199); assertContains(vertices, T.label, "person", "name", "peter", "age", 29, "city", "Shanghai"); }
Example #19
Source File: BelongApiTest.java From hugegraph-client with Apache License 2.0 | 6 votes |
@Test public void testList() { createBelong(user1, group1, "user1 => group1"); createBelong(user1, group2, "user1 => group2"); createBelong(user2, group2, "user2 => group2"); List<Belong> belongs = api.list(null, null, -1); Assert.assertEquals(3, belongs.size()); belongs.sort((t1, t2) -> t1.description().compareTo(t2.description())); Assert.assertEquals("user1 => group1", belongs.get(0).description()); Assert.assertEquals("user1 => group2", belongs.get(1).description()); Assert.assertEquals("user2 => group2", belongs.get(2).description()); belongs = api.list(null, null, 1); Assert.assertEquals(1, belongs.size()); belongs = api.list(null, null, 2); Assert.assertEquals(2, belongs.size()); Assert.assertThrows(IllegalArgumentException.class, () -> { api.list(null, null, 0); }, e -> { Assert.assertContains("Limit must be > 0 or == -1", e.getMessage()); }); }
Example #20
Source File: CacheTest.java From hugegraph with Apache License 2.0 | 6 votes |
@Test public void testMutiThreadsGetAndUpdate() { Cache<Id, Object> cache = newCache(10); Id id1 = IdGenerator.of("1"); cache.update(id1, "value-1"); Id id2 = IdGenerator.of("2"); cache.update(id2, "value-2"); Id id3 = IdGenerator.of("3"); cache.update(id3, "value-3"); Assert.assertEquals(3, cache.size()); runWithThreads(THREADS_NUM, () -> { for (int i = 0; i < 10000 * 100; i++) { Assert.assertEquals("value-1", cache.get(id1)); Assert.assertEquals("value-2", cache.get(id2)); Assert.assertEquals("value-2", cache.get(id2)); Assert.assertEquals("value-3", cache.get(id3)); cache.update(id2, "value-2"); Assert.assertEquals("value-1", cache.get(id1)); } }); Assert.assertEquals(3, cache.size()); }
Example #21
Source File: VertexLabelApiTest.java From hugegraph-client with Apache License 2.0 | 6 votes |
@Test public void testAppend() { VertexLabel vertexLabel1 = schema().vertexLabel("person") .useAutomaticId() .properties("name", "age") .build(); vertexLabel1 = vertexLabelAPI.create(vertexLabel1); Assert.assertEquals("person", vertexLabel1.name()); Assert.assertEquals(IdStrategy.AUTOMATIC, vertexLabel1.idStrategy()); Set<String> props = ImmutableSet.of("name", "age"); Set<String> nullableKeys = ImmutableSet.of(); Assert.assertEquals(props, vertexLabel1.properties()); Assert.assertEquals(nullableKeys, vertexLabel1.nullableKeys()); VertexLabel vertexLabel2 = schema().vertexLabel("person") .properties("city") .nullableKeys("city") .build(); vertexLabel2 = vertexLabelAPI.append(vertexLabel2); Assert.assertEquals("person", vertexLabel2.name()); Assert.assertEquals(IdStrategy.AUTOMATIC, vertexLabel2.idStrategy()); props = ImmutableSet.of("name", "age", "city"); nullableKeys = ImmutableSet.of("city"); Assert.assertEquals(props, vertexLabel2.properties()); Assert.assertEquals(nullableKeys, vertexLabel2.nullableKeys()); }
Example #22
Source File: HugeConfigTest.java From hugegraph-common with Apache License 2.0 | 6 votes |
@Test public void testOptionsToString() { Assert.assertEquals("[String]group1.text1=text1-value", TestOptions.text1.toString()); Assert.assertEquals("[Integer]group1.int1=1", TestOptions.int1.toString()); Assert.assertEquals("[Long]group1.long1=100", TestOptions.long1.toString()); Assert.assertEquals("[Float]group1.float1=100.0", TestOptions.float1.toString()); Assert.assertEquals("[Double]group1.double1=100.0", TestOptions.double1.toString()); Assert.assertEquals("[Boolean]group1.bool=true", TestOptions.bool.toString()); Assert.assertEquals("[List]group1.list=[list-value1, list-value2]", TestOptions.list.toString()); Assert.assertEquals("[List]group1.map=[key1:value1, key2:value2]", TestOptions.map.toString()); Assert.assertEquals("[String]group1.text1=text1-value", TestSubOptions.text1.toString()); Assert.assertEquals("[String]group1.text2=text2-value-override", TestSubOptions.text2.toString()); Assert.assertEquals("[String]group1.textsub=textsub-value", TestSubOptions.textsub.toString()); }
Example #23
Source File: EdgeLabelCoreTest.java From hugegraph with Apache License 2.0 | 6 votes |
@Test public void testAddEdgeLabelWithSortKeyContainSameProp() { super.initPropertyKeys(); SchemaManager schema = graph().schema(); schema.vertexLabel("person") .properties("name", "age", "city") .primaryKeys("name") .create(); schema.vertexLabel("book").properties("id", "name") .primaryKeys("id") .create(); Assert.assertThrows(IllegalArgumentException.class, () -> { schema.edgeLabel("look") .multiTimes() .properties("date") .link("person", "book") .sortKeys("date", "date") .create(); }); }
Example #24
Source File: UsersTest.java From hugegraph with Apache License 2.0 | 6 votes |
@Test public void testGetUser() { HugeGraph graph = graph(); UserManager userManager = graph.userManager(); Id id = userManager.createUser(makeUser("tom", "pass1")); HugeUser user = userManager.getUser(id); Assert.assertEquals("tom", user.name()); Assert.assertEquals("pass1", user.password()); Assert.assertThrows(NotFoundException.class, () -> { userManager.getUser(IdGenerator.of("fake")); }); Assert.assertThrows(NotFoundException.class, () -> { userManager.getUser(null); }); }
Example #25
Source File: RocksDBCountersTest.java From hugegraph with Apache License 2.0 | 6 votes |
@Test public void testCounterWithMutiThreads() { final int TIMES = 1000; AtomicLong times = new AtomicLong(0); Map<Id, Boolean> ids = new ConcurrentHashMap<>(); runWithThreads(THREADS_NUM, () -> { Session session = this.rocks.session(); for (int i = 0; i < TIMES; i++) { Id id = nextId(session, HugeType.PROPERTY_KEY); Assert.assertFalse(ids.containsKey(id)); ids.put(id, true); times.incrementAndGet(); } this.rocks.close(); }); Assert.assertEquals(THREADS_NUM * TIMES, times.get()); }
Example #26
Source File: OrderLimitMapTest.java From hugegraph-common with Apache License 2.0 | 5 votes |
@Test public void testOrder() { OrderLimitMap<Integer, Double> map = new OrderLimitMap<>(5); map.put(1, 0.1); map.put(2, 0.2); map.put(3, 0.3); map.put(4, 0.4); map.put(5, 0.5); Assert.assertEquals(5, map.size()); Assert.assertEquals(ImmutableList.of(5, 4, 3, 2, 1), ImmutableList.copyOf(map.keySet())); }
Example #27
Source File: FlatMapperIteratorTest.java From hugegraph-common with Apache License 2.0 | 5 votes |
@Test public void testClose() throws Exception { CloseableItor<String> vals = new CloseableItor<>( DATA.keySet().iterator()); FlatMapperIterator<String, Integer> results; results = new FlatMapperIterator<>(vals, key -> DATA.get(key).iterator()); Assert.assertFalse(vals.closed()); results.close(); Assert.assertTrue(vals.closed()); }
Example #28
Source File: IndexLabelCoreTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testRebuildIndexOfVertexWithoutLabelIndex() { Assume.assumeFalse("Support query by label", storeFeatures().supportsQueryByLabel()); initDataWithoutLabelIndex(); // Not support query by label Assert.assertThrows(NoIndexException.class, () -> { graph().traversal().V().hasLabel("reader").toList(); }, e -> { Assert.assertTrue( e.getMessage().startsWith("Don't accept query by label") && e.getMessage().endsWith("label index is disabled")); }); // Query by property index is ok List<Vertex> vertices = graph().traversal().V() .has("city", "Shanghai").toList(); Assert.assertEquals(10, vertices.size()); graph().schema().indexLabel("readerByCity").rebuild(); vertices = graph().traversal().V() .has("city", "Shanghai").toList(); Assert.assertEquals(10, vertices.size()); }
Example #29
Source File: VertexLabelTest.java From hugegraph-client with Apache License 2.0 | 5 votes |
@Test public void testResetVertexLabelId() { SchemaManager schema = schema(); VertexLabel player = schema.vertexLabel("player") .properties("name").create(); Assert.assertTrue(player.id() > 0); player.resetId(); Assert.assertEquals(0L, player.id()); }
Example #30
Source File: EdgeLabelTest.java From hugegraph-client with Apache License 2.0 | 5 votes |
@Test public void testResetEdgeLabelId() { SchemaManager schema = schema(); EdgeLabel write = schema.edgeLabel("write") .link("person", "book") .properties("date", "weight") .userdata("multiplicity", "one-to-many") .userdata("icon", "picture2") .create(); Assert.assertTrue(write.id() > 0); write.resetId(); Assert.assertEquals(0L, write.id()); }