Search in sources :

Example 1 with InputTimer

use of org.commonjava.indy.ftest.core.fixture.InputTimer 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));
}
Also used : ReluctantInputStream(org.commonjava.indy.ftest.core.fixture.ReluctantInputStream) InputTimer(org.commonjava.indy.ftest.core.fixture.InputTimer) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) PathInfo(org.commonjava.indy.client.core.helper.PathInfo) DelayedDownload(org.commonjava.indy.ftest.core.fixture.DelayedDownload) CountDownLatch(java.util.concurrent.CountDownLatch) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 2 with InputTimer

use of org.commonjava.indy.ftest.core.fixture.InputTimer 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));
}
Also used : ReluctantInputStream(org.commonjava.indy.ftest.core.fixture.ReluctantInputStream) InputTimer(org.commonjava.indy.ftest.core.fixture.InputTimer) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) PathInfo(org.commonjava.indy.client.core.helper.PathInfo) DelayedDownload(org.commonjava.indy.ftest.core.fixture.DelayedDownload) CountDownLatch(java.util.concurrent.CountDownLatch) StoreKey(org.commonjava.indy.model.core.StoreKey) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)2 PathInfo (org.commonjava.indy.client.core.helper.PathInfo)2 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)2 DelayedDownload (org.commonjava.indy.ftest.core.fixture.DelayedDownload)2 InputTimer (org.commonjava.indy.ftest.core.fixture.InputTimer)2 ReluctantInputStream (org.commonjava.indy.ftest.core.fixture.ReluctantInputStream)2 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)2 StoreKey (org.commonjava.indy.model.core.StoreKey)2 Test (org.junit.Test)2 Category (org.junit.experimental.categories.Category)1