Search in sources :

Example 1 with CollectionType

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);
}
Also used : CollectionFactory(com.baidu.hugegraph.util.collection.CollectionFactory) CollectionType(com.baidu.hugegraph.type.define.CollectionType) Test(org.junit.Test)

Example 2 with CollectionType

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();
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) Random(java.util.Random) IdSet(com.baidu.hugegraph.util.collection.IdSet) CollectionType(com.baidu.hugegraph.type.define.CollectionType) Id(com.baidu.hugegraph.backend.id.Id) UUID(java.util.UUID) HashSet(java.util.HashSet) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) Test(org.junit.Test)

Example 3 with CollectionType

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();
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) Random(java.util.Random) IdSet(com.baidu.hugegraph.util.collection.IdSet) CollectionType(com.baidu.hugegraph.type.define.CollectionType) Id(com.baidu.hugegraph.backend.id.Id) HashSet(java.util.HashSet) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) Test(org.junit.Test)

Example 4 with CollectionType

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();
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) IdSet(com.baidu.hugegraph.util.collection.IdSet) CollectionType(com.baidu.hugegraph.type.define.CollectionType) Id(com.baidu.hugegraph.backend.id.Id) UUID(java.util.UUID) HashSet(java.util.HashSet) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) Test(org.junit.Test)

Example 5 with CollectionType

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();
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) Random(java.util.Random) IdSet(com.baidu.hugegraph.util.collection.IdSet) CollectionType(com.baidu.hugegraph.type.define.CollectionType) Id(com.baidu.hugegraph.backend.id.Id) UUID(java.util.UUID) HashSet(java.util.HashSet) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) Test(org.junit.Test)

Aggregations

CollectionType (com.baidu.hugegraph.type.define.CollectionType)8 Test (org.junit.Test)8 Id (com.baidu.hugegraph.backend.id.Id)7 IdSet (com.baidu.hugegraph.util.collection.IdSet)7 HashSet (java.util.HashSet)7 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)7 Random (java.util.Random)5 UUID (java.util.UUID)5 IdGenerator (com.baidu.hugegraph.backend.id.IdGenerator)1 CollectionFactory (com.baidu.hugegraph.util.collection.CollectionFactory)1