use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class PromotionManagerTest method promoteAllByPath_CollidingPaths_VerifySecondSkipped.
/**
* On collision, the promotion manager should skip the second file to be promoted (instead of overwriting the
* existing one). This assumes no overwrite attribute is available for setting in the promotion request (or that
* it is available but isn't set...and defaults to false).
* @throws Exception
*/
@Test
public void promoteAllByPath_CollidingPaths_VerifySecondSkipped() throws Exception {
final HostedRepository source1 = new HostedRepository(MAVEN_PKG_KEY, "source1");
final HostedRepository source2 = new HostedRepository(MAVEN_PKG_KEY, "source2");
storeManager.storeArtifactStore(source1, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
storeManager.storeArtifactStore(source2, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
String originalString = "This is a test";
final String path = "/path/path";
contentManager.store(source1, path, new ByteArrayInputStream(originalString.getBytes()), TransferOperation.UPLOAD, new EventMetadata());
contentManager.store(source2, path, new ByteArrayInputStream("This is another 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());
PathsPromoteResult result = manager.promotePaths(new PathsPromoteRequest(source1.getKey(), target.getKey(), path), FAKE_BASE_URL);
assertThat(result.getRequest().getSource(), equalTo(source1.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(1));
assertThat(result.getError(), nullValue());
Transfer ref = downloadManager.getStorageReference(target, path);
assertThat(ref.exists(), equalTo(true));
try (InputStream in = ref.openInputStream()) {
String value = IOUtils.toString(in);
assertThat(value, equalTo(originalString));
}
result = manager.promotePaths(new PathsPromoteRequest(source1.getKey(), target.getKey(), path), FAKE_BASE_URL);
assertThat(result.getRequest().getSource(), equalTo(source1.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(1));
completed = result.getCompletedPaths();
assertThat(completed == null || completed.isEmpty(), equalTo(true));
assertThat(result.getError(), nullValue());
ref = downloadManager.getStorageReference(target, path);
assertThat(ref.exists(), equalTo(true));
try (InputStream in = ref.openInputStream()) {
String value = IOUtils.toString(in);
assertThat(value, equalTo(originalString));
}
}
use of org.commonjava.indy.audit.ChangeSummary 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.audit.ChangeSummary 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.audit.ChangeSummary 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.audit.ChangeSummary in project indy by Commonjava.
the class PromoteValidationsManagerTest method testRuleSetParseAndMatchOnStoreKey.
@Test
public void testRuleSetParseAndMatchOnStoreKey() throws Exception {
DataFile dataFile = fileManager.getDataFile("promote/rule-sets/test.json");
dataFile.writeString("{\"name\":\"test\",\"storeKeyPattern\":\".*\"}", new ChangeSummary(ChangeSummary.SYSTEM_USER, "writing test data"));
promoteValidations = new PromoteValidationsManager(fileManager, config, parser);
ValidationRuleSet ruleSet = promoteValidations.getRuleSetMatching(new StoreKey(StoreType.hosted, "repo"));
assertThat(ruleSet, notNullValue());
assertThat(ruleSet.matchesKey("hosted:repo"), equalTo(true));
}
Aggregations