use of co.cask.cdap.test.DataSetManager in project cdap by caskdata.
the class AuthorizationTest method testFlowStreamAuth.
@Test
@Category(SlowTests.class)
public void testFlowStreamAuth() throws Exception {
createAuthNamespace();
Authorizer authorizer = getAuthorizer();
ApplicationManager appManager = deployApplication(AUTH_NAMESPACE, StreamAuthApp.class);
// After deploy, change Alice from ALL to ADMIN on the namespace
authorizer.revoke(AUTH_NAMESPACE, ALICE, EnumSet.allOf(Action.class));
authorizer.grant(AUTH_NAMESPACE, ALICE, EnumSet.of(Action.ADMIN));
final FlowManager flowManager = appManager.getFlowManager(StreamAuthApp.FLOW);
StreamId streamId = AUTH_NAMESPACE.stream(StreamAuthApp.STREAM);
StreamManager streamManager = getStreamManager(AUTH_NAMESPACE.stream(StreamAuthApp.STREAM));
StreamManager streamManager2 = getStreamManager(AUTH_NAMESPACE.stream(StreamAuthApp.STREAM2));
streamManager.send("Auth");
flowManager.start();
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
DataSetManager<KeyValueTable> kvTable = getDataset(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE));
return kvTable.get().read("Auth") != null;
}
}, 5, TimeUnit.SECONDS);
flowManager.stop();
flowManager.waitForRun(ProgramRunStatus.KILLED, 60, TimeUnit.SECONDS);
// Now revoke read permission for Alice on that stream (revoke ALL and then grant everything other than READ)
authorizer.revoke(streamId, ALICE, EnumSet.allOf(Action.class));
authorizer.grant(streamId, ALICE, EnumSet.of(Action.WRITE, Action.ADMIN, Action.EXECUTE));
streamManager.send("Security");
streamManager2.send("Safety");
try {
flowManager.start();
} catch (RuntimeException e) {
Assert.assertTrue(e.getCause() instanceof UnauthorizedException);
}
authorizer.grant(streamId, ALICE, ImmutableSet.of(Action.READ));
flowManager.start();
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
DataSetManager<KeyValueTable> kvTable = getDataset(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE));
return kvTable.get().read("Security") != null;
}
}, 5, TimeUnit.SECONDS);
authorizer.revoke(streamId, ALICE, ImmutableSet.of(Action.READ));
TimeUnit.MILLISECONDS.sleep(10);
flowManager.stop();
flowManager.waitForRuns(ProgramRunStatus.KILLED, 2, 5, TimeUnit.SECONDS);
appManager.delete();
}
use of co.cask.cdap.test.DataSetManager in project cdap by caskdata.
the class TestFrameworkTestRun method testAppWithWorker.
@Category(SlowTests.class)
@Test
public void testAppWithWorker() throws Exception {
ApplicationManager applicationManager = deployApplication(testSpace, AppWithWorker.class);
LOG.info("Deployed.");
WorkerManager manager = applicationManager.getWorkerManager(AppWithWorker.WORKER).start();
// Wait for initialize and run states
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
DataSetManager<KeyValueTable> dataSetManager = getDataset(testSpace.dataset(AppWithWorker.DATASET));
KeyValueTable table = dataSetManager.get();
return AppWithWorker.INITIALIZE.equals(Bytes.toString(table.read(AppWithWorker.INITIALIZE))) && AppWithWorker.RUN.equals(Bytes.toString(table.read(AppWithWorker.RUN)));
}
}, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
manager.stop();
applicationManager.stopAll();
// Wait for stop state
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
DataSetManager<KeyValueTable> dataSetManager = getDataset(testSpace.dataset(AppWithWorker.DATASET));
KeyValueTable table = dataSetManager.get();
return AppWithWorker.STOP.equals(Bytes.toString(table.read(AppWithWorker.STOP)));
}
}, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
}
Aggregations