use of com.baidu.hugegraph.type.define.CollectionType in project incubator-hugegraph by apache.
the class IdSetTest method testIdSetIterator.
@Test
public void testIdSetIterator() {
Random random = new Random();
Set<Long> numbers = new HashSet<>();
Set<UUID> uuids = new HashSet<>();
Set<String> strings = new HashSet<>();
for (CollectionType type : CollectionType.values()) {
idSet = new IdSet(type);
for (int i = 1; i < SIZE; i++) {
long number = random.nextLong();
numbers.add(number);
idSet.add(IdGenerator.of(number));
}
for (int i = 0; i < SIZE; i++) {
UUID uuid = UUID.randomUUID();
uuids.add(uuid);
idSet.add(IdGenerator.of(uuid));
}
for (int i = 0; i < SIZE; i++) {
String string = RandomStringUtils.randomAlphanumeric(10);
strings.add(string);
idSet.add(IdGenerator.of(string));
}
Assert.assertEquals(numbers.size() + uuids.size() + strings.size(), idSet.size());
LongHashSet numberIds = Whitebox.getInternalState(idSet, "numberIds");
Assert.assertEquals(numbers.size(), numberIds.size());
Set<Id> nonNumberIds = Whitebox.getInternalState(idSet, "nonNumberIds");
Assert.assertEquals(uuids.size() + strings.size(), nonNumberIds.size());
Iterator<Id> iterator = idSet.iterator();
while (iterator.hasNext()) {
Id id = iterator.next();
if (id instanceof IdGenerator.LongId) {
Assert.assertTrue(numbers.contains(id.asLong()));
} else if (id instanceof IdGenerator.UuidId) {
Assert.assertTrue(id.uuid() && uuids.contains(id.asObject()));
} else {
Assert.assertTrue(id instanceof IdGenerator.StringId);
Assert.assertTrue(strings.contains(id.asString()));
}
}
numbers.clear();
uuids.clear();
strings.clear();
idSet.clear();
}
}
use of com.baidu.hugegraph.type.define.CollectionType in project incubator-hugegraph by apache.
the class IdSetTest method testIdSetWithMixedId.
@Test
public void testIdSetWithMixedId() {
Random random = new Random();
Set<Long> numbers = new HashSet<>();
Set<UUID> uuids = new HashSet<>();
Set<String> strings = new HashSet<>();
for (CollectionType type : CollectionType.values()) {
idSet = new IdSet(type);
for (int i = 1; i < SIZE; i++) {
long number = random.nextLong();
numbers.add(number);
idSet.add(IdGenerator.of(number));
}
for (int i = 0; i < SIZE; i++) {
UUID uuid = UUID.randomUUID();
uuids.add(uuid);
idSet.add(IdGenerator.of(uuid));
}
for (int i = 0; i < SIZE; i++) {
String string = RandomStringUtils.randomAlphanumeric(10);
strings.add(string);
idSet.add(IdGenerator.of(string));
}
Assert.assertEquals(numbers.size() + uuids.size() + strings.size(), idSet.size());
LongHashSet numberIds = Whitebox.getInternalState(idSet, "numberIds");
Assert.assertEquals(numbers.size(), numberIds.size());
Set<Id> nonNumberIds = Whitebox.getInternalState(idSet, "nonNumberIds");
Assert.assertEquals(uuids.size() + strings.size(), nonNumberIds.size());
numbers.clear();
uuids.clear();
strings.clear();
idSet.clear();
}
}
use of com.baidu.hugegraph.type.define.CollectionType in project incubator-hugegraph by apache.
the class IdSetTest method testIdSetWithOnlyStringId.
@Test
public void testIdSetWithOnlyStringId() {
Set<String> strings = new HashSet<>();
for (CollectionType type : CollectionType.values()) {
idSet = new IdSet(type);
for (int i = 0; i < SIZE; i++) {
String string = RandomStringUtils.randomAlphanumeric(10);
strings.add(string);
idSet.add(IdGenerator.of(string));
}
Assert.assertEquals(strings.size(), idSet.size());
LongHashSet numberIds = Whitebox.getInternalState(idSet, "numberIds");
Assert.assertTrue(numberIds.isEmpty());
Set<Id> nonNumberIds = Whitebox.getInternalState(idSet, "nonNumberIds");
Assert.assertEquals(strings.size(), nonNumberIds.size());
strings.clear();
idSet.clear();
}
}
Aggregations