use of com.baidu.hugegraph.backend.cache.CachedSchemaTransaction in project incubator-hugegraph by apache.
the class CachedSchemaTransactionTest method testEventClear.
@Test
public void testEventClear() throws Exception {
CachedSchemaTransaction cache = this.cache();
FakeObjects objects = new FakeObjects("unit-test");
cache.addPropertyKey(objects.newPropertyKey(IdGenerator.of(1), "fake-pk-1"));
cache.addPropertyKey(objects.newPropertyKey(IdGenerator.of(2), "fake-pk-2"));
Assert.assertEquals(2L, Whitebox.invoke(cache, "idCache", "size"));
Assert.assertEquals(2L, Whitebox.invoke(cache, "nameCache", "size"));
Assert.assertEquals("fake-pk-1", cache.getPropertyKey(IdGenerator.of(1)).name());
Assert.assertEquals(IdGenerator.of(1), cache.getPropertyKey("fake-pk-1").id());
Assert.assertEquals("fake-pk-2", cache.getPropertyKey(IdGenerator.of(2)).name());
Assert.assertEquals(IdGenerator.of(2), cache.getPropertyKey("fake-pk-2").id());
this.params.schemaEventHub().notify(Events.CACHE, "clear", null).get();
Assert.assertEquals(0L, Whitebox.invoke(cache, "idCache", "size"));
Assert.assertEquals(0L, Whitebox.invoke(cache, "nameCache", "size"));
Assert.assertEquals("fake-pk-1", cache.getPropertyKey(IdGenerator.of(1)).name());
Assert.assertEquals(IdGenerator.of(1), cache.getPropertyKey("fake-pk-1").id());
Assert.assertEquals("fake-pk-2", cache.getPropertyKey(IdGenerator.of(2)).name());
Assert.assertEquals(IdGenerator.of(2), cache.getPropertyKey("fake-pk-2").id());
Assert.assertEquals(2L, Whitebox.invoke(cache, "idCache", "size"));
Assert.assertEquals(2L, Whitebox.invoke(cache, "nameCache", "size"));
}
use of com.baidu.hugegraph.backend.cache.CachedSchemaTransaction in project incubator-hugegraph by apache.
the class CachedSchemaTransactionTest method setup.
@Before
public void setup() {
HugeGraph graph = HugeFactory.open(FakeObjects.newConfig());
this.params = Whitebox.getInternalState(graph, "params");
this.cache = new CachedSchemaTransaction(this.params, this.params.loadSchemaStore());
}
use of com.baidu.hugegraph.backend.cache.CachedSchemaTransaction in project incubator-hugegraph by apache.
the class CachedSchemaTransactionTest method testEventInvalid.
@Test
public void testEventInvalid() throws Exception {
CachedSchemaTransaction cache = this.cache();
FakeObjects objects = new FakeObjects("unit-test");
cache.addPropertyKey(objects.newPropertyKey(IdGenerator.of(1), "fake-pk-1"));
cache.addPropertyKey(objects.newPropertyKey(IdGenerator.of(2), "fake-pk-2"));
Assert.assertEquals(2L, Whitebox.invoke(cache, "idCache", "size"));
Assert.assertEquals(2L, Whitebox.invoke(cache, "nameCache", "size"));
Assert.assertEquals("fake-pk-1", cache.getPropertyKey(IdGenerator.of(1)).name());
Assert.assertEquals(IdGenerator.of(1), cache.getPropertyKey("fake-pk-1").id());
Assert.assertEquals("fake-pk-2", cache.getPropertyKey(IdGenerator.of(2)).name());
Assert.assertEquals(IdGenerator.of(2), cache.getPropertyKey("fake-pk-2").id());
this.params.schemaEventHub().notify(Events.CACHE, "invalid", HugeType.PROPERTY_KEY, IdGenerator.of(1)).get();
Assert.assertEquals(1L, Whitebox.invoke(cache, "idCache", "size"));
Assert.assertEquals(1L, Whitebox.invoke(cache, "nameCache", "size"));
Assert.assertEquals("fake-pk-1", cache.getPropertyKey(IdGenerator.of(1)).name());
Assert.assertEquals(IdGenerator.of(1), cache.getPropertyKey("fake-pk-1").id());
Assert.assertEquals("fake-pk-2", cache.getPropertyKey(IdGenerator.of(2)).name());
Assert.assertEquals(IdGenerator.of(2), cache.getPropertyKey("fake-pk-2").id());
Assert.assertEquals(2L, Whitebox.invoke(cache, "idCache", "size"));
Assert.assertEquals(2L, Whitebox.invoke(cache, "nameCache", "size"));
}
use of com.baidu.hugegraph.backend.cache.CachedSchemaTransaction in project incubator-hugegraph by apache.
the class CachedSchemaTransactionTest method testResetCachedAllIfReachedCapacity.
@Test
public void testResetCachedAllIfReachedCapacity() throws Exception {
CachedSchemaTransaction cache = this.cache();
Object old = Whitebox.getInternalState(cache, "idCache.capacity");
Whitebox.setInternalState(cache, "idCache.capacity", 2);
try {
Assert.assertEquals(0L, Whitebox.invoke(cache, "idCache", "size"));
FakeObjects objects = new FakeObjects("unit-test");
cache.addPropertyKey(objects.newPropertyKey(IdGenerator.of(1), "fake-pk-1"));
Assert.assertEquals(1L, Whitebox.invoke(cache, "idCache", "size"));
Assert.assertEquals(1, cache.getPropertyKeys().size());
Whitebox.invoke(CachedSchemaTransaction.class, "cachedTypes", cache);
Assert.assertEquals(ImmutableMap.of(HugeType.PROPERTY_KEY, true), Whitebox.invoke(CachedSchemaTransaction.class, "cachedTypes", cache));
cache.addPropertyKey(objects.newPropertyKey(IdGenerator.of(3), "fake-pk-2"));
cache.addPropertyKey(objects.newPropertyKey(IdGenerator.of(2), "fake-pk-3"));
Assert.assertEquals(2L, Whitebox.invoke(cache, "idCache", "size"));
Assert.assertEquals(3, cache.getPropertyKeys().size());
Assert.assertEquals(ImmutableMap.of(), Whitebox.invoke(CachedSchemaTransaction.class, "cachedTypes", cache));
} finally {
Whitebox.setInternalState(cache, "idCache.capacity", old);
}
}
use of com.baidu.hugegraph.backend.cache.CachedSchemaTransaction in project incubator-hugegraph by apache.
the class CachedSchemaTransactionTest method testGetSchema.
@Test
public void testGetSchema() throws Exception {
CachedSchemaTransaction cache = this.cache();
FakeObjects objects = new FakeObjects("unit-test");
cache.addPropertyKey(objects.newPropertyKey(IdGenerator.of(1), "fake-pk-1"));
this.params.schemaEventHub().notify(Events.CACHE, "clear", null).get();
Assert.assertEquals("fake-pk-1", cache.getPropertyKey(IdGenerator.of(1)).name());
Assert.assertEquals(IdGenerator.of(1), cache.getPropertyKey("fake-pk-1").id());
this.params.schemaEventHub().notify(Events.CACHE, "clear", null).get();
Assert.assertEquals(IdGenerator.of(1), cache.getPropertyKey("fake-pk-1").id());
Assert.assertEquals("fake-pk-1", cache.getPropertyKey(IdGenerator.of(1)).name());
}
Aggregations