Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
Merge pull request #786 from bsinno/maxhbr/fix/fix/attachment-blackho…
Browse files Browse the repository at this point in the history
…letest-assertion

test(datahandler): add assertion for couchdb test (lib-datahandler)

review-by: thomas.maier@evosoft.com
tested-by: travis-ci
  • Loading branch information
maierthomas committed Mar 20, 2018
2 parents d3e58c4 + 5edc183 commit 53fc3bc
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@

import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.concurrent.*;

import static org.eclipse.sw360.datahandler.TestUtils.*;
import static org.eclipse.sw360.datahandler.common.Duration.durationOf;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeThat;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -63,16 +66,13 @@ public void testTheCouchDbUrl() throws Exception {
public void testABlackHoleUrl() throws Exception {
assumeThat(getAvailableNetworkInterface(), isAvailable());

Callable<String> downloadAttempt = new Callable<String>() {
@Override
public String call() throws Exception {
AttachmentContent attachmentContent = mock(AttachmentContent.class);
when(attachmentContent.getRemoteUrl()).thenReturn("http://" + BLACK_HOLE_ADDRESS + "/filename");
Callable<String> downloadAttempt = () -> {
AttachmentContent attachmentContent = mock(AttachmentContent.class);
when(attachmentContent.getRemoteUrl()).thenReturn("http://" + BLACK_HOLE_ADDRESS + "/filename");

try (InputStream download = attachmentContentDownloader
.download(attachmentContent, downloadTimeout)) {
return CharStreams.toString(new InputStreamReader(download));
}
try (InputStream download = attachmentContentDownloader
.download(attachmentContent, downloadTimeout)) {
return CharStreams.toString(new InputStreamReader(download));
}
};

Expand All @@ -88,6 +88,7 @@ public String call() throws Exception {
} catch (ExecutionException e) {
Throwable futureException = e.getCause();
assertThat(futureException, is(notNullValue()));
assertTrue(futureException instanceof SocketException || futureException instanceof SocketTimeoutException);
}
} catch (TimeoutException e) {
fail("downloader got stuck on a black hole");
Expand Down

0 comments on commit 53fc3bc

Please sign in to comment.