Skip to content

Commit

Permalink
Fix skipping not found videos for Koofr (dtinit#1146)
Browse files Browse the repository at this point in the history
Summary:
When video is imported to Koofr and it was not found in CDN, such video should be skipped.
Currently null is returned instead path to video, which breaks creation of successfull ItemImportResult, which requires non-null data.

Short-term solution: return dynamic skipped filepath based on video id.

Potential long term solution: introduce skipped result
  • Loading branch information
calmarj committed Aug 22, 2022
1 parent f1f1b01 commit 526b529
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
public class KoofrVideosImporter
implements Importer<TokensAndUrlAuthData, VideosContainerResource> {

private static final String SKIPPED_FILE_RESULT_FORMAT = "skipped-%s";

private final KoofrClientFactory koofrClientFactory;
private final ImageStreamProvider imageStreamProvider;
private final Monitor monitor;
Expand Down Expand Up @@ -141,7 +143,7 @@ private String importSingleVideo(
} catch (FileNotFoundException e) {
monitor.info(
() -> String.format("Video resource was missing for id: %s", video.getDataId()), e);
return null;
return String.format(SKIPPED_FILE_RESULT_FORMAT, video.getDataId());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
package org.datatransferproject.transfer.koofr.videos;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import com.google.common.collect.ImmutableList;
import java.util.Collection;
import java.util.UUID;
import java.util.concurrent.Callable;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import org.datatransferproject.api.launcher.Monitor;
Expand All @@ -26,41 +16,53 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Collection;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicReference;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
public class KoofrVideosImporterTest {

@Mock
private KoofrClientFactory clientFactory;
@Mock
private KoofrClient client;
@Mock
private Monitor monitor;
private KoofrVideosImporter importer;
@Mock
private IdempotentImportExecutor executor;
private KoofrVideosImporter importer;
private TokensAndUrlAuthData authData;
private MockWebServer server;

private final AtomicReference<String> capturedResult = new AtomicReference<>();

@BeforeEach
public void setUp() throws Exception {
server = new MockWebServer();
server.start();

client = mock(KoofrClient.class);

clientFactory = mock(KoofrClientFactory.class);
when(clientFactory.create(any())).thenReturn(client);

monitor = mock(Monitor.class);

importer = new KoofrVideosImporter(clientFactory, monitor);

executor = mock(IdempotentImportExecutor.class);
when(executor.executeAndSwallowIOExceptions(any(), any(), any()))
.then(
(InvocationOnMock invocation) -> {
Callable<String> callable = invocation.getArgument(2);
return callable.call();
String result = callable.call();
capturedResult.set(result);
return result;
});
authData = new TokensAndUrlAuthData("acc", "refresh", "");
}
Expand Down Expand Up @@ -239,5 +241,8 @@ public void testSkipNotFoundVideo() throws Exception {
InOrder clientInOrder = Mockito.inOrder(client);

clientInOrder.verifyNoMoreInteractions();

String importResult = capturedResult.get();
assertEquals(importResult, "skipped-not_found_video_1");
}
}

0 comments on commit 526b529

Please sign in to comment.