### Question:
GroupConfigChangeTaskHolder { public boolean onLogCommitted(GroupConfigEntry entry) { if (isEmpty()) { return false; } logger.debug("log {} committed, current task {}", entry, task); if (entry instanceof AddNodeEntry && task instanceof AddNodeTask && task.isTargetNode(((AddNodeEntry) entry).getNewNodeEndpoint().getId())) { task.onLogCommitted(); return true; } if (entry instanceof RemoveNodeEntry && task instanceof RemoveNodeTask && task.isTargetNode(((RemoveNodeEntry) entry).getNodeToRemove())) { task.onLogCommitted(); return true; } return false; } GroupConfigChangeTaskHolder();  GroupConfigChangeTaskHolder(GroupConfigChangeTask task, GroupConfigChangeTaskReference reference); void awaitDone(long timeout); void cancel(); boolean isEmpty(); boolean onLogCommitted(GroupConfigEntry entry);  }### Answer:
@Test public void testOnLogCommittedEmpty() { GroupConfigChangeTaskHolder taskHolder = new GroupConfigChangeTaskHolder(); RemoveNodeEntry entry = new RemoveNodeEntry(1, 1, Collections.emptySet(), NodeId.of("B")); Assert.assertFalse(taskHolder.onLogCommitted(entry)); }
@Test public void testOnLogCommittedAddNodeTask() throws InterruptedException, ExecutionException { WaitableGroupConfigChangeTaskContext taskContext = new WaitableGroupConfigChangeTaskContext(); AddNodeTask task = new AddNodeTask( taskContext, new NodeEndpoint("D", "localhost", 2336), 2, 1 ); GroupConfigChangeTaskHolder taskHolder = new GroupConfigChangeTaskHolder( task, new FixedResultGroupConfigTaskReference(GroupConfigChangeTaskResult.OK) ); Future<GroupConfigChangeTaskResult> future = taskExecutor.submit(task); taskContext.awaitLogAppended(); AddNodeEntry entry = new AddNodeEntry( 1, 1, Collections.emptySet(), new NodeEndpoint("D", "localhost", 2336) ); Assert.assertTrue(taskHolder.onLogCommitted(entry)); future.get(); }
@Test public void testOnLogCommittedAddNodeTask2() { AddNodeTask task = new AddNodeTask( new WaitableGroupConfigChangeTaskContext(), new NodeEndpoint("D", "localhost", 2336), 2, 1 ); GroupConfigChangeTaskHolder taskHolder = new GroupConfigChangeTaskHolder( task, new FixedResultGroupConfigTaskReference(GroupConfigChangeTaskResult.OK) ); AddNodeEntry entry = new AddNodeEntry( 1, 1, Collections.emptySet(), new NodeEndpoint("E", "localhost", 2337) ); Assert.assertFalse(taskHolder.onLogCommitted(entry)); }
@Test public void testOnLogCommittedRemoveNodeTask() throws ExecutionException, InterruptedException { WaitableGroupConfigChangeTaskContext taskContext = new WaitableGroupConfigChangeTaskContext(); RemoveNodeTask task = new RemoveNodeTask(taskContext, NodeId.of("B")); Future<GroupConfigChangeTaskResult> future = taskExecutor.submit(task); GroupConfigChangeTaskHolder taskHolder = new GroupConfigChangeTaskHolder( task, new FixedResultGroupConfigTaskReference(GroupConfigChangeTaskResult.OK) ); taskContext.awaitLogAppended(); RemoveNodeEntry entry = new RemoveNodeEntry(1, 1, Collections.emptySet(), NodeId.of("B")); Assert.assertTrue(taskHolder.onLogCommitted(entry)); future.get(); }
@Test public void testOnLogCommittedRemoveNodeTask2() throws ExecutionException, InterruptedException { WaitableGroupConfigChangeTaskContext taskContext = new WaitableGroupConfigChangeTaskContext(); RemoveNodeTask task = new RemoveNodeTask(taskContext, NodeId.of("B")); GroupConfigChangeTaskHolder taskHolder = new GroupConfigChangeTaskHolder( task, new FixedResultGroupConfigTaskReference(GroupConfigChangeTaskResult.OK) ); RemoveNodeEntry entry = new RemoveNodeEntry(1, 1, Collections.emptySet(), NodeId.of("C")); Assert.assertFalse(taskHolder.onLogCommitted(entry)); }