Search in sources :

Example 6 with IdSet

use of com.baidu.hugegraph.util.collection.IdSet 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 7 with IdSet

use of com.baidu.hugegraph.util.collection.IdSet 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)

Example 8 with IdSet

use of com.baidu.hugegraph.util.collection.IdSet 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();
    }
}
Also used : IdGenerator(com.baidu.hugegraph.backend.id.IdGenerator) 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 9 with IdSet

use of com.baidu.hugegraph.util.collection.IdSet 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();
    }
}
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 10 with IdSet

use of com.baidu.hugegraph.util.collection.IdSet 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();
    }
}
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) HashSet(java.util.HashSet) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) Test(org.junit.Test)

Aggregations

Id (com.baidu.hugegraph.backend.id.Id)10 IdSet (com.baidu.hugegraph.util.collection.IdSet)10 Test (org.junit.Test)8 CollectionType (com.baidu.hugegraph.type.define.CollectionType)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 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)2 IdGenerator (com.baidu.hugegraph.backend.id.IdGenerator)1 DataType (com.baidu.hugegraph.type.define.DataType)1 CollectionFactory (com.baidu.hugegraph.util.collection.CollectionFactory)1