Program: 4748
Project: 4748
Buggy source:
@Test @Category(SlowTests.class) public void testFlowStreamAuth() throws Exception {
  createAuthNamespace();
  Authorizer authorizer=getAuthorizer();
  setUpPrivilegeToDeployStreamAuthApp();
  StreamId streamId1=AUTH_NAMESPACE.stream(StreamAuthApp.STREAM);
  StreamId streamId2=AUTH_NAMESPACE.stream(StreamAuthApp.STREAM2);
  Map<EntityId,Set<Action>> additionalPrivileges=ImmutableMap.<EntityId,Set<Action>>builder().put(streamId1,EnumSet.of(Action.READ,Action.WRITE)).put(streamId2,EnumSet.of(Action.READ,Action.WRITE)).put(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE),EnumSet.of(Action.READ,Action.WRITE)).put(AUTH_NAMESPACE.app(StreamAuthApp.APP).flow(StreamAuthApp.FLOW),EnumSet.of(Action.EXECUTE)).build();
  setUpPrivilegeAndRegisterForDeletion(ALICE,additionalPrivileges);
  ApplicationManager appManager=deployApplication(AUTH_NAMESPACE,StreamAuthApp.class);
  final FlowManager flowManager=appManager.getFlowManager(StreamAuthApp.FLOW);
  StreamManager streamManager=getStreamManager(streamId1);
  StreamManager streamManager2=getStreamManager(streamId2);
  streamManager.send("String_Node_Str");
  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("String_Node_Str") != null;
    }
  }
,5,TimeUnit.SECONDS);
  flowManager.stop();
  flowManager.waitForRun(ProgramRunStatus.KILLED,60,TimeUnit.SECONDS);
  authorizer.revoke(streamId1,ALICE,EnumSet.allOf(Action.class));
  authorizer.grant(streamId1,ALICE,EnumSet.of(Action.WRITE,Action.ADMIN));
  streamManager.send("String_Node_Str");
  streamManager2.send("String_Node_Str");
  try {
    flowManager.start();
  }
 catch (  RuntimeException e) {
    Assert.assertTrue(e.getCause() instanceof UnauthorizedException);
  }
  authorizer.grant(streamId1,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("String_Node_Str") != null;
    }
  }
,5,TimeUnit.SECONDS);
  TimeUnit.MILLISECONDS.sleep(10);
  flowManager.stop();
  flowManager.waitForRuns(ProgramRunStatus.KILLED,2,5,TimeUnit.SECONDS);
  appManager.delete();
}

Fixed version (ground truth):
@Test @Category(SlowTests.class) public void testFlowStreamAuth() throws Exception {
  createAuthNamespace();
  Authorizer authorizer=getAuthorizer();
  setUpPrivilegeToDeployStreamAuthApp();
  StreamId streamId1=AUTH_NAMESPACE.stream(StreamAuthApp.STREAM);
  StreamId streamId2=AUTH_NAMESPACE.stream(StreamAuthApp.STREAM2);
  Map<EntityId,Set<Action>> additionalPrivileges=ImmutableMap.<EntityId,Set<Action>>builder().put(streamId1,EnumSet.of(Action.READ,Action.WRITE)).put(streamId2,EnumSet.of(Action.READ,Action.WRITE)).put(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE),EnumSet.of(Action.READ,Action.WRITE)).put(AUTH_NAMESPACE.app(StreamAuthApp.APP).flow(StreamAuthApp.FLOW),EnumSet.of(Action.EXECUTE)).build();
  setUpPrivilegeAndRegisterForDeletion(ALICE,additionalPrivileges);
  ApplicationManager appManager=deployApplication(AUTH_NAMESPACE,StreamAuthApp.class);
  final FlowManager flowManager=appManager.getFlowManager(StreamAuthApp.FLOW);
  StreamManager streamManager=getStreamManager(streamId1);
  StreamManager streamManager2=getStreamManager(streamId2);
  streamManager.send("String_Node_Str");
  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("String_Node_Str") != null;
    }
  }
,5,TimeUnit.SECONDS);
  flowManager.stop();
  flowManager.waitForRun(ProgramRunStatus.KILLED,60,TimeUnit.SECONDS);
  authorizer.revoke(streamId1,ALICE,EnumSet.allOf(Action.class));
  authorizer.grant(streamId1,ALICE,EnumSet.of(Action.WRITE,Action.ADMIN));
  streamManager.send("String_Node_Str");
  streamManager2.send("String_Node_Str");
  try {
    flowManager.start();
  }
 catch (  UnauthorizedException e) {
  }
  authorizer.grant(streamId1,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("String_Node_Str") != null;
    }
  }
,5,TimeUnit.SECONDS);
  TimeUnit.MILLISECONDS.sleep(10);
  flowManager.stop();
  flowManager.waitForRuns(ProgramRunStatus.KILLED,2,5,TimeUnit.SECONDS);
  appManager.delete();
}