Search in sources :

Example 1 with MemoryStorage

use of oap.storage.MemoryStorage in project oap by oaplatform.

the class StatsDBTest method testSync.

@Test
public void testSync() {
    try (val storage = service(new SingleFileStorage<>(masterDbPath, NodeIdentifier.identifier, 10000, NoLock));
        val master = service(new StatsDBMaster(schema2, storage));
        val node = service(new StatsDBNode(schema2, master, null, new MemoryStorage<>(NodeIdentifier.identifier, NoLock)))) {
        node.sync();
        node.update("k1", "k2", (c) -> c.ci = 10, MockChild::new);
        node.update("k1", "k3", (c) -> c.ci = 1, MockChild::new);
        node.update("k1", (c) -> c.i2 = 20, MockValue::new);
        node.sync();
        assertThat(node.<MockValue>get("k1", "k2")).isNull();
        assertThat(master.<MockChild>get("k1", "k2").ci).isEqualTo(10);
        assertThat(master.<MockValue>get("k1").i2).isEqualTo(20);
        node.update("k1", "k2", (c) -> c.ci = 10, MockChild::new);
        node.update("k1", (c) -> c.i2 = 21, () -> new MockValue(21));
        node.sync();
        assertThat(node.<MockValue>get("k1", "k2")).isNull();
        assertThat(master.<MockChild>get("k1", "k2").ci).isEqualTo(20);
        assertThat(master.<MockValue>get("k1").i2).isEqualTo(41);
        assertThat(master.<MockValue>get("k1").sum).isEqualTo(21L);
    }
}
Also used : lombok.val(lombok.val) MemoryStorage(oap.storage.MemoryStorage) Test(org.testng.annotations.Test) AbstractTest(oap.testng.AbstractTest)

Example 2 with MemoryStorage

use of oap.storage.MemoryStorage in project oap by oaplatform.

the class StatsDBTest method testVersion.

@Test
public void testVersion() {
    try (val master = service(new StatsDBMaster(schema2, new MemoryStorage<>(NodeIdentifier.identifier, NoLock)));
        val node = service(new StatsDBNode(schema2, master, null, new MemoryStorage<>(NodeIdentifier.identifier, NoLock)))) {
        Cuid.reset("s", 0);
        node.update("k1", (c) -> c.i2 = 20, MockValue::new);
        node.sync();
        assertThat(master.<MockValue>get("k1").i2).isEqualTo(20);
        Cuid.reset("s", 0);
        node.update("k1", (c) -> c.i2 = 21, MockValue::new);
        node.sync();
        assertThat(master.<MockValue>get("k1").i2).isEqualTo(20);
    }
}
Also used : lombok.val(lombok.val) MemoryStorage(oap.storage.MemoryStorage) Test(org.testng.annotations.Test) AbstractTest(oap.testng.AbstractTest)

Example 3 with MemoryStorage

use of oap.storage.MemoryStorage in project oap by oaplatform.

the class DefaultAclServiceTest method beforeMethod.

@BeforeMethod
public void beforeMethod() {
    objectStorage = service(new MemoryStorage<SecurityContainer<TestAclObject>>(IdentifierBuilder.annotationBuild(), Lock));
    roleStorage = service(new MemoryStorage<>(IdentifierBuilder.annotationBuild(), Lock));
    val gaRole = roleStorage.store(new AclRole(AclService.GLOBAL_ADMIN_ROLE, "ga", singletonList("*")));
    val aclSchema = new MockAclSchema(objectStorage);
    aclService = service(new DefaultAclService(roleStorage, aclSchema));
    rootId = register(ROOT, "testObject1", ROOT);
    childId = register(rootId, "child", ROOT);
    childId2 = register(childId, "child", ROOT);
    subjectId = register(rootId, "subject", ROOT);
    subjectGroupId = register(rootId, "subject", ROOT);
    subjectId2 = register(subjectGroupId, "subject", ROOT);
    subjectId23 = register(subjectId2, "subject", ROOT);
    ga = register(ROOT, "user", ROOT);
    roleUknown = roleStorage.store(new AclRole("roleIdUknown", "testRole1", singletonList("testObjectUnknown.read")));
    role1 = roleStorage.store(new AclRole("roleId1", "testRole1", singletonList("testObject1.read")));
    role2 = roleStorage.store(new AclRole("roleId2", "testRole2", singletonList("testObject2.read")));
    role3 = roleStorage.store(new AclRole("roleId3", "testRole3", singletonList("testObject3.read")));
    aclService.add(ROOT, ga, gaRole.getId(), true);
}
Also used : lombok.val(lombok.val) MemoryStorage(oap.storage.MemoryStorage) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with MemoryStorage

use of oap.storage.MemoryStorage in project oap by oaplatform.

the class StatsDBTest method testChildren.

@Test
public void testChildren() {
    try (val master = service(new StatsDBMaster(schema2, new MemoryStorage<>(NodeIdentifier.identifier, NoLock)))) {
        master.update("k1", "k2", (c) -> c.ci = 10, MockChild::new);
        master.update("k1", "k3", (c) -> c.ci = 3, MockChild::new);
        master.update("k2", "k4", (c) -> c.ci = 4, MockChild::new);
        master.update("k1", (c) -> c.i2 = 10, MockValue::new);
        assertThat(master.children("k1")).hasSize(2).contains(new MockChild(10)).contains(new MockChild(3));
        assertThat(master.children("k2")).hasSize(1).contains(new MockChild(4));
        assertThat(master.children("unknown")).isEmpty();
        assertThat(master.children("k1", "k2")).isEmpty();
    }
}
Also used : lombok.val(lombok.val) MemoryStorage(oap.storage.MemoryStorage) Test(org.testng.annotations.Test) AbstractTest(oap.testng.AbstractTest)

Example 5 with MemoryStorage

use of oap.storage.MemoryStorage in project oap by oaplatform.

the class StatsDBTest method testMergeChild.

@Test
public void testMergeChild() {
    try (val master = service(new StatsDBMaster(schema3, new MemoryStorage<>(NodeIdentifier.identifier, NoLock)));
        val node = service(new StatsDBNode(schema3, master, null, new MemoryStorage<>(NodeIdentifier.identifier, NoLock)))) {
        node.update("p", (p) -> {
        }, () -> new MockValue(1));
        node.update("p", "c1", (c) -> {
        }, () -> new MockChild(1));
        node.update("p", "c1", "c2", (c) -> {
        }, () -> new MockChild(2));
        node.sync();
        assertThat(master.<MockValue>get("p").sum).isEqualTo(3);
        node.update("p", (p) -> {
        }, () -> new MockValue(1));
        node.update("p", "c1", "c2", "c3", (c) -> {
        }, () -> new MockChild(2));
        node.sync();
        node.update("p", "c1", "c2", (c) -> {
        }, () -> new MockChild(2));
        node.sync();
        assertThat(master.<MockValue>get("p").i2).isEqualTo(2);
        assertThat(master.<MockValue>get("p").sum).isEqualTo(5);
        assertThat(master.<MockChild>get("p", "c1").ci).isEqualTo(1);
        assertThat(master.<MockChild>get("p", "c1").sum).isEqualTo(4);
        assertThat(master.<MockChild>get("p", "c1", "c2").ci).isEqualTo(4);
        assertThat(master.<MockChild>get("p", "c1", "c2", "c3").ci).isEqualTo(2);
    }
}
Also used : lombok.val(lombok.val) MemoryStorage(oap.storage.MemoryStorage) Test(org.testng.annotations.Test) AbstractTest(oap.testng.AbstractTest)

Aggregations

lombok.val (lombok.val)5 MemoryStorage (oap.storage.MemoryStorage)5 AbstractTest (oap.testng.AbstractTest)4 Test (org.testng.annotations.Test)4 BeforeMethod (org.testng.annotations.BeforeMethod)1