use of com.baidu.hugegraph.type.define.CollectionType in project incubator-hugegraph by apache.
the class CollectionFactoryTest method testCollectionFactoryConstructor.
@Test
public void testCollectionFactoryConstructor() {
factory = new CollectionFactory();
CollectionType type = Whitebox.getInternalState(factory, "type");
Assert.assertEquals(CollectionType.EC, type);
factory = new CollectionFactory(CollectionType.EC);
type = Whitebox.getInternalState(factory, "type");
Assert.assertEquals(CollectionType.EC, type);
factory = new CollectionFactory(CollectionType.FU);
type = Whitebox.getInternalState(factory, "type");
Assert.assertEquals(CollectionType.FU, type);
factory = new CollectionFactory(CollectionType.JCF);
type = Whitebox.getInternalState(factory, "type");
Assert.assertEquals(CollectionType.JCF, type);
}
use of com.baidu.hugegraph.type.define.CollectionType in project incubator-hugegraph by apache.
the class IdSetTest method testIdSetRemove.
@Test
public void testIdSetRemove() {
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());
for (long number : numbers) {
idSet.remove(IdGenerator.of(number));
}
Assert.assertEquals(nonNumberIds.size(), idSet.size());
for (UUID uuid : uuids) {
idSet.remove(IdGenerator.of(uuid));
}
for (String string : strings) {
idSet.remove(IdGenerator.of(string));
}
Assert.assertTrue(idSet.isEmpty());
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 testIdSetWithOnlyNumberId.
@Test
public void testIdSetWithOnlyNumberId() {
Random random = new Random();
Set<Long> numbers = 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));
}
Assert.assertEquals(numbers.size(), idSet.size());
LongHashSet numberIds = Whitebox.getInternalState(idSet, "numberIds");
Assert.assertEquals(numbers.size(), numberIds.size());
Set<Id> nonNumberIds = Whitebox.getInternalState(idSet, "nonNumberIds");
Assert.assertTrue(nonNumberIds.isEmpty());
numbers.clear();
idSet.clear();
}
}
use of com.baidu.hugegraph.type.define.CollectionType in project incubator-hugegraph by apache.
the class IdSetTest method testIdSetWithOnlyUUIDId.
@Test
public void testIdSetWithOnlyUUIDId() {
Set<UUID> uuids = new HashSet<>();
for (CollectionType type : CollectionType.values()) {
idSet = new IdSet(type);
for (int i = 0; i < SIZE; i++) {
UUID uuid = UUID.randomUUID();
uuids.add(uuid);
idSet.add(IdGenerator.of(uuid));
}
Assert.assertEquals(uuids.size(), idSet.size());
LongHashSet numberIds = Whitebox.getInternalState(idSet, "numberIds");
Assert.assertTrue(numberIds.isEmpty());
Set<Id> nonNumberIds = Whitebox.getInternalState(idSet, "nonNumberIds");
Assert.assertEquals(uuids.size(), nonNumberIds.size());
uuids.clear();
idSet.clear();
}
}
use of com.baidu.hugegraph.type.define.CollectionType in project incubator-hugegraph by apache.
the class IdSetTest method testIdSetContains.
@Test
public void testIdSetContains() {
Random random = new Random();
Set<Long> numbers = new HashSet<>();
Set<UUID> uuids = new HashSet<>();
Set<String> strings = new HashSet<>();
long number = 0L;
UUID uuid = null;
String string = null;
for (CollectionType type : CollectionType.values()) {
idSet = new IdSet(type);
for (int i = 1; i < SIZE; i++) {
number = random.nextLong();
numbers.add(number);
idSet.add(IdGenerator.of(number));
}
for (int i = 0; i < SIZE; i++) {
uuid = UUID.randomUUID();
uuids.add(uuid);
idSet.add(IdGenerator.of(uuid));
}
for (int i = 0; i < SIZE; i++) {
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());
Assert.assertTrue(idSet.contains(IdGenerator.of(number)));
Assert.assertTrue(idSet.contains(IdGenerator.of(uuid)));
Assert.assertTrue(idSet.contains(IdGenerator.of(string)));
numbers.clear();
uuids.clear();
strings.clear();
idSet.clear();
}
}
Aggregations