use of io.cdap.cdap.internal.app.store.DefaultStore in project cdap by caskdata.
the class SqlProfileServiceTest method setup.
@BeforeClass
public static void setup() throws IOException, TableAlreadyExistsException {
cConf = CConfiguration.create();
// any plugin which requires transaction will be excluded
cConf.set(Constants.REQUIREMENTS_DATASET_TYPE_EXCLUDE, Joiner.on(",").join(Table.TYPE, KeyValueTable.TYPE));
pg = PostgresInstantiator.createAndStart(cConf, TEMP_FOLDER.newFolder());
injector = AppFabricTestHelper.getInjector(cConf);
structuredTableAdmin = injector.getInstance(StructuredTableAdmin.class);
TransactionRunner transactionRunner = injector.getInstance(TransactionRunner.class);
StoreDefinition.createAllTables(structuredTableAdmin);
profileService = new ProfileService(cConf, injector.getInstance(MetricsSystemClient.class), transactionRunner);
defaultStore = new DefaultStore(transactionRunner);
}
use of io.cdap.cdap.internal.app.store.DefaultStore in project cdap by caskdata.
the class ProfileServiceTest method testProfileDeletion.
@Test
public void testProfileDeletion() throws Exception {
ProfileId myProfile = NamespaceId.DEFAULT.profile("MyProfile");
ProfileId myProfile2 = NamespaceId.DEFAULT.profile("MyProfile2");
Profile profile1 = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), Profile.NATIVE.getProvisioner());
Profile profile2 = new Profile("MyProfile2", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), ProfileStatus.DISABLED, Profile.NATIVE.getProvisioner());
profileService.saveProfile(myProfile, profile1);
// add profile2 and disable it, profile2 can get deleted at any time
profileService.saveProfile(myProfile2, profile2);
profileService.disableProfile(myProfile2);
// Should not be able to delete because the profile is by default enabled
try {
profileService.deleteProfile(myProfile);
Assert.fail();
} catch (ProfileConflictException e) {
// expected
}
try {
profileService.deleteAllProfiles(NamespaceId.DEFAULT);
Assert.fail();
} catch (ProfileConflictException e) {
// expected and check profile 2 is not getting deleted
Assert.assertEquals(profile2, profileService.getProfile(myProfile2));
}
// add assignment and disable it, deletion should also fail
profileService.addProfileAssignment(myProfile, NamespaceId.DEFAULT);
profileService.disableProfile(myProfile);
try {
profileService.deleteProfile(myProfile);
Assert.fail();
} catch (ProfileConflictException e) {
// expected
}
try {
profileService.deleteAllProfiles(NamespaceId.DEFAULT);
Assert.fail();
} catch (ProfileConflictException e) {
// expected and check profile 2 is not getting deleted
Assert.assertEquals(profile2, profileService.getProfile(myProfile2));
}
profileService.removeProfileAssignment(myProfile, NamespaceId.DEFAULT);
// add an active record to DefaultStore, deletion should still fail
Store store = getDefaultStore();
ProgramId programId = NamespaceId.DEFAULT.app("myApp").workflow("myProgram");
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("testArtifact", "1.0").toApiArtifactId();
RunId runId = RunIds.generate(System.currentTimeMillis());
ProgramRunId programRunId = programId.run(runId.getId());
Map<String, String> systemArgs = Collections.singletonMap(SystemArguments.PROFILE_NAME, myProfile.getScopedName());
int sourceId = 0;
store.setProvisioning(programRunId, Collections.emptyMap(), systemArgs, AppFabricTestHelper.createSourceId(++sourceId), artifactId);
store.setProvisioned(programRunId, 0, AppFabricTestHelper.createSourceId(++sourceId));
store.setStart(programRunId, null, systemArgs, AppFabricTestHelper.createSourceId(++sourceId));
try {
profileService.deleteProfile(myProfile);
Assert.fail();
} catch (ProfileConflictException e) {
// expected
}
try {
profileService.deleteAllProfiles(NamespaceId.DEFAULT);
Assert.fail();
} catch (ProfileConflictException e) {
// expected and check profile 2 is not getting deleted
Assert.assertEquals(profile2, profileService.getProfile(myProfile2));
}
// set the run to stopped then deletion should work
store.setStop(programRunId, System.currentTimeMillis() + 1000, ProgramController.State.ERROR.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
// now profile deletion should succeed
profileService.deleteProfile(myProfile);
Assert.assertEquals(Collections.singletonList(profile2), profileService.getProfiles(NamespaceId.DEFAULT, false));
profileService.saveProfile(myProfile, profile1);
profileService.disableProfile(myProfile);
profileService.deleteAllProfiles(NamespaceId.DEFAULT);
Assert.assertEquals(Collections.emptyList(), profileService.getProfiles(NamespaceId.DEFAULT, false));
}
Aggregations