Search in sources :

Example 21 with Namespace

use of org.apache.distributedlog.api.namespace.Namespace in project incubator-heron by apache.

the class DlogUploaderTest method testUploadPackageLocalFileNotExist.

@Test
public void testUploadPackageLocalFileNotExist() throws Exception {
    uploader = Mockito.spy(uploader);
    Namespace ns = mock(Namespace.class);
    when(nsBuilder.build()).thenReturn(ns);
    Mockito.doReturn(false).when(uploader).isLocalFileExists(Mockito.anyString());
    uploader.initialize(config);
    try {
        uploader.uploadPackage();
        fail("Should fail on uploading package");
    } catch (UploaderException ue) {
    // expected
    }
    verify(ns, never()).logExists(anyString());
}
Also used : UploaderException(com.twitter.heron.spi.uploader.UploaderException) Namespace(org.apache.distributedlog.api.namespace.Namespace) Test(org.junit.Test)

Example 22 with Namespace

use of org.apache.distributedlog.api.namespace.Namespace in project incubator-heron by apache.

the class DlogUploaderTest method testUndoSuccess.

@Test
public void testUndoSuccess() throws Exception {
    Namespace ns = mock(Namespace.class);
    when(nsBuilder.build()).thenReturn(ns);
    uploader.initialize(config);
    assertTrue(uploader.undo());
    verify(ns, times(1)).deleteLog(eq(uploader.getPackageName()));
}
Also used : Namespace(org.apache.distributedlog.api.namespace.Namespace) Test(org.junit.Test)

Example 23 with Namespace

use of org.apache.distributedlog.api.namespace.Namespace in project incubator-heron by apache.

the class DlogStorage method deleteCheckpoint.

private void deleteCheckpoint(URI checkpointUri) throws IOException {
    Namespace checkpointNs = initializeNamespace(checkpointUri);
    try {
        Iterator<String> checkpoints = checkpointNs.getLogs();
        while (checkpoints.hasNext()) {
            String checkpoint = checkpoints.next();
            checkpointNs.deleteLog(checkpoint);
        }
    } finally {
        checkpointNs.close();
    }
}
Also used : Namespace(org.apache.distributedlog.api.namespace.Namespace)

Example 24 with Namespace

use of org.apache.distributedlog.api.namespace.Namespace in project incubator-heron by apache.

the class DlogStorage method dispose.

@Override
public void dispose(String topologyName, String oldestCheckpointId, boolean deleteAll) throws StatefulStorageException {
    // Currently dlog doesn't support recursive deletion. so we have to fetch all the checkpoints
    // and delete individual checkpoints.
    // TODO (sijie): replace the logic here once distributedlog supports recursive deletion.
    String topologyCheckpointRoot = getTopologyCheckpointRoot(topologyName);
    URI topologyUri = URI.create(checkpointNamespaceUriStr + topologyCheckpointRoot);
    // get checkpoints
    Namespace topologyNs = null;
    Iterator<String> checkpoints;
    try {
        topologyNs = initializeNamespace(topologyUri);
        checkpoints = topologyNs.getLogs();
    } catch (IOException ioe) {
        throw new StatefulStorageException("Failed to open topology namespace", ioe);
    } finally {
        if (null != topologyNs) {
            topologyNs.close();
        }
    }
    while (checkpoints.hasNext()) {
        String checkpointId = checkpoints.next();
        if (deleteAll || checkpointId.compareTo(oldestCheckpointId) < 0) {
            URI checkpointUri = URI.create(checkpointNamespaceUriStr + topologyCheckpointRoot + "/" + checkpointId);
            try {
                deleteCheckpoint(checkpointUri);
            } catch (IOException e) {
                throw new StatefulStorageException("Failed to remove checkpoint " + checkpointId + " for topology " + topologyName, e);
            }
        }
    }
}
Also used : StatefulStorageException(com.twitter.heron.spi.statefulstorage.StatefulStorageException) IOException(java.io.IOException) URI(java.net.URI) Namespace(org.apache.distributedlog.api.namespace.Namespace)

Example 25 with Namespace

use of org.apache.distributedlog.api.namespace.Namespace in project incubator-heron by apache.

the class DlogStorageTest method testDiposeNone.

@Test
public void testDiposeNone() throws Exception {
    Namespace mockTopoloyNs = mock(Namespace.class);
    Namespace mockCheckpoint1 = mock(Namespace.class);
    Namespace mockCheckpoint2 = mock(Namespace.class);
    String checkpoint1 = "checkpoint1";
    String checkpoint2 = "checkpoint2";
    List<String> checkpoints = Lists.newArrayList(checkpoint1, checkpoint2);
    List<String> chkp1Tasks = Lists.newArrayList("component1_task1", "component1_task2");
    List<String> chkp2Tasks = Lists.newArrayList("component2_task1", "component2_task2");
    doReturn(mockTopoloyNs).when(dlogStorage).initializeNamespace(eq(URI.create(ROOT_URI + "/" + StatefulStorageTestContext.TOPOLOGY_NAME)));
    doReturn(mockCheckpoint1).when(dlogStorage).initializeNamespace(eq(URI.create(ROOT_URI + "/" + StatefulStorageTestContext.TOPOLOGY_NAME + "/checkpoint1")));
    doReturn(mockCheckpoint2).when(dlogStorage).initializeNamespace(eq(URI.create(ROOT_URI + "/" + StatefulStorageTestContext.TOPOLOGY_NAME + "/checkpoint2")));
    when(mockTopoloyNs.getLogs()).thenReturn(checkpoints.iterator());
    when(mockCheckpoint1.getLogs()).thenReturn(chkp1Tasks.iterator());
    when(mockCheckpoint2.getLogs()).thenReturn(chkp2Tasks.iterator());
    dlogStorage.dispose(StatefulStorageTestContext.TOPOLOGY_NAME, "checkpoint0", false);
    verify(mockCheckpoint1, times(0)).deleteLog(eq("component1_task1"));
    verify(mockCheckpoint1, times(0)).deleteLog(eq("component1_task2"));
    verify(mockCheckpoint2, times(0)).deleteLog(eq("component2_task1"));
    verify(mockCheckpoint2, times(0)).deleteLog(eq("component2_task2"));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) Namespace(org.apache.distributedlog.api.namespace.Namespace) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Namespace (org.apache.distributedlog.api.namespace.Namespace)50 Test (org.junit.Test)31 URI (java.net.URI)26 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)25 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)13 InputStream (java.io.InputStream)12 IOException (java.io.IOException)10 Response (javax.ws.rs.core.Response)8 Test (org.testng.annotations.Test)8 FunctionMetaData (org.apache.pulsar.functions.proto.Function.FunctionMetaData)6 RequestResult (org.apache.pulsar.functions.worker.request.RequestResult)6 AsyncLogReader (org.apache.distributedlog.api.AsyncLogReader)5 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)5 LogWriter (org.apache.distributedlog.api.LogWriter)5 ErrorData (org.apache.pulsar.common.policies.data.ErrorData)5 DLSN (org.apache.distributedlog.DLSN)4 DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)4 Matchers.anyString (org.mockito.Matchers.anyString)4 DLInputStream (com.twitter.heron.dlog.DLInputStream)3 OutputStream (java.io.OutputStream)3