use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.
the class AppMetadataStoreTest method testScanApplications.
@Test
public void testScanApplications() {
ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
// Writes 100 application specs
int count = 100;
for (int i = 0; i < count; i++) {
String appName = "test" + i;
TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore store = AppMetadataStore.create(context);
store.writeApplication(NamespaceId.DEFAULT.getNamespace(), appName, ApplicationId.DEFAULT_VERSION, appSpec);
});
}
// Scan all apps
Map<ApplicationId, ApplicationMeta> apps = new LinkedHashMap<>();
TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore store = AppMetadataStore.create(context);
store.scanApplications(ScanApplicationsRequest.builder().build(), entry -> {
apps.put(entry.getKey(), entry.getValue());
return true;
});
});
Assert.assertEquals(count, apps.size());
}
use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.
the class AppMetadataStoreTest method testScanApplicationsWithNamespace.
@Test
public void testScanApplicationsWithNamespace() {
ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
// Writes 100 application specs
int count = 100;
for (int i = 0; i < count / 2; i++) {
String defaultAppName = "test" + (2 * i);
TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore store = AppMetadataStore.create(context);
store.writeApplication(NamespaceId.DEFAULT.getNamespace(), defaultAppName, ApplicationId.DEFAULT_VERSION, appSpec);
});
String cdapAppName = "test" + (2 * i + 1);
TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore store = AppMetadataStore.create(context);
store.writeApplication(NamespaceId.CDAP.getNamespace(), cdapAppName, ApplicationId.DEFAULT_VERSION, appSpec);
});
}
// Scan all apps
Map<ApplicationId, ApplicationMeta> apps = new LinkedHashMap<>();
TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore store = AppMetadataStore.create(context);
store.scanApplications(ScanApplicationsRequest.builder().setNamespaceId(NamespaceId.DEFAULT).build(), entry -> {
apps.put(entry.getKey(), entry.getValue());
return true;
});
});
Assert.assertEquals(count / 2, apps.size());
}
use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.
the class AppMetadataStoreTest method testBatchApplications.
@Test
public void testBatchApplications() {
ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
// Writes 20 application specs
for (int i = 0; i < 20; i++) {
String appName = "test" + i;
TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore store = AppMetadataStore.create(context);
store.writeApplication(NamespaceId.DEFAULT.getNamespace(), appName, ApplicationId.DEFAULT_VERSION, appSpec);
store.writeApplication(NamespaceId.SYSTEM.getNamespace(), appName, ApplicationId.DEFAULT_VERSION, appSpec);
});
}
TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore store = AppMetadataStore.create(context);
long count = store.getApplicationCount();
// System apps are not included in the count
Assert.assertEquals(20, count);
});
// Batch read 30, expect to get back 20
List<ApplicationId> appIds = new ArrayList<>();
for (int i = 0; i < 30; i++) {
appIds.add(NamespaceId.DEFAULT.app("test" + i));
}
Map<ApplicationId, ApplicationMeta> result = TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore store = AppMetadataStore.create(context);
return store.getApplicationsForAppIds(appIds);
});
Assert.assertEquals(20, result.size());
for (int i = 0; i < 20; i++) {
Assert.assertTrue("Missing application test" + i, result.containsKey(NamespaceId.DEFAULT.app("test" + i)));
}
}
use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.
the class DefaultStoreTest method testScanApplicationsWithNamespace.
public void testScanApplicationsWithNamespace(Store store) {
ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
int count = 100;
for (int i = 0; i < count / 2; i++) {
String appName = "test" + (2 * i);
store.addApplication(new ApplicationId(NamespaceId.DEFAULT.getNamespace(), appName), appSpec);
appName = "test" + (2 * i + 1);
store.addApplication(new ApplicationId(NamespaceId.CDAP.getNamespace(), appName), appSpec);
}
List<ApplicationId> apps = new ArrayList<ApplicationId>();
ScanApplicationsRequest request = ScanApplicationsRequest.builder().setNamespaceId(NamespaceId.CDAP).build();
store.scanApplications(request, 20, (appId, spec) -> {
apps.add(appId);
});
Assert.assertEquals(count / 2, apps.size());
// Reverse
List<ApplicationId> reverseApps = new ArrayList<>();
request = ScanApplicationsRequest.builder().setNamespaceId(NamespaceId.CDAP).setSortOrder(SortOrder.DESC).build();
store.scanApplications(request, 20, (appId, spec) -> reverseApps.add(appId));
Assert.assertEquals(Lists.reverse(apps), reverseApps);
// Second page
int firstPageSize = 10;
List<ApplicationId> restartApps = new ArrayList<>();
request = ScanApplicationsRequest.builder().setNamespaceId(NamespaceId.CDAP).setScanFrom(apps.get(firstPageSize - 1)).build();
store.scanApplications(request, 20, (appId, spec) -> restartApps.add(appId));
Assert.assertEquals(apps.subList(firstPageSize, apps.size()), restartApps);
}
use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.
the class DefaultStoreTest method testRemoveApplication.
@Test
public void testRemoveApplication() {
ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
NamespaceId namespaceId = new NamespaceId("account1");
ApplicationId appId = namespaceId.app(spec.getName());
store.addApplication(appId, spec);
Assert.assertNotNull(store.getApplication(appId));
// removing application
store.removeApplication(appId);
Assert.assertNull(store.getApplication(appId));
}
Aggregations