Search in sources :

Example 56 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class MetadataPassthroughTimeoutWorkingTest method createRemoteRepository.

@Override
protected RemoteRepository createRemoteRepository() {
    final RemoteRepository repository = new RemoteRepository(repoId, server.formatUrl(repoId));
    repository.setPassthrough(true);
    repository.setCacheTimeoutSeconds(CACHE_TIMEOUT_SECONDS);
    repository.setMetadataTimeoutSeconds(METADATA_TIMEOUT_SECONDS);
    return repository;
}
Also used : RemoteRepository(org.commonjava.indy.model.core.RemoteRepository)

Example 57 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository 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 58 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository 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 59 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class NestedStoreInGroupWithErrorTest method run.

@Test
public void run() throws Exception {
    final String path = "org/foo/bar/pom.xml";
    final String repo1 = "repo1";
    final String content = "This is a test: " + System.nanoTime();
    final InputStream stream = new ByteArrayInputStream(content.getBytes());
    server.expect(server.formatUrl(repo1, path), 200, stream);
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    remote1 = client.stores().create(remote1, "adding remote2", RemoteRepository.class);
    final String repo2 = "repo2";
    server.registerException(server.formatUrl(repo2, path), "upstream error", HttpStatus.SC_UNAUTHORIZED);
    RemoteRepository remote2 = new RemoteRepository(repo2, server.formatUrl(repo2));
    remote2.setMetadata(Location.CONNECTION_TIMEOUT_SECONDS, Integer.toString(1));
    remote2 = client.stores().create(remote2, "adding remote2", RemoteRepository.class);
    final String gName = "test";
    Group tgroup = new Group(gName, Arrays.asList(remote2.getKey(), remote1.getKey()));
    client.stores().create(tgroup, "new group with remote2", Group.class);
    try (InputStream is = client.content().get(group, gName, path)) {
        assertThat(IOUtils.toString(is), equalTo(content));
    }
}
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) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 60 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class RemoteRepoGetTimeoutTest method run.

@Test
public void run() throws Exception {
    final String repo1 = "repo1";
    final String path = "org/foo/bar/maven-metadata.xml";
    server.expect(server.formatUrl(repo1, path), 200, new DelayInputStream());
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    remote1.setMetadata(Location.CONNECTION_TIMEOUT_SECONDS, Integer.toString(1));
    remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
    try (InputStream is = client.content().get(remote, repo1, path)) {
    } catch (final IndyClientException e) {
        assertThat(e.getStatusCode(), equalTo(HttpStatus.SC_BAD_GATEWAY));
    }
}
Also used : InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyClientException(org.commonjava.indy.client.core.IndyClientException) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Aggregations

RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)149 Test (org.junit.Test)99 InputStream (java.io.InputStream)52 Group (org.commonjava.indy.model.core.Group)48 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)32 StoreKey (org.commonjava.indy.model.core.StoreKey)31 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)27 ByteArrayInputStream (java.io.ByteArrayInputStream)22 File (java.io.File)17 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)17 HostedRepository (org.commonjava.indy.model.core.HostedRepository)17 PathInfo (org.commonjava.indy.client.core.helper.PathInfo)16 IndyDataException (org.commonjava.indy.data.IndyDataException)14 Before (org.junit.Before)13 Category (org.junit.experimental.categories.Category)12 Date (java.util.Date)10 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)10 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)10 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)9 HttpGet (org.apache.http.client.methods.HttpGet)9