Search in sources :

Example 11 with RemoteRepository

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

the class AbstractContentManagementTest method before.

@Before
public void before() throws Exception {
    if (!createStandardTestStructures()) {
        return;
    }
    final String changelog = "Create test structures";
    final HostedRepository hosted = this.client.stores().create(new HostedRepository(STORE), changelog, HostedRepository.class);
    client.stores().delete(remote, CENTRAL, "removing to setup test instance");
    final RemoteRepository central = client.stores().create(new RemoteRepository(CENTRAL, server.formatUrl("central")), changelog, RemoteRepository.class);
    Group g;
    if (client.stores().exists(group, PUBLIC)) {
        System.out.println("Loading pre-existing public group.");
        g = client.stores().load(group, PUBLIC, Group.class);
    } else {
        System.out.println("Creating new group 'public'");
        g = client.stores().create(new Group(PUBLIC), changelog, Group.class);
    }
    g.setConstituents(Arrays.asList(hosted.getKey(), central.getKey()));
    client.stores().update(g, changelog);
}
Also used : Group(org.commonjava.indy.model.core.Group) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Before(org.junit.Before)

Example 12 with RemoteRepository

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

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

the class GroupHttpHeadersFromSameRepoAsPomTest method setupStores.

@Before
public void setupStores() throws Exception {
    String changelog = "test setup";
    repoX = client.stores().create(new RemoteRepository(REPO_X, server.formatUrl(REPO_X)), changelog, RemoteRepository.class);
    repoY = client.stores().create(new RemoteRepository(REPO_Y, server.formatUrl(REPO_Y)), changelog, RemoteRepository.class);
    content2 = CONTENT_2.getBytes("UTF-8");
    server.expect(server.formatUrl(REPO_X, PATH), 200, CONTENT_1);
    server.expect(server.formatUrl(REPO_Y, PATH), 200, new ByteArrayInputStream(content2));
    groupA = client.stores().create(new Group(GROUP_A, repoX.getKey(), repoY.getKey()), changelog, Group.class);
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Before(org.junit.Before)

Example 14 with RemoteRepository

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

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

the class AbstractRemoteRepoTimeoutTest method run.

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));
    setRemoteTimeout(remote1);
    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));
    }
    Thread.sleep(1000);
    RemoteRepository result = client.stores().load(remote, repo1, RemoteRepository.class);
    assertResult(result);
}
Also used : InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyClientException(org.commonjava.indy.client.core.IndyClientException)

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