Search in sources :

Example 6 with PathInfo

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

the class GroupMetaOverlapWithMetaOfHostedReposTest method run.

@Test
@Category(EventDependent.class)
public void run() throws Exception {
    final String repo1 = "repo1";
    final String repo2 = "repo2";
    final String path = "org/foo/bar/maven-metadata.xml";
    /* @formatter:off */
    final String repo1Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + "  <groupId>org.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <versioning>\n" + "    <latest>1.0</latest>\n" + "    <release>1.0</release>\n" + "    <versions>\n" + "      <version>1.0</version>\n" + "    </versions>\n" + "    <lastUpdated>20150722164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    /* @formatter:off */
    final String repo2Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + "  <groupId>org.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <versioning>\n" + "    <latest>1.1</latest>\n" + "    <release>1.1</release>\n" + "    <versions>\n" + "      <version>1.1</version>\n" + "    </versions>\n" + "    <lastUpdated>20150822164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    server.expect(server.formatUrl(repo1, path), 200, repo1Content);
    server.expect(server.formatUrl(repo2, path), 200, repo2Content);
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
    RemoteRepository remote2 = new RemoteRepository(repo2, server.formatUrl(repo2));
    remote2 = client.stores().create(remote2, "adding remote", RemoteRepository.class);
    Group g = new Group("test", remote1.getKey(), remote2.getKey());
    g = client.stores().create(g, "adding group", Group.class);
    System.out.printf("\n\nGroup constituents are:\n  %s\n\n", StringUtils.join(g.getConstituents(), "\n  "));
    InputStream stream = client.content().get(group, g.getName(), path);
    assertThat(stream, notNullValue());
    String metadata = IOUtils.toString(stream);
    /* @formatter:off */
    final String groupContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + "  <groupId>org.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <versioning>\n" + "    <latest>1.1</latest>\n" + "    <release>1.1</release>\n" + "    <versions>\n" + "      <version>1.0</version>\n" + "      <version>1.1</version>\n" + "    </versions>\n" + "    <lastUpdated>20150822164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    assertThat(metadata, equalTo(groupContent));
    final String hostedRepo = "hostedRepo";
    HostedRepository hostedRepository = new HostedRepository(hostedRepo);
    hostedRepository = client.stores().create(hostedRepository, "adding hosted", HostedRepository.class);
    /* @formatter:off */
    final String hostedMetaContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + "  <groupId>org.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <versioning>\n" + "    <latest>1.2</latest>\n" + "    <release>1.2</release>\n" + "    <versions>\n" + "      <version>1.2</version>\n" + "    </versions>\n" + "    <lastUpdated>20150922164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    client.content().store(hostedRepository.getKey(), path, new ByteArrayInputStream(hostedMetaContent.getBytes("UTF-8")));
    final PathInfo p = client.content().getInfo(hosted, hostedRepo, path);
    assertThat("hosted metadata should exist", p.exists(), equalTo(true));
    g.addConstituent(hostedRepository);
    client.stores().update(g, "add new hosted");
    System.out.printf("\n\nUpdated group constituents are:\n  %s\n\n", StringUtils.join(g.getConstituents(), "\n  "));
    waitForEventPropagation();
    final String gpLevelMetaFilePath = String.format("%s/var/lib/indy/storage/%s-%s/%s", fixture.getBootOptions().getIndyHome(), group.name(), g.getName(), path);
    assertThat("group metadata should be removed after merging", new File(gpLevelMetaFilePath).exists(), equalTo(false));
    stream = client.content().get(group, g.getName(), path);
    assertThat(stream, notNullValue());
    metadata = IOUtils.toString(stream);
    /* @formatter:off */
    final String updGroupContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + "  <groupId>org.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <versioning>\n" + "    <latest>1.2</latest>\n" + "    <release>1.2</release>\n" + "    <versions>\n" + "      <version>1.0</version>\n" + "      <version>1.1</version>\n" + "      <version>1.2</version>\n" + "    </versions>\n" + "    <lastUpdated>20150922164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    assertThat(metadata, equalTo(updGroupContent));
}
Also used : Group(org.commonjava.indy.model.core.Group) 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) File(java.io.File) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 7 with PathInfo

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

the class GroupMetaOverlapWithNestedGroupOfHostRepoMetaTest method run.

@Test
@Category(EventDependent.class)
public void run() throws Exception {
    final String repo1 = "repo1";
    final String repo2 = "repo2";
    final String path = "org/foo/bar/maven-metadata.xml";
    /* @formatter:off */
    final String repo1Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + "  <groupId>org.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <versioning>\n" + "    <latest>1.0</latest>\n" + "    <release>1.0</release>\n" + "    <versions>\n" + "      <version>1.0</version>\n" + "    </versions>\n" + "    <lastUpdated>20150722164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    /* @formatter:off */
    final String repo2Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + "  <groupId>org.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <versioning>\n" + "    <latest>1.1</latest>\n" + "    <release>1.1</release>\n" + "    <versions>\n" + "      <version>1.1</version>\n" + "    </versions>\n" + "    <lastUpdated>20150822164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    server.expect(server.formatUrl(repo1, path), 200, repo1Content);
    server.expect(server.formatUrl(repo2, path), 200, repo2Content);
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
    RemoteRepository remote2 = new RemoteRepository(repo2, server.formatUrl(repo2));
    remote2 = client.stores().create(remote2, "adding remote", RemoteRepository.class);
    // constructs 3 level group structure: top -> middle -> bottom
    // and the bottom group contains repo1 and repo2
    Group bottomGroup = new Group("bottom", remote1.getKey(), remote2.getKey());
    bottomGroup = client.stores().create(bottomGroup, "adding bottom group", Group.class);
    System.out.printf("\n\nBottom group constituents are:\n  %s\n\n", StringUtils.join(bottomGroup.getConstituents(), "\n  "));
    Group middleGroup = new Group("middle", bottomGroup.getKey());
    middleGroup = client.stores().create(middleGroup, "adding middle group", Group.class);
    System.out.printf("\n\nMiddle group constituents are:\n  %s\n\n", StringUtils.join(middleGroup.getConstituents(), "\n  "));
    Group topGroup = new Group("top", middleGroup.getKey());
    topGroup = client.stores().create(topGroup, "adding top group", Group.class);
    System.out.printf("\n\nTop group constituents are:\n  %s\n\n", StringUtils.join(topGroup.getConstituents(), "\n  "));
    InputStream stream = client.content().get(group, topGroup.getName(), path);
    assertThat(stream, notNullValue());
    String metadata = IOUtils.toString(stream);
    stream.close();
    /* @formatter:off */
    final String groupContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + "  <groupId>org.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <versioning>\n" + "    <latest>1.1</latest>\n" + "    <release>1.1</release>\n" + "    <versions>\n" + "      <version>1.0</version>\n" + "      <version>1.1</version>\n" + "    </versions>\n" + "    <lastUpdated>20150822164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    assertThat(metadata, equalTo(groupContent));
    final String hostedRepo = "hostedRepo";
    HostedRepository hostedRepository = new HostedRepository(hostedRepo);
    hostedRepository = client.stores().create(hostedRepository, "adding hosted", HostedRepository.class);
    /* @formatter:off */
    final String hostedMetaContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + "  <groupId>org.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <versioning>\n" + "    <latest>1.2</latest>\n" + "    <release>1.2</release>\n" + "    <versions>\n" + "      <version>1.2</version>\n" + "    </versions>\n" + "    <lastUpdated>20150922164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    client.content().store(hostedRepository.getKey(), path, new ByteArrayInputStream(hostedMetaContent.getBytes("UTF-8")));
    final PathInfo p = client.content().getInfo(hosted, hostedRepo, path);
    assertThat("hosted metadata should exist", p.exists(), equalTo(true));
    // added hosted repo to bottom group and update
    bottomGroup.addConstituent(hostedRepository);
    client.stores().update(bottomGroup, "add new hosted to bottom");
    System.out.printf("\n\nUpdated bottom group constituents are:\n  %s\n\n", StringUtils.join(bottomGroup.getConstituents(), "\n  "));
    waitForEventPropagation();
    // the top group should reflect the meta file deprecation and re-indexing
    final String gpLevelMetaFilePath = String.format("%s/var/lib/indy/storage/%s-%s/%s", fixture.getBootOptions().getIndyHome(), group.name(), topGroup.getName(), path);
    assertThat("group metadata should be removed after merging", new File(gpLevelMetaFilePath).exists(), equalTo(false));
    stream = client.content().get(group, topGroup.getName(), path);
    assertThat(stream, notNullValue());
    metadata = IOUtils.toString(stream);
    stream.close();
    /* @formatter:off */
    final String updGroupContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + "  <groupId>org.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <versioning>\n" + "    <latest>1.2</latest>\n" + "    <release>1.2</release>\n" + "    <versions>\n" + "      <version>1.0</version>\n" + "      <version>1.1</version>\n" + "      <version>1.2</version>\n" + "    </versions>\n" + "    <lastUpdated>20150922164334</lastUpdated>\n" + "  </versioning>\n" + "</metadata>\n";
    /* @formatter:on */
    assertThat(metadata, equalTo(updGroupContent));
}
Also used : Group(org.commonjava.indy.model.core.Group) 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) File(java.io.File) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 8 with PathInfo

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

the class MetadataRescheduleTimeoutTest method timeout.

@Test
@Category(TimingDependent.class)
public void timeout() throws Exception {
    final int METADATA_TIMEOUT_SECONDS = 4;
    final int METADATA_TIMEOUT_WAITING_MILLISECONDS = 2500;
    final String repoId = "test-repo";
    final String metadataPath = "org/foo/bar/maven-metadata.xml";
    final String metadataUrl = server.formatUrl(repoId, metadataPath);
    // mocking up a http server that expects access to metadata
    final String datetime = (new Date()).toString();
    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.setMetadataTimeoutSeconds(METADATA_TIMEOUT_SECONDS);
    client.stores().create(repository, changelog, RemoteRepository.class);
    // first time trigger normal content storage with timeout, should be 4s
    PathInfo pomResult = client.content().getInfo(remote, repoId, metadataPath);
    // force storage
    client.content().get(remote, repoId, metadataPath).close();
    assertThat("no metadata result", pomResult, notNullValue());
    assertThat("metadata doesn't exist", pomResult.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.exists(), equalTo(true));
    // wait for first 2.5s
    Thread.sleep(METADATA_TIMEOUT_WAITING_MILLISECONDS);
    // as the metadata content re-request, the metadata timeout interval should NOT be re-scheduled
    client.content().get(remote, repoId, metadataPath).close();
    // will wait another 4s
    Thread.sleep(METADATA_TIMEOUT_WAITING_MILLISECONDS + 1500);
    // as rescheduled, the artifact should not be deleted
    assertThat("artifact should be removed as the rescheduled of metadata should not succeed", metadataFile.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 9 with PathInfo

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

the class RoutedCacheProviderForRemoteTest method proxyRemoteAndNFSNotSetup.

@Test
public void proxyRemoteAndNFSNotSetup() throws Exception {
    final String repo1 = "repo1";
    final String pomPath = "org/foo/bar/1.0/bar-1.0.pom";
    final String pomUrl = server.formatUrl(repo1, pomPath);
    final String datetime = (new Date()).toString();
    server.expect(pomUrl, 200, String.format("pom %s", datetime));
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    client.stores().create(remote1, "adding remote", RemoteRepository.class);
    final PathInfo result = client.content().getInfo(remote, repo1, pomPath);
    assertThat("no result", result, notNullValue());
    assertThat("doesn't exist", result.exists(), equalTo(true));
    final File nfsStorage = Paths.get(fixture.getBootOptions().getIndyHome(), NFS_BASE).toFile();
    assertThat(nfsStorage.exists(), equalTo(true));
    assertThat(nfsStorage.list().length, equalTo(0));
}
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) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 10 with PathInfo

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

the class RemoteRepoHeadExistenceCheckTest method run.

@Ignore
@Test
public void run() throws Exception {
    final InputStream stream = new ByteArrayInputStream(("{\"content\": \"This is a test: " + System.nanoTime() + "\"}").getBytes());
    final String path = "org/foo/foo-project/1/foo-1.txt";
    final String nonExistPath = "org/foo/foo-project/1/foo-2.txt";
    server.expect(server.formatUrl(STORE, path), 200, stream);
    server.expect(server.formatUrl(STORE, nonExistPath), 404, "not exist");
    client.stores().create(new RemoteRepository(STORE, server.formatUrl(STORE)), "adding test proxy", RemoteRepository.class);
    final PathInfo result = client.content().getInfo(remote, STORE, path);
    try {
        boolean exists = client.content().exists(remote, STORE, path);
        assertTrue(exists);
        File f = new File(new File(fixture.getBootOptions().getIndyHome()), "var/lib/indy/storage/remote-test/" + path);
        assertTrue(!f.exists());
        //TODO: this breaks because for whatever reason the head can not get content-length and we have to fall over to get().
        //Refer to NCL-2729 and we will have a better fix in future
        exists = client.content().exists(remote, STORE, nonExistPath);
        assertFalse(exists);
    } catch (final IndyClientException e) {
        fail("IndyClientException: " + e);
    }
}
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) IndyClientException(org.commonjava.indy.client.core.IndyClientException) File(java.io.File) Ignore(org.junit.Ignore) 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