use of org.commonjava.indy.ftest.core.fixture.ReluctantInputStream in project indy by Commonjava.
the class DownloadWhileProxyingInProgressTest method downloadWhileSlowProxyCompletes.
@Test
public void downloadWhileSlowProxyCompletes() throws Exception {
RemoteRepository rmt = new RemoteRepository(STORE, server.formatUrl(STORE));
rmt.setTimeoutSeconds(30);
client.stores().create(rmt, "adding test proxy", RemoteRepository.class);
final String path = "org/foo/foo-project/1/foo-1.txt";
final byte[] data = ("This is a test: " + System.nanoTime()).getBytes();
final CountDownLatch latch = new CountDownLatch(2);
final ReluctantInputStream stream = new ReluctantInputStream(data);
server.expect(server.formatUrl(STORE, path), 200, stream);
final InputTimer input = new InputTimer(stream, 10000 / data.length, latch);
newThread("input", input).start();
final DelayedDownload download = new DelayedDownload(client, new StoreKey(remote, STORE), path, 5000, latch);
newThread("download", download).start();
System.out.println("Waiting for content transfers to complete.");
latch.await();
// waitForEventPropagation();
System.out.printf("Timing results:\n Input started: {}\n Input ended: {}\n Download started: {}\n Download ended: {}", input.getStartTime(), input.getEndTime(), download.getStartTime(), download.getEndTime());
assertThat(download.getContent().toByteArray(), equalTo(data));
assertThat(input.getEndTime() > download.getStartTime(), equalTo(true));
final PathInfo result = client.content().getInfo(remote, STORE, path);
assertThat("no result", result, notNullValue());
assertThat("doesn't exist", result.exists(), equalTo(true));
}
use of org.commonjava.indy.ftest.core.fixture.ReluctantInputStream in project indy by Commonjava.
the class LateJoinDownloadWhileProxyingInProgressTest method downloadTwiceWhileSlowProxyCompletes.
@Test
@Category(TimingDependent.class)
public void downloadTwiceWhileSlowProxyCompletes() throws Exception {
RemoteRepository rmt = new RemoteRepository(STORE, server.formatUrl(STORE));
rmt.setTimeoutSeconds(30);
client.stores().create(rmt, "adding test proxy", RemoteRepository.class);
final String path = "org/foo/foo-project/1/foo-1.txt";
final byte[] data = ("This is a test: " + System.nanoTime()).getBytes();
final CountDownLatch latch = new CountDownLatch(3);
final ReluctantInputStream stream = new ReluctantInputStream(data);
server.expect(server.formatUrl(STORE, path), 200, stream);
final InputTimer input = new InputTimer(stream, 10000 / data.length, latch);
newThread("input", input).start();
final DelayedDownload download = new DelayedDownload(client, new StoreKey(remote, STORE), path, 5, latch);
newThread("download", download).start();
final DelayedDownload download2 = new DelayedDownload(client, new StoreKey(remote, STORE), path, 5000, latch);
newThread("download2", download2).start();
System.out.println("Waiting for content transfers to complete.");
latch.await();
// waitForEventPropagation();
System.out.printf("Timing results:\n Input started: {}\n Input ended: {}\n Download1 started: {}\n Download1 ended: {}\\n Download2 started: {}\\n Download2 ended: {}", input.getStartTime(), input.getEndTime(), download.getStartTime(), download.getEndTime(), download2.getStartTime(), download2.getEndTime());
assertThat("First download retrieved wrong content", Arrays.equals(download.getContent().toByteArray(), data), equalTo(true));
assertThat("Second download retrieved wrong content", Arrays.equals(download2.getContent().toByteArray(), data), equalTo(true));
assertThat("First download started after input ended.", input.getEndTime() > download.getStartTime(), equalTo(true));
assertThat("Second download started after input ended.", input.getEndTime() > download2.getStartTime(), equalTo(true));
final PathInfo result = client.content().getInfo(remote, STORE, path);
assertThat("no result", result, notNullValue());
assertThat("doesn't exist", result.exists(), equalTo(true));
}
Aggregations