use of io.cdap.cdap.internal.app.runtime.artifact.RemoteArtifactRepositoryReader in project cdap by caskdata.
the class ArtifactHttpHandlerInternalTest method testRemoteArtifactRepositoryReaderGetArtifact.
/**
* Test {@link RemoteArtifactRepositoryReader#getArtifact}
*/
@Test
public void testRemoteArtifactRepositoryReaderGetArtifact() throws Exception {
// Add a system artifact
String systemArtfiactName = "sysApp";
String systemArtifactVeresion = "1.0.0";
ArtifactId systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, systemArtifactVeresion);
addAppAsSystemArtifacts(systemArtifactId);
// Fetch ArtifactDetail using RemoteArtifactRepositoryReader and verify
ArtifactRepositoryReader remoteReader = getInjector().getInstance(RemoteArtifactRepositoryReader.class);
ArtifactDetail detail = remoteReader.getArtifact(Id.Artifact.fromEntityId(systemArtifactId));
Assert.assertNotNull(detail);
ArtifactDetail expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
Assert.assertTrue(detail.equals(expectedDetail));
wipeData();
}
use of io.cdap.cdap.internal.app.runtime.artifact.RemoteArtifactRepositoryReader in project cdap by caskdata.
the class ArtifactHttpHandlerInternalTest method testRemoteArtifactRepositoryReaderGetArtifactDetails.
/**
* Test {@link RemoteArtifactRepositoryReader#getArtifactDetails}
*/
@Test
public void testRemoteArtifactRepositoryReaderGetArtifactDetails() throws Exception {
// Add an artifact with a number of versions
String systemArtfiactName = "sysApp3";
final int numVersions = 10;
List<ArtifactId> artifactIds = new ArrayList<>();
for (int i = 1; i <= numVersions; i++) {
String version = String.format("%d.0.0", i);
ArtifactId systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, version);
addAppAsSystemArtifacts(systemArtifactId);
artifactIds.add(systemArtifactId);
}
ArtifactRepositoryReader remoteReader = getInjector().getInstance(RemoteArtifactRepositoryReader.class);
ArtifactRange range = null;
List<ArtifactDetail> details = null;
ArtifactId systemArtifactId = null;
ArtifactDetail expectedDetail = null;
int numLimits = 0;
range = new ArtifactRange(NamespaceId.SYSTEM.getNamespace(), systemArtfiactName, new ArtifactVersion("1.0.0"), new ArtifactVersion(String.format("%d.0.0", numVersions)));
// Fetch artifacts with the version in range [1.0.0, numVersions.0.0], but limit == 1 in desc order
numLimits = 1;
details = remoteReader.getArtifactDetails(range, numLimits, ArtifactSortOrder.DESC);
Assert.assertEquals(numLimits, details.size());
systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, String.format("%d.0.0", numVersions));
expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
Assert.assertTrue(details.get(numLimits - 1).equals(expectedDetail));
// Fetch artifacts with the version in range [1.0.0, numVersions.0.0], but limit == 3 in desc order
numLimits = 3;
details = remoteReader.getArtifactDetails(range, numLimits, ArtifactSortOrder.DESC);
Assert.assertEquals(numLimits, details.size());
for (int i = 0; i < numLimits; i++) {
systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, String.format("%d.0.0", numVersions - i));
expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
Assert.assertTrue(details.get(i).equals(expectedDetail));
}
// Fetch artifacts with the version in range [1.0.0, numVersions.0.0], but limit == 1 in asec order
details = remoteReader.getArtifactDetails(range, 1, ArtifactSortOrder.ASC);
Assert.assertEquals(1, details.size());
systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, "1.0.0");
expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
Assert.assertTrue(details.get(0).equals(expectedDetail));
// Fetch artifacts with the version in range [1.0.0, numVersions.0.0], but limit == 5 in asec order
numLimits = 5;
details = remoteReader.getArtifactDetails(range, numLimits, ArtifactSortOrder.ASC);
Assert.assertEquals(numLimits, details.size());
for (int i = 0; i < numLimits; i++) {
systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, String.format("%d.0.0", i + 1));
expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
Assert.assertTrue(details.get(i).equals(expectedDetail));
}
int versionLow = 1;
int versionHigh = numVersions / 2;
range = new ArtifactRange(NamespaceId.SYSTEM.getNamespace(), systemArtfiactName, new ArtifactVersion(String.format("%d.0.0", versionLow)), new ArtifactVersion(String.format("%d.0.0", versionHigh)));
// Fetch artifacts with the version in range [1.0.0, <numVersions/2>.0.0], but limit == numVersions in desc order
numLimits = numVersions;
details = remoteReader.getArtifactDetails(range, numLimits, ArtifactSortOrder.DESC);
Assert.assertEquals(versionHigh - versionLow + 1, details.size());
for (int i = 0; i < versionHigh - versionLow + 1; i++) {
systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, String.format("%d.0.0", versionHigh - i));
expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
Assert.assertTrue(details.get(i).equals(expectedDetail));
}
}
Aggregations