Search in sources :

Example 1 with PathInfo

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

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

the class AbstractMetadataTimeoutWorkingTest method setupRepo.

@Before
public void setupRepo() throws Exception {
    final String pomUrl = server.formatUrl(repoId, pomPath);
    final String metadataUrl = server.formatUrl(repoId, metadataPath);
    final String archetypeUrl = server.formatUrl(repoId, archetypePath);
    // 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));
    server.expect(archetypeUrl, 200, String.format("archetype %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 = createRemoteRepository();
    client.stores().create(repository, changelog, RemoteRepository.class);
    // ensure the pom exist before the timeout checking
    final 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));
    pomFile = Paths.get(fixture.getBootOptions().getIndyHome(), "var/lib/indy/storage", MAVEN_PKG_KEY, remote.singularEndpointName() + "-" + repoId, pomPath).toFile();
    assertThat("pom doesn't exist: " + pomFile, pomFile.exists(), equalTo(true));
    // ensure the metadata exist before the timeout checking
    final 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));
    metadataFile = Paths.get(fixture.getBootOptions().getIndyHome(), "var/lib/indy/storage", MAVEN_PKG_KEY, remote.singularEndpointName() + "-" + repoId, metadataPath).toFile();
    assertThat("metadata doesn't exist", metadataFile.exists(), equalTo(true));
    // ensure the archetype exist before the timeout checking
    final PathInfo archetypeResult = client.content().getInfo(remote, repoId, archetypePath);
    // force storage
    client.content().get(remote, repoId, archetypePath).close();
    assertThat("no archetype result", archetypeResult, notNullValue());
    assertThat("archetype doesn't exist", archetypeResult.exists(), equalTo(true));
    archetypeFile = Paths.get(fixture.getBootOptions().getIndyHome(), "var/lib/indy/storage", MAVEN_PKG_KEY, remote.singularEndpointName() + "-" + repoId, archetypePath).toFile();
    assertThat("archetype doesn't exist: " + archetypeFile, archetypeFile.exists(), equalTo(true));
}
Also used : RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) PathInfo(org.commonjava.indy.client.core.helper.PathInfo) Date(java.util.Date) Before(org.junit.Before)

Example 3 with PathInfo

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

the class DownloadContentHasLengthHeaderTest method proxyRemoteArtifact.

@Test
public void proxyRemoteArtifact() throws Exception {
    byte[] data = ("This is a test: " + System.nanoTime()).getBytes();
    final InputStream stream = new ByteArrayInputStream(data);
    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);
    try (HttpResources httpResources = client.module(IndyRawHttpModule.class).getHttp().getRaw(client.content().contentPath(remote, STORE, path))) {
        HttpResponse response = httpResources.getResponse();
        String contentLength = response.getFirstHeader("Content-Length").getValue();
        assertThat("Wrong content-length for download: " + contentLength + " (should have been: " + data.length + ")", contentLength, equalTo(Integer.toString(data.length)));
    }
    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) HttpResources(org.commonjava.indy.client.core.helper.HttpResources) HttpResponse(org.apache.http.HttpResponse) 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)

Example 4 with PathInfo

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

the class IndyFoloContentClientModuleTest method deprecatedContentStore.

@Test
public void deprecatedContentStore() throws Exception {
    String tid = "foo";
    String repo = "central";
    String path = "org/foo/bar/1/bar-1.pom";
    String fullPath = String.format("/api/folo/track/%s/maven/remote/%s/%s", tid, repo, path);
    server.expect("PUT", server.formatUrl(fullPath), 201, "");
    String value = "<project><modelVersion>4.0.0</modelVersion><groupId>org.foo</groupId><artifactId>bar</artifactId>" + "<version>1</version><packaging>pom</packaging></project>";
    PathInfo info = module.store(tid, remote, "central", path, new ByteArrayInputStream(value.getBytes()));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PathInfo(org.commonjava.indy.client.core.helper.PathInfo) Test(org.junit.Test)

Example 5 with PathInfo

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

the class StoreAndVerifyReturnedPathInfoForTrackedHostedRepoTest method storeFileAndVerifyReturnedInfo.

@Test
public void storeFileAndVerifyReturnedInfo() throws Exception {
    final String trackingId = newName();
    final InputStream stream = new ByteArrayInputStream(("This is a test: " + System.nanoTime()).getBytes());
    final String path = "/path/to/foo.class";
    final PathInfo result = client.module(IndyFoloContentClientModule.class).store(trackingId, hosted, STORE, path, stream);
    System.out.println(result);
    assertThat(result, notNullValue());
    assertThat(result.exists(), equalTo(true));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) PathInfo(org.commonjava.indy.client.core.helper.PathInfo) Test(org.junit.Test)

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