Search in sources :

Example 81 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class ExpiringMemoryNotFoundCacheTest method expireUsingConfiguredValue.

@Test
public void expireUsingConfiguredValue() throws Exception {
    final DefaultIndyConfiguration config = new DefaultIndyConfiguration();
    config.setNotFoundCacheTimeoutSeconds(1);
    final ExpiringMemoryNotFoundCache nfc = new ExpiringMemoryNotFoundCache(config);
    final ConcreteResource res = new ConcreteResource(new SimpleLocation("test:uri"), "/path/to/expired/object");
    nfc.addMissing(res);
    assertThat(nfc.isMissing(res), equalTo(true));
    Thread.sleep(TimeUnit.SECONDS.toMillis(2));
    assertThat(nfc.isMissing(res), equalTo(false));
    final Set<String> locMissing = nfc.getMissing(res.getLocation());
    assertThat(locMissing == null || locMissing.isEmpty(), equalTo(true));
    final Map<Location, Set<String>> allMissing = nfc.getAllMissing();
    assertThat(allMissing == null || allMissing.isEmpty(), equalTo(true));
}
Also used : Set(java.util.Set) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) DefaultIndyConfiguration(org.commonjava.indy.conf.DefaultIndyConfiguration) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 82 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class DownloadManagerTest method downloadOnePOMFromSecondRepositoryAfterDummyRepoFails.

@Test
public void downloadOnePOMFromSecondRepositoryAfterDummyRepoFails() throws Exception {
    final RemoteRepository repo = new RemoteRepository(MAVEN_PKG_KEY, "dummy", "http://www.nowhere.com/");
    final String content = "This is a test";
    final String path = "/org/apache/maven/maven-model/3.0.3/maven-model-3.0.3.pom";
    final RemoteRepository repo2 = new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo.maven.apache.org/maven2");
    fixture.getTransport().registerDownload(new ConcreteResource(new RepositoryLocation(repo2), path), new TestDownload(content.getBytes()));
    data.storeArtifactStore(repo, summary, false, true, new EventMetadata());
    data.storeArtifactStore(repo2, summary, false, true, new EventMetadata());
    final List<ArtifactStore> repos = new ArrayList<ArtifactStore>();
    repos.add(repo);
    repos.add(repo2);
    final Transfer stream = downloader.retrieveFirst(repos, path, new EventMetadata());
    final String downloaded = IOUtils.toString(stream.openInputStream());
    assertThat(downloaded, equalTo(content));
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ArrayList(java.util.ArrayList) Transfer(org.commonjava.maven.galley.model.Transfer) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 83 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class DownloadManagerTest method downloadOnePOMFromSingleRepository.

@Test
public void downloadOnePOMFromSingleRepository() throws Exception {
    final String content = "This is a test";
    final String path = "/org/apache/maven/maven-model/3.0.3/maven-model-3.0.3.pom";
    final RemoteRepository repo = new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo.maven.apache.org/maven2");
    fixture.getTransport().registerDownload(new ConcreteResource(new RepositoryLocation(repo), path), new TestDownload(content.getBytes()));
    data.storeArtifactStore(repo, summary, false, true, new EventMetadata());
    final Transfer stream = downloader.retrieve(repo, path, new EventMetadata());
    final String downloaded = IOUtils.toString(stream.openInputStream());
    assertThat(downloaded, equalTo(content));
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 84 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class NfcStoreContentAction method clearStoreContent.

/**
 * When a path is removed from a store and affected groups, it might because of membership changes. e.g,
 * Group A contains hosted B, and a NFC entry path/to/something exists. If a hosted C is added, we need to
 * clear the NFC entry because the newly added repo may provide such artifact.
 */
@Override
public void clearStoreContent(String path, ArtifactStore store, Set<Group> affectedGroups, boolean clearOriginPath) {
    logger.debug("Clearing NFC path: {}, store: {}, affected: {}", path, store.getKey(), affectedGroups);
    nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(store), path));
    affectedGroups.forEach(group -> nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(group), path)));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource)

Example 85 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class ContentControllerTest method detectHtml_MultipleHtmlElementsOnALine.

@Test
public void detectHtml_MultipleHtmlElementsOnALine() throws Exception {
    final ConcreteResource res = new ConcreteResource(new SimpleLocation("test:uri"), "file.html");
    final Transfer tx = fixture.getCache().getTransfer(res);
    PrintWriter writer = null;
    try {
        writer = new PrintWriter(new OutputStreamWriter(tx.openOutputStream(TransferOperation.GENERATE)));
        writer.print("<html><body><h1>FOO</h1>");
        writer.flush();
    } finally {
        IOUtils.closeQuietly(writer);
    }
    assertThat(content.isHtmlContent(tx), equalTo(true));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)206 Test (org.junit.Test)138 Transfer (org.commonjava.maven.galley.model.Transfer)92 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)55 Location (org.commonjava.maven.galley.model.Location)45 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)36 BMScript (org.jboss.byteman.contrib.bmunit.BMScript)33 OutputStream (java.io.OutputStream)30 InputStream (java.io.InputStream)26 Group (org.commonjava.indy.model.core.Group)25 ArrayList (java.util.ArrayList)23 HostedRepository (org.commonjava.indy.model.core.HostedRepository)23 TransferException (org.commonjava.maven.galley.TransferException)23 SimpleHttpLocation (org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation)23 HashSet (java.util.HashSet)22 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)18 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)18 Logger (org.slf4j.Logger)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)16