use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class ContentIndexDirLvWithArtifactsTest method test.
@Test
public void test() throws Exception {
final String remoteName1 = newName();
RemoteRepository remote1 = new RemoteRepository(MAVEN_PKG_KEY, remoteName1, server.formatUrl(remoteName1));
remote1 = client.stores().create(remote1, name.getMethodName(), RemoteRepository.class);
final String remoteName2 = newName();
RemoteRepository remote2 = new RemoteRepository(MAVEN_PKG_KEY, remoteName2, server.formatUrl(remoteName2));
remote2 = client.stores().create(remote2, name.getMethodName(), RemoteRepository.class);
final String groupName = newName();
Group group = new Group(MAVEN_PKG_KEY, groupName, remote1.getKey(), remote2.getKey());
group = client.stores().create(group, name.getMethodName(), Group.class);
server.expect(server.formatUrl(remoteName2, PATH_JAR), 200, PATH_JAR_CONTENT);
server.expect(server.formatUrl(remoteName2, PATH_POM), 200, PATH_POM_CONTENT);
final String CHECKSUM_CONTENT = newName();
for (String checksumPath : PATHS_CHECKSUM) {
server.expect(server.formatUrl(remoteName2, checksumPath), 200, CHECKSUM_CONTENT);
}
try (InputStream s = client.content().get(group.getKey(), PATH_JAR)) {
assertThat(IOUtils.toString(s), equalTo(PATH_JAR_CONTENT));
}
try (InputStream s = client.content().get(group.getKey(), PATH_JAR)) {
assertThat(IOUtils.toString(s), equalTo(PATH_JAR_CONTENT));
}
for (String checksumPath : PATHS_CHECKSUM) {
try (InputStream s = client.content().get(group.getKey(), checksumPath)) {
assertThat(IOUtils.toString(s), equalTo(CHECKSUM_CONTENT));
}
}
AdvancedCache<IndexedStorePath, IndexedStorePath> advancedCache = (AdvancedCache) contentIndex.execute(c -> c);
System.out.println("[Content index DEBUG]: cached isps: " + advancedCache.keySet());
for (IndexedStorePath value : advancedCache.values()) {
boolean match = remote2.getKey().equals(value.getOriginStoreKey()) || remote2.getKey().equals(value.getStoreKey());
assertThat(match, equalTo(true));
}
System.out.println("[Content index DEBUG]: cache size:" + advancedCache.size());
assertTrue(advancedCache.size() <= 2);
System.out.println("[Content index DEBUG]: cache hit:" + advancedCache.getStats().getHits());
assertTrue(advancedCache.getStats().getHits() >= 7);
System.out.println("[Content index DEBUG]: cache misses:" + advancedCache.getStats().getMisses());
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class ContentIndexGroupUsageTest method bypassNotIndexedContentWithAuthoritativeIndex.
@Test
public void bypassNotIndexedContentWithAuthoritativeIndex() throws Exception {
final String repoName = newName();
RemoteRepository repo = new RemoteRepository(MAVEN_PKG_KEY, repoName, server.formatUrl(repoName));
repo = client.stores().create(repo, name.getMethodName(), RemoteRepository.class);
server.expect(server.formatUrl(repoName, FIRST_PATH), 200, FIRST_PATH_CONTENT);
String groupName = newName();
Group group = new Group(MAVEN_PKG_KEY, groupName, repo.getKey());
group = client.stores().create(group, name.getMethodName(), Group.class);
StoreKey indexedStoreKey = indexManager.getIndexedStoreKey(repo.getKey(), FIRST_PATH);
logger.info("\n\n\nBEFORE: Indexed path entry: " + indexedStoreKey + "\n\n\n\n");
assertThat(indexedStoreKey, nullValue());
try (InputStream first = client.content().get(repo.getKey(), FIRST_PATH)) {
assertThat(IOUtils.toString(first), equalTo(FIRST_PATH_CONTENT));
}
indexedStoreKey = indexManager.getIndexedStoreKey(repo.getKey(), FIRST_PATH);
logger.info("\n\n\nAFTER remote: Remote-level indexed path entry: " + indexedStoreKey + "\n\n\n\n");
assertThat(indexedStoreKey, notNullValue());
try (InputStream first = client.content().get(group.getKey(), FIRST_PATH)) {
assertThat(IOUtils.toString(first), equalTo(FIRST_PATH_CONTENT));
}
indexedStoreKey = indexManager.getIndexedStoreKey(group.getKey(), FIRST_PATH);
logger.info("\n\n\nAFTER group: Group-level indexed path entry: " + indexedStoreKey + "\n\n\n\n");
assertThat(indexedStoreKey, notNullValue());
// indexedStoreKey = indexManager.getIndexedStoreKey( repo.getKey(), FIRST_PATH );
// logger.info( "\n\n\nAFTER group: Remote-level indexed path entry: " + indexedStoreKey + "\n\n\n\n");
// assertThat( indexedStoreKey, notNullValue() );
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class RepositoryFilterGACacheTest method run.
/* @formatter:on */
@Test
public // @Ignore( "Test validation relies on log message stability, which is not something we test for")
void run() throws Exception {
BufferedLogAppender bufferedLogAppender = prepareTestAppender();
final String remoteR = "R";
final String build_1 = "build-1";
final String build_2 = "build-2";
final String build_3 = "build-3";
final String build_4 = "build-4";
final String npc_builds = "npc_builds";
final String groupG = "G";
RemoteRepository remote = prepareRemote(remoteR, A_0, V1);
HostedRepository hosted_1 = prepareHosted(build_1, A_1, V2_1);
HostedRepository hosted_2 = prepareHosted(build_2, A_1, V2_2);
HostedRepository hosted_3 = prepareHosted(build_3, A_2, V2_1);
HostedRepository hosted_4 = prepareHosted(build_4, A_2, V2_2);
HostedRepository hosted_npc_builds = prepareHosted(npc_builds, A_1, V1);
hosted_npc_builds = prepareHosted(npc_builds, A_2, V1);
List<StoreKey> storeKeys = new ArrayList<>();
storeKeys.add(hosted_1.getKey());
storeKeys.add(hosted_2.getKey());
storeKeys.add(hosted_3.getKey());
storeKeys.add(hosted_4.getKey());
storeKeys.add(hosted_npc_builds.getKey());
storeKeys.add(remote.getKey());
// add confusing repos, hope it is not confused
for (int i = 100; i < 200; i++) {
HostedRepository h = client.stores().create(new HostedRepository(MAVEN_PKG_KEY, "build-" + i), "Add hosted-" + i, HostedRepository.class);
storeKeys.add(h.getKey());
}
// create group G
StoreKey[] keyArray = new StoreKey[storeKeys.size()];
Group g = client.stores().create(new Group(MAVEN_PKG_KEY, groupG, storeKeys.toArray(keyArray)), "Add group", Group.class);
System.out.printf("\n\nGroup constituents are:\n %s\n\n", StringUtils.join(g.getConstituents(), "\n "));
// fill the GA cache (because when test fixture starts up the repos are not created yet)
CDI.current().select(PathMappedMavenGACache.class).get().fill();
ResultBufferingGroupRepoFilter filterBuffer = CDI.current().select(ResultBufferingGroupRepoFilter.class).get();
Thread.sleep(10);
// get pom
String pomPath = getPomPath(A_0, V1);
try (InputStream stream = client.content().get(g.getKey(), pomPath)) {
String str = IOUtils.toString(stream);
System.out.println(">>>> " + pomPath + "\n" + str);
assertThat(str, containsString("<artifactId>" + A_0 + "</artifactId>"));
assertThat(str, containsString("<version>" + V1 + "</version>"));
}
assertEquals(Arrays.asList(hosted_npc_builds, remote), filterBuffer.getFilteredRepositories(pomPath, g));
// checkLogMessage( pomPath, bufferedLogAppender.getMessages().toString(),
// "[maven:hosted:npc_builds, maven:remote:R]" );
pomPath = getPomPath(A_1, V2_1);
try (InputStream stream = client.content().get(g.getKey(), pomPath)) {
String str = IOUtils.toString(stream);
System.out.println(">>>> " + pomPath + "\n" + str);
assertThat(str, containsString("<artifactId>" + A_1 + "</artifactId>"));
assertThat(str, containsString("<version>" + V2_1 + "</version>"));
}
assertEquals(Arrays.asList(hosted_1, hosted_2, hosted_npc_builds, remote), filterBuffer.getFilteredRepositories(pomPath, g));
// checkLogMessage( pomPath, bufferedLogAppender.getMessages().toString(),
// "[maven:hosted:build-1, maven:hosted:build-2, maven:hosted:npc_builds, maven:remote:R]" );
pomPath = getPomPath(A_2, V2_1);
try (InputStream stream = client.content().get(g.getKey(), pomPath)) {
String str = IOUtils.toString(stream);
System.out.println(">>>> " + pomPath + "\n" + str);
assertThat(str, containsString("<artifactId>" + A_2 + "</artifactId>"));
assertThat(str, containsString("<version>" + V2_1 + "</version>"));
}
assertEquals(Arrays.asList(hosted_3, hosted_4, hosted_npc_builds, remote), filterBuffer.getFilteredRepositories(pomPath, g));
// checkLogMessage( pomPath, bufferedLogAppender.getMessages().toString(),
// "[maven:hosted:build-3, maven:hosted:build-4, maven:hosted:npc_builds, maven:remote:R]" );
pomPath = getPomPath(A_1, V1);
try (InputStream stream = client.content().get(g.getKey(), pomPath)) {
String str = IOUtils.toString(stream);
System.out.println(">>>> " + pomPath + "\n" + str);
assertThat(str, containsString("<artifactId>" + A_1 + "</artifactId>"));
assertThat(str, containsString("<version>" + V1 + "</version>"));
}
assertEquals(Arrays.asList(hosted_1, hosted_2, hosted_npc_builds, remote), filterBuffer.getFilteredRepositories(pomPath, g));
// checkLogMessage( pomPath, bufferedLogAppender.getMessages().toString(),
// "[maven:hosted:build-1, maven:hosted:build-2, maven:hosted:npc_builds, maven:remote:R]" );
// get metadata
String metadataPath = getMetadataPath(A_0);
try (InputStream stream = client.content().get(g.getKey(), metadataPath)) {
String str = IOUtils.toString(stream);
System.out.println(">>>> " + metadataPath + "\n" + str);
assertThat(str, containsString("<artifactId>" + A_0 + "</artifactId>"));
assertThat(str, containsString("<version>" + V1 + "</version>"));
}
assertEquals(Arrays.asList(hosted_npc_builds, remote), filterBuffer.getFilteredRepositories(metadataPath, g));
// checkLogMessage( metadataPath, bufferedLogAppender.getMessages().toString(),
// "[maven:hosted:npc_builds, maven:remote:R]" );
metadataPath = getMetadataPath(A_1);
try (InputStream stream = client.content().get(g.getKey(), metadataPath)) {
String str = IOUtils.toString(stream);
System.out.println(">>>> " + metadataPath + "\n" + str);
assertThat(str, containsString("<artifactId>" + A_1 + "</artifactId>"));
assertThat(str, containsString("<version>" + V1 + "</version>"));
assertThat(str, containsString("<version>" + V2_1 + "</version>"));
assertThat(str, containsString("<version>" + V2_2 + "</version>"));
}
assertEquals(Arrays.asList(hosted_1, hosted_2, hosted_npc_builds, remote), filterBuffer.getFilteredRepositories(metadataPath, g));
// checkLogMessage( metadataPath, bufferedLogAppender.getMessages().toString(),
// "[maven:hosted:build-1, maven:hosted:build-2, maven:hosted:npc_builds, maven:remote:R]" );
metadataPath = getMetadataPath(A_2);
try (InputStream stream = client.content().get(g.getKey(), metadataPath)) {
String str = IOUtils.toString(stream);
System.out.println(">>>> " + metadataPath + "\n" + str);
assertThat(str, containsString("<artifactId>" + A_2 + "</artifactId>"));
assertThat(str, containsString("<version>" + V1 + "</version>"));
assertThat(str, containsString("<version>" + V2_1 + "</version>"));
assertThat(str, containsString("<version>" + V2_2 + "</version>"));
}
assertEquals(Arrays.asList(hosted_3, hosted_4, hosted_npc_builds, remote), filterBuffer.getFilteredRepositories(metadataPath, g));
// checkLogMessage( metadataPath, bufferedLogAppender.getMessages().toString(),
// "[maven:hosted:build-3, maven:hosted:build-4, maven:hosted:npc_builds, maven:remote:R]" );
//
String messages = bufferedLogAppender.getMessages().toString();
System.out.println(">>>>\n{\n" + messages + "}\n\n");
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class RepositoryPathMaskExistsTest method run.
@Test
public void run() throws Exception {
final String content = "{\"content\": \"This is a test: " + System.nanoTime() + "\"}";
final String path_1 = "org/foo/foo-project/1/a.out.txt";
// not in masks
final String path_2 = "org/bar/bar-project/1/a.out.txt";
final String repo1 = "repo1";
server.expect(server.formatUrl(repo1, path_1), 200, new ByteArrayInputStream(content.getBytes()));
server.expect(server.formatUrl(repo1, path_2), 200, new ByteArrayInputStream(content.getBytes()));
RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
Set<String> pathMaskPatterns = new HashSet<>();
pathMaskPatterns.add("org/foo");
remote1.setPathMaskPatterns(pathMaskPatterns);
remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
Group g = new Group("test", remote1.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 "));
// get stream for path-1 via group (success)
boolean result = client.content().exists(group, g.getName(), path_1);
assertThat(result, equalTo(true));
// get stream for path_2 via group (null)
result = client.content().exists(group, g.getName(), path_2);
assertThat(result, equalTo(false));
// get stream for path_1 via concrete store (success)
result = client.content().exists(remote, remote1.getName(), path_1);
assertThat(result, equalTo(true));
// get stream for path_2 via concrete repo (null)
result = client.content().exists(remote, remote1.getName(), path_2);
assertThat(result, equalTo(false));
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class RepositoryPathMaskMetadataExcludeTest method run.
/**
* Case where user requests maven-metadata.xml from a group. The group contains two repositories.
* One repository have path masks to exclude the metadata paths, but the other repository shouldn't mask any paths.
*
* The group maven-metadata.xml should exclude versions from the member that un-mask the path
*/
@Test
public void run() throws Exception {
final String path_metadata = "org/bar/bar-project/maven-metadata.xml";
final String remote1 = "remote1";
final String hosted1 = "hosted1";
server.expect(server.formatUrl(remote1, path_metadata), 200, meta1);
RemoteRepository remoteRepo1 = new RemoteRepository(remote1, server.formatUrl(remote1));
Set<String> pathMaskPatterns = new HashSet<>();
// regex patterns, un-mask org/bar
pathMaskPatterns.add("r|org/foo.*|");
remoteRepo1.setPathMaskPatterns(pathMaskPatterns);
remoteRepo1 = client.stores().create(remoteRepo1, "adding remote 1", RemoteRepository.class);
HostedRepository hostedRepo1 = new HostedRepository(hosted1);
hostedRepo1 = client.stores().create(hostedRepo1, "adding hosted 1", HostedRepository.class);
client.content().store(hosted, hosted1, path_metadata, new ByteArrayInputStream(meta2.getBytes()));
Group g = new Group("group1", remoteRepo1.getKey(), hostedRepo1.getKey());
g = client.stores().create(g, "adding group1", Group.class);
System.out.printf("\n\nGroup constituents are:\n %s\n\n", StringUtils.join(g.getConstituents(), "\n "));
InputStream stream = null;
String str = null;
// get metadata from hosted1
stream = client.content().get(hosted, hostedRepo1.getName(), path_metadata);
assertThat(stream, notNullValue());
str = IOUtils.toString(stream);
System.out.println("hosted1.metadata >>>> " + str);
stream.close();
// get metadata from remote1
stream = client.content().get(remote, remoteRepo1.getName(), path_metadata);
assertThat(stream, nullValue());
// get metadata from group1
stream = client.content().get(group, g.getName(), path_metadata);
assertThat(stream, notNullValue());
// return aggregated versions from all repositories with valid mask
str = IOUtils.toString(stream);
System.out.println("group1.metadata >>>> " + str);
assertThat(str.trim(), equalTo(aggregatedMeta));
stream.close();
}
Aggregations