use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.
the class PromotionManagerTest method promoteAllByPath_PushTwoArtifactsToHostedRepo_DryRun_VerifyPendingPathsPopulated.
@Test
public void promoteAllByPath_PushTwoArtifactsToHostedRepo_DryRun_VerifyPendingPathsPopulated() throws Exception {
final HostedRepository source = new HostedRepository(MAVEN_PKG_KEY, "source");
storeManager.storeArtifactStore(source, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
final String first = "/first/path";
final String second = "/second/path";
contentManager.store(source, first, new ByteArrayInputStream("This is a test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
contentManager.store(source, second, new ByteArrayInputStream("This is a test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
final HostedRepository target = new HostedRepository(MAVEN_PKG_KEY, "target");
storeManager.storeArtifactStore(target, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
final PathsPromoteResult result = manager.promotePaths(new PathsPromoteRequest(source.getKey(), target.getKey()).setDryRun(true), FAKE_BASE_URL);
assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
final Set<String> completed = result.getCompletedPaths();
assertThat(completed == null || completed.isEmpty(), equalTo(true));
final Set<String> pending = result.getPendingPaths();
assertThat(pending, notNullValue());
assertThat(pending.size(), equalTo(2));
assertThat(result.getError(), nullValue());
Transfer ref = downloadManager.getStorageReference(target, first);
assertThat(ref.exists(), equalTo(false));
ref = downloadManager.getStorageReference(target, second);
assertThat(ref.exists(), equalTo(false));
}
use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.
the class PromotionManagerTest method promoteAllByPath_PurgeSource_PushTwoArtifactsToHostedRepo_VerifyCopiedToOtherHostedRepo.
@Test
public void promoteAllByPath_PurgeSource_PushTwoArtifactsToHostedRepo_VerifyCopiedToOtherHostedRepo() throws Exception {
final HostedRepository source = new HostedRepository(MAVEN_PKG_KEY, "source");
storeManager.storeArtifactStore(source, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
final String first = "/first/path";
final String second = "/second/path";
contentManager.store(source, first, new ByteArrayInputStream("This is a test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
contentManager.store(source, second, new ByteArrayInputStream("This is a test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
final HostedRepository target = new HostedRepository(MAVEN_PKG_KEY, "target");
storeManager.storeArtifactStore(target, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
final PathsPromoteResult result = manager.promotePaths(new PathsPromoteRequest(source.getKey(), target.getKey()).setPurgeSource(true), FAKE_BASE_URL);
assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
final Set<String> pending = result.getPendingPaths();
assertThat(pending == null || pending.isEmpty(), equalTo(true));
final Set<String> completed = result.getCompletedPaths();
assertThat(completed, notNullValue());
assertThat(completed.size(), equalTo(2));
assertThat(result.getError(), nullValue());
Transfer ref = downloadManager.getStorageReference(target, first);
assertThat(ref.exists(), equalTo(true));
ref = downloadManager.getStorageReference(target, second);
assertThat(ref.exists(), equalTo(true));
// source artifacts should be deleted.
ref = downloadManager.getStorageReference(source, first);
assertThat(ref.exists(), equalTo(false));
ref = downloadManager.getStorageReference(source, second);
assertThat(ref.exists(), equalTo(false));
}
use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.
the class PromotionManagerTest method promoteAllByPath_RaceToPromote_FirstLocksTargetStore.
@Test
public void promoteAllByPath_RaceToPromote_FirstLocksTargetStore() throws Exception {
Random rand = new Random();
final HostedRepository[] sources = { new HostedRepository(MAVEN_PKG_KEY, "source1"), new HostedRepository(MAVEN_PKG_KEY, "source2") };
final String[] paths = { "/path/path1", "/path/path2", "/path3", "/path/path/4" };
Stream.of(sources).forEach((source) -> {
try {
storeManager.storeArtifactStore(source, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
Stream.of(paths).forEach((path) -> {
byte[] buf = new byte[1024 * 1024 * 2];
rand.nextBytes(buf);
try {
contentManager.store(source, path, new ByteArrayInputStream(buf), TransferOperation.UPLOAD, new EventMetadata());
} catch (IndyWorkflowException e) {
e.printStackTrace();
Assert.fail("failed to store generated file to: " + source + path);
}
});
} catch (IndyDataException e) {
e.printStackTrace();
Assert.fail("failed to store hosted repository: " + source);
}
});
final HostedRepository target = new HostedRepository(MAVEN_PKG_KEY, "target");
storeManager.storeArtifactStore(target, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
PathsPromoteResult[] results = new PathsPromoteResult[2];
CountDownLatch cdl = new CountDownLatch(2);
AtomicInteger counter = new AtomicInteger(0);
Stream.of(sources).forEach((source) -> {
int idx = counter.getAndIncrement();
executor.execute(() -> {
try {
results[idx] = manager.promotePaths(new PathsPromoteRequest(source.getKey(), target.getKey(), paths), FAKE_BASE_URL);
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Promotion from source: " + source + " failed.");
} finally {
cdl.countDown();
}
});
try {
Thread.sleep(25);
} catch (InterruptedException e) {
Assert.fail("Test interrupted");
}
});
assertThat("Promotions failed to finish.", cdl.await(30, TimeUnit.SECONDS), equalTo(true));
// first one should succeed.
PathsPromoteResult result = results[0];
assertThat(result.getRequest().getSource(), equalTo(sources[0].getKey()));
assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
Set<String> pending = result.getPendingPaths();
assertThat(pending == null || pending.isEmpty(), equalTo(true));
Set<String> skipped = result.getSkippedPaths();
assertThat(skipped == null || skipped.isEmpty(), equalTo(true));
Set<String> completed = result.getCompletedPaths();
assertThat(completed, notNullValue());
assertThat(completed.size(), equalTo(paths.length));
assertThat(result.getError(), nullValue());
Stream.of(paths).forEach((path) -> {
HostedRepository src = sources[0];
Transfer sourceRef = downloadManager.getStorageReference(src, path);
Transfer targetRef = downloadManager.getStorageReference(target, path);
assertThat(targetRef.exists(), equalTo(true));
try (InputStream sourceIn = sourceRef.openInputStream();
InputStream targetIn = targetRef.openInputStream()) {
int s = -1, t = -1;
while ((s = sourceIn.read()) == (t = targetIn.read())) {
if (s == -1) {
break;
}
}
if (s != -1 && s != t) {
Assert.fail(path + " doesn't match between source: " + src + " and target: " + target);
}
} catch (IOException e) {
e.printStackTrace();
Assert.fail("Failed to compare contents of: " + path + " between source: " + src + " and target: " + target);
}
});
// second one should be completely skipped.
result = results[1];
assertThat(result.getRequest().getSource(), equalTo(sources[1].getKey()));
assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
pending = result.getPendingPaths();
assertThat(pending == null || pending.isEmpty(), equalTo(true));
skipped = result.getSkippedPaths();
assertThat(skipped, notNullValue());
assertThat(skipped.size(), equalTo(paths.length));
completed = result.getCompletedPaths();
assertThat(completed == null || completed.isEmpty(), equalTo(true));
assertThat(result.getError(), nullValue());
}
use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.
the class CacheCheckingforPromoteWithRemoteTest method start.
@Before
public void start() throws Throwable {
super.start();
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("client:{}", client);
module = client.module(IndyPromoteClientModule.class);
h = new HostedRepository(hId);
h = client.stores().create(h, "Creating h", HostedRepository.class);
r = new RemoteRepository(rId, server.formatUrl(rId));
r = client.stores().create(r, "Creating r", RemoteRepository.class);
g = new Group(gId, h.getKey(), r.getKey());
g = client.stores().create(g, "Creating group", Group.class);
logger.info("{} contains members: {}", g, g.getConstituents());
}
use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.
the class RepositoryPathMaskExtTest method run.
/**
* Extensive tests. Both regex patterns and "directory prefix" patterns need to be tested, involving all three store types:
* RemoteRepository (direct access)
* HostedRepository (direct access)
* Group (where one or more members has path masks)
* Case where two members contain the same path, but first one's path mask doesn't match
* - Should return content from the second member
*/
@Test
public void run() throws Exception {
final String content1 = "{\"content1\": \"This is a test: " + System.nanoTime() + "\"}";
final String content2 = "{\"content2\": \"This is a test: " + System.nanoTime() + "\"}";
final String path_1 = "org/foo/foo-project/1.0/pom.xml";
final String path_2 = "org/bar/bar-project/1.0/pom.xml";
final String remote1 = "remote1";
final String hosted1 = "hosted1";
server.expect(server.formatUrl(remote1, path_1), 200, new ByteArrayInputStream(content1.getBytes()));
RemoteRepository remoteRepo1 = new RemoteRepository(remote1, server.formatUrl(remote1));
Set<String> pathMaskPatterns = new HashSet<>();
// regex patterns
pathMaskPatterns.add("r|org/bar.*|");
remoteRepo1.setPathMaskPatterns(pathMaskPatterns);
remoteRepo1 = client.stores().create(remoteRepo1, "adding remote 1", RemoteRepository.class);
HostedRepository hostedRepo1 = new HostedRepository(hosted1);
pathMaskPatterns = new HashSet<>();
pathMaskPatterns.add("org/foo");
pathMaskPatterns.add("r|org/bar.*|");
hostedRepo1.setPathMaskPatterns(pathMaskPatterns);
hostedRepo1 = client.stores().create(hostedRepo1, "adding hosted 1", HostedRepository.class);
client.content().store(hosted, hosted1, path_1, new ByteArrayInputStream(content2.getBytes()));
client.content().store(hosted, hosted1, path_2, new ByteArrayInputStream(content2.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;
// Case 1. return content from the repo with valid mask
// get stream for path-1 via group
stream = client.content().get(group, g.getName(), path_1);
assertThat(stream, notNullValue());
// return content from the repo with mask
str = IOUtils.toString(stream);
stream.close();
assertThat(str, equalTo(content2));
// Case 2. multiple repositories with same mask, use what can supply the real artifact
// get stream for path-2 via group (success)
stream = client.content().get(group, g.getName(), path_2);
assertThat(stream, notNullValue());
stream.close();
// Case 3. test direct access hosted repo with regex mask
// direct access for path-2 (success)
stream = client.content().get(hosted, hostedRepo1.getName(), path_2);
assertThat(stream, notNullValue());
stream.close();
}
Aggregations