Search in sources :

Example 16 with PathInfo

use of org.commonjava.indy.client.core.helper.PathInfo in project indy by Commonjava.

the class ContentRescheduleTimeoutTest method timeout.

@Test
@Category(TimingDependent.class)
public void timeout() throws Exception {
    final String repoId = "test-repo";
    final String pomPath = "org/foo/bar/1.0/bar-1.0.pom";
    final String pomUrl = server.formatUrl(repoId, pomPath);
    final int CACHE_TIMEOUT_SECONDS = 6;
    final int CACHE_TIMEOUT_WAITING_MILLISECONDS = 3000;
    // mocking up a http server that expects access to a .pom
    final String datetime = (new Date()).toString();
    server.expect(pomUrl, 200, String.format("pom %s", datetime));
    // set up remote repository pointing to the test http server, and timeout little later
    final String changelog = "Timeout Testing: " + name.getMethodName();
    final RemoteRepository repository = new RemoteRepository(repoId, server.formatUrl(repoId));
    repository.setCacheTimeoutSeconds(CACHE_TIMEOUT_SECONDS);
    client.stores().create(repository, changelog, RemoteRepository.class);
    // first time trigger normal content storage with timeout, should be 6s
    PathInfo pomResult = client.content().getInfo(remote, repoId, pomPath);
    // force storage
    client.content().get(remote, repoId, pomPath).close();
    assertThat("no pom result", pomResult, notNullValue());
    assertThat("pom doesn't exist", pomResult.exists(), equalTo(true));
    File pomFile = Paths.get(fixture.getBootOptions().getIndyHome(), "var/lib/indy/storage", MAVEN_PKG_KEY, remote.singularEndpointName() + "-" + repoId, pomPath).toFile();
    assertThat("pom doesn't exist", pomFile.exists(), equalTo(true));
    // wait for first 3s
    Thread.sleep(CACHE_TIMEOUT_WAITING_MILLISECONDS);
    // as the normal content re-request, the timeout interval should be re-scheduled
    client.content().get(remote, repoId, pomPath);
    // will wait another 3.5s
    Thread.sleep(CACHE_TIMEOUT_WAITING_MILLISECONDS + 500);
    // as rescheduled in 3s, the new timeout should be 3+6=9s, so the artifact should not be deleted
    assertThat("artifact should not be removed as it is rescheduled with new request", pomFile.exists(), equalTo(true));
    // another round wait for 4.5s
    Thread.sleep(CACHE_TIMEOUT_WAITING_MILLISECONDS + 4500);
    assertThat("artifact should be removed when new scheduled cache timeout", pomFile.exists(), equalTo(false));
}
Also used : RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) PathInfo(org.commonjava.indy.client.core.helper.PathInfo) File(java.io.File) Date(java.util.Date) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 17 with PathInfo

use of org.commonjava.indy.client.core.helper.PathInfo in project indy by Commonjava.

the class DownloadContentHasLengthHeaderHostedTest method run.

@Test
public void run() throws Exception {
    byte[] data = ("This is a test: " + System.nanoTime()).getBytes();
    String path = "org/foo/foo-project/1/foo-1.txt";
    InputStream stream = new ByteArrayInputStream(data);
    client.content().store(hosted, STORE, path, stream);
    String p = client.content().contentPath(hosted, STORE, path);
    Map<String, String> headers = client.module(IndyRawHttpModule.class).getHttp().head(p);
    logger.debug("Get headers: " + headers);
    PathInfo result = client.content().getInfo(hosted, STORE, path);
    assertThat("no result", result, notNullValue());
    assertThat("doesn't exist", result.exists(), equalTo(true));
    assertThat("content length wrong", new Long(result.getContentLength()).intValue(), equalTo(data.length));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PathInfo(org.commonjava.indy.client.core.helper.PathInfo) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 18 with PathInfo

use of org.commonjava.indy.client.core.helper.PathInfo 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)

Example 19 with PathInfo

use of org.commonjava.indy.client.core.helper.PathInfo in project indy by Commonjava.

the class MixContentRescheduleTimeoutTest method timeout.

@Test
@Category(TimingDependent.class)
public void timeout() throws Exception {
    final String repoId = "test-repo";
    final String pomPath = "org/foo/bar/1.0/bar-1.0.pom";
    final String metadataPath = "org/foo/bar/maven-metadata.xml";
    final String pomUrl = server.formatUrl(repoId, pomPath);
    final String metadataUrl = server.formatUrl(repoId, metadataPath);
    final int CACHE_TIMEOUT_SECONDS = 8;
    final int CACHE_TIMEOUT_WAITING_MILLISECONDS = 4000;
    final int METADATA_TIMEOUT_SECONDS = 4;
    // mocking up a http server that expects access to a .pom
    final String datetime = (new Date()).toString();
    server.expect(pomUrl, 200, String.format("pom %s", datetime));
    server.expect(metadataUrl, 200, String.format("metadata %s", datetime));
    // set up remote repository pointing to the test http server, and timeout little later
    final String changelog = "Timeout Testing: " + name.getMethodName();
    final RemoteRepository repository = new RemoteRepository(repoId, server.formatUrl(repoId));
    repository.setCacheTimeoutSeconds(CACHE_TIMEOUT_SECONDS);
    repository.setMetadataTimeoutSeconds(METADATA_TIMEOUT_SECONDS);
    client.stores().create(repository, changelog, RemoteRepository.class);
    // first time trigger normal content storage with timeout, should be 8s
    PathInfo pomResult = client.content().getInfo(remote, repoId, pomPath);
    // force storage
    client.content().get(remote, repoId, pomPath).close();
    assertThat("no pom result", pomResult, notNullValue());
    assertThat("pom doesn't exist", pomResult.exists(), equalTo(true));
    File pomFile = Paths.get(fixture.getBootOptions().getIndyHome(), "var/lib/indy/storage", MAVEN_PKG_KEY, remote.singularEndpointName() + "-" + repoId, pomPath).toFile();
    assertThat("pom doesn't exist", pomFile.exists(), equalTo(true));
    // first time trigger metadata storage with timeout, should be 4s
    PathInfo metadataResult = client.content().getInfo(remote, repoId, metadataPath);
    // force storage
    client.content().get(remote, repoId, metadataPath).close();
    assertThat("no metadata result", metadataResult, notNullValue());
    assertThat("metadata doesn't exist", metadataResult.exists(), equalTo(true));
    File metadataFile = Paths.get(fixture.getBootOptions().getIndyHome(), "var/lib/indy/storage", MAVEN_PKG_KEY, remote.singularEndpointName() + "-" + repoId, metadataPath).toFile();
    assertThat("metadata doesn't exist: " + metadataFile, metadataFile.exists(), equalTo(true));
    // wait for first 4s
    Thread.sleep(CACHE_TIMEOUT_WAITING_MILLISECONDS);
    // as the metadata re-request, the timeout interval should NOT be re-scheduled
    try (InputStream is = client.content().get(remote, repoId, metadataPath)) {
    }
    // will wait another 4.5s
    Thread.sleep(CACHE_TIMEOUT_WAITING_MILLISECONDS + 500);
    // even meta file re-request @ 4s, normal content timeout should not be rescheduled, so the artifact should be deleted
    assertThat("artifact should be removed even metadata rescheduled with new request", pomFile.exists(), equalTo(false));
}
Also used : InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) PathInfo(org.commonjava.indy.client.core.helper.PathInfo) File(java.io.File) Date(java.util.Date) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 20 with PathInfo

use of org.commonjava.indy.client.core.helper.PathInfo in project indy by Commonjava.

the class ProxyRemoteContentTest method proxyRemoteArtifact.

@Test
public void proxyRemoteArtifact() throws Exception {
    final InputStream stream = new ByteArrayInputStream(("This is a test: " + System.nanoTime()).getBytes());
    final String path = "org/foo/foo-project/1/foo-1.txt";
    server.expect(server.formatUrl(STORE, path), 200, stream);
    client.stores().create(new RemoteRepository(STORE, server.formatUrl(STORE)), "adding test proxy", RemoteRepository.class);
    final PathInfo result = client.content().getInfo(remote, STORE, path);
    assertThat("no result", result, notNullValue());
    assertThat("doesn't exist", result.exists(), equalTo(true));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) PathInfo(org.commonjava.indy.client.core.helper.PathInfo) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Aggregations

PathInfo (org.commonjava.indy.client.core.helper.PathInfo)21 Test (org.junit.Test)19 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)17 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)16 ByteArrayInputStream (java.io.ByteArrayInputStream)12 InputStream (java.io.InputStream)12 File (java.io.File)10 Category (org.junit.experimental.categories.Category)8 Date (java.util.Date)7 Group (org.commonjava.indy.model.core.Group)4 HostedRepository (org.commonjava.indy.model.core.HostedRepository)4 CountDownLatch (java.util.concurrent.CountDownLatch)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 StoreKey (org.commonjava.indy.model.core.StoreKey)2 Before (org.junit.Before)2 HttpResponse (org.apache.http.HttpResponse)1 IndyClientException (org.commonjava.indy.client.core.IndyClientException)1 HttpResources (org.commonjava.indy.client.core.helper.HttpResources)1