Search in sources :

Example 6 with CheckpointStoreException

use of io.pravega.controller.store.checkpoint.CheckpointStoreException in project pravega by pravega.

the class CheckpointStoreTests method folderOperationTests.

@Test
public void folderOperationTests() throws CheckpointStoreException {
    final String process1 = "process1";
    final String readerGroup1 = "rg1";
    final String readerGroup2 = "rg2";
    final String reader1 = "reader1";
    final String reader2 = "reader2";
    Set<String> processes = checkpointStore.getProcesses();
    Assert.assertEquals(0, processes.size());
    checkpointStore.addReaderGroup(process1, readerGroup1);
    List<String> result = checkpointStore.getReaderGroups(process1);
    Assert.assertNotNull(result);
    Assert.assertEquals(1, result.size());
    Assert.assertEquals(readerGroup1, result.get(0));
    processes = checkpointStore.getProcesses();
    Assert.assertEquals(1, processes.size());
    checkpointStore.addReader(process1, readerGroup1, reader1);
    Map<String, Position> resultMap = checkpointStore.getPositions(process1, readerGroup1);
    Assert.assertNotNull(resultMap);
    Assert.assertEquals(1, resultMap.size());
    Assert.assertNull(resultMap.get(reader1));
    Position position = new PositionImpl(Collections.emptyMap());
    checkpointStore.setPosition(process1, readerGroup1, reader1, position);
    resultMap = checkpointStore.getPositions(process1, readerGroup1);
    Assert.assertNotNull(resultMap);
    Assert.assertEquals(1, resultMap.size());
    Assert.assertNotNull(resultMap.get(reader1));
    Assert.assertEquals(position, resultMap.get(reader1));
    try {
        checkpointStore.setPosition(process1, readerGroup1, "randomReader", position);
        Assert.assertTrue(false);
    } catch (CheckpointStoreException cse) {
        Assert.assertEquals(CheckpointStoreException.Type.NoNode, cse.getType());
    }
    try {
        checkpointStore.removeReaderGroup(process1, readerGroup1);
        Assert.assertFalse(true);
    } catch (CheckpointStoreException cse) {
        Assert.assertEquals(CheckpointStoreException.Type.Active, cse.getType());
    }
    result = checkpointStore.getReaderGroups(process1);
    Assert.assertNotNull(result);
    Assert.assertEquals(1, result.size());
    Assert.assertEquals(readerGroup1, result.get(0));
    checkpointStore.addReader(process1, readerGroup1, reader2);
    resultMap = checkpointStore.getPositions(process1, readerGroup1);
    Assert.assertNotNull(resultMap);
    Assert.assertEquals(2, resultMap.size());
    Assert.assertNotNull(resultMap.get(reader1));
    Assert.assertNull(resultMap.get(reader2));
    checkpointStore.addReaderGroup(process1, readerGroup2);
    result = checkpointStore.getReaderGroups(process1);
    Assert.assertNotNull(result);
    Assert.assertEquals(2, result.size());
    Map<String, Position> map = checkpointStore.sealReaderGroup(process1, readerGroup2);
    Assert.assertNotNull(map);
    Assert.assertEquals(0, map.size());
    try {
        checkpointStore.addReader(process1, readerGroup2, "randomReader");
        Assert.assertTrue(false);
    } catch (CheckpointStoreException cse) {
        Assert.assertEquals(CheckpointStoreException.Type.Sealed, cse.getType());
    }
    try {
        checkpointStore.addReader(process1, "dummyReaderGroup", "randomReader");
        Assert.assertTrue(false);
    } catch (CheckpointStoreException cse) {
        Assert.assertEquals(CheckpointStoreException.Type.NoNode, cse.getType());
    }
    try {
        checkpointStore.sealReaderGroup(process1, "dummyReaderGroup");
        Assert.assertTrue(false);
    } catch (CheckpointStoreException cse) {
        Assert.assertEquals(CheckpointStoreException.Type.NoNode, cse.getType());
    }
    checkpointStore.removeReaderGroup(process1, readerGroup2);
    result = checkpointStore.getReaderGroups(process1);
    Assert.assertNotNull(result);
    Assert.assertEquals(1, result.size());
    Assert.assertEquals(readerGroup1, result.get(0));
    try {
        checkpointStore.addReader(process1, readerGroup1, reader1);
    } catch (CheckpointStoreException cse) {
        Assert.assertEquals(CheckpointStoreException.Type.NodeExists, cse.getType());
    }
    map = checkpointStore.sealReaderGroup(process1, readerGroup1);
    Assert.assertNotNull(map);
    Assert.assertEquals(2, map.size());
    try {
        checkpointStore.removeReaderGroup(process1, readerGroup1);
    } catch (CheckpointStoreException cse) {
        Assert.assertEquals(CheckpointStoreException.Type.NodeNotEmpty, cse.getType());
    }
    try {
        checkpointStore.addReader(process1, readerGroup1, "dummyReader");
    } catch (CheckpointStoreException cse) {
        Assert.assertEquals(CheckpointStoreException.Type.Sealed, cse.getType());
    }
    checkpointStore.removeReader(process1, readerGroup1, reader1);
    checkpointStore.removeReader(process1, readerGroup1, "randomReader");
    resultMap = checkpointStore.getPositions(process1, readerGroup1);
    Assert.assertNotNull(resultMap);
    Assert.assertEquals(1, resultMap.size());
    Assert.assertNull(resultMap.get(reader2));
    checkpointStore.removeReader(process1, readerGroup1, reader2);
    resultMap = checkpointStore.getPositions(process1, readerGroup1);
    Assert.assertNotNull(resultMap);
    Assert.assertEquals(0, resultMap.size());
    try {
        checkpointStore.addReaderGroup(process1, readerGroup1);
        Assert.assertTrue(false);
    } catch (CheckpointStoreException cse) {
        Assert.assertEquals(CheckpointStoreException.Type.NodeExists, cse.getType());
    }
    result = checkpointStore.getReaderGroups(process1);
    Assert.assertNotNull(result);
    Assert.assertEquals(1, result.size());
    Assert.assertEquals(readerGroup1, result.get(0));
    checkpointStore.removeReaderGroup(process1, readerGroup1);
    result = checkpointStore.getReaderGroups(process1);
    Assert.assertNotNull(result);
    Assert.assertEquals(0, result.size());
}
Also used : Position(io.pravega.client.stream.Position) PositionImpl(io.pravega.client.stream.impl.PositionImpl) CheckpointStoreException(io.pravega.controller.store.checkpoint.CheckpointStoreException) Test(org.junit.Test)

Aggregations

CheckpointStoreException (io.pravega.controller.store.checkpoint.CheckpointStoreException)6 Test (org.junit.Test)5 Collections (java.util.Collections)4 ConnectionFactory (io.pravega.client.netty.impl.ConnectionFactory)3 Position (io.pravega.client.stream.Position)3 PositionImpl (io.pravega.client.stream.impl.PositionImpl)3 CheckpointStore (io.pravega.controller.store.checkpoint.CheckpointStore)3 CheckpointStoreFactory (io.pravega.controller.store.checkpoint.CheckpointStoreFactory)3 HostControllerStore (io.pravega.controller.store.host.HostControllerStore)3 StreamMetadataStore (io.pravega.controller.store.stream.StreamMetadataStore)3 ControllerEvent (io.pravega.shared.controller.event.ControllerEvent)3 AssertExtensions (io.pravega.test.common.AssertExtensions)3 UUID (java.util.UUID)3 Predicate (java.util.function.Predicate)3 CuratorFramework (org.apache.curator.framework.CuratorFramework)3 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)3 ClientFactory (io.pravega.client.ClientFactory)2 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)2 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)2 Controller (io.pravega.client.stream.impl.Controller)2