### Question:
TaskStateSnapshot implements CompositeStateHandle { @Override public long getStateSize() { long size = 0L; for (OperatorSubtaskState subtaskState : subtaskStatesByOperatorID.values()) { if (subtaskState != null) { size += subtaskState.getStateSize(); } } return size; } TaskStateSnapshot();  TaskStateSnapshot(int size);  TaskStateSnapshot(Map<OperatorID, OperatorSubtaskState> subtaskStatesByOperatorID); @Nullable OperatorSubtaskState getSubtaskStateByOperatorID(OperatorID operatorID); OperatorSubtaskState putSubtaskStateByOperatorID(
		@Nonnull OperatorID operatorID,
		@Nonnull OperatorSubtaskState state); Set<Map.Entry<OperatorID, OperatorSubtaskState>> getSubtaskStateMappings(); boolean hasState(); @Override void discardState(); @Override long getStateSize(); @Override void registerSharedStates(SharedStateRegistry stateRegistry); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void getStateSize() { Random random = new Random(0x42); TaskStateSnapshot taskStateSnapshot = new TaskStateSnapshot(); Assert.assertEquals(0, taskStateSnapshot.getStateSize()); OperatorSubtaskState emptyOperatorSubtaskState = new OperatorSubtaskState(); Assert.assertFalse(emptyOperatorSubtaskState.hasState()); taskStateSnapshot.putSubtaskStateByOperatorID(new OperatorID(), emptyOperatorSubtaskState); Assert.assertEquals(0, taskStateSnapshot.getStateSize()); OperatorStateHandle stateHandle_1 = StateHandleDummyUtil.createNewOperatorStateHandle(2, random); OperatorSubtaskState nonEmptyOperatorSubtaskState_1 = new OperatorSubtaskState( stateHandle_1, null, null, null ); OperatorStateHandle stateHandle_2 = StateHandleDummyUtil.createNewOperatorStateHandle(2, random); OperatorSubtaskState nonEmptyOperatorSubtaskState_2 = new OperatorSubtaskState( null, stateHandle_2, null, null ); taskStateSnapshot.putSubtaskStateByOperatorID(new OperatorID(), nonEmptyOperatorSubtaskState_1); taskStateSnapshot.putSubtaskStateByOperatorID(new OperatorID(), nonEmptyOperatorSubtaskState_2); long totalSize = stateHandle_1.getStateSize() + stateHandle_2.getStateSize(); Assert.assertEquals(totalSize, taskStateSnapshot.getStateSize()); }
@Test public void getStateSize() { Random random = new Random(0x42); TaskStateSnapshot taskStateSnapshot = new TaskStateSnapshot(); Assert.assertEquals(0, taskStateSnapshot.getStateSize()); OperatorSubtaskState emptyOperatorSubtaskState = new OperatorSubtaskState(); Assert.assertFalse(emptyOperatorSubtaskState.hasState()); taskStateSnapshot.putSubtaskStateByOperatorID(new OperatorID(), emptyOperatorSubtaskState); Assert.assertEquals(0, taskStateSnapshot.getStateSize()); OperatorStateHandle stateHandle_1 = StateHandleDummyUtil.createNewOperatorStateHandle(2, random); OperatorSubtaskState nonEmptyOperatorSubtaskState_1 = new OperatorSubtaskState( stateHandle_1, null, null, null, null, null ); OperatorStateHandle stateHandle_2 = StateHandleDummyUtil.createNewOperatorStateHandle(2, random); OperatorSubtaskState nonEmptyOperatorSubtaskState_2 = new OperatorSubtaskState( null, stateHandle_2, null, null, null, null ); taskStateSnapshot.putSubtaskStateByOperatorID(new OperatorID(), nonEmptyOperatorSubtaskState_1); taskStateSnapshot.putSubtaskStateByOperatorID(new OperatorID(), nonEmptyOperatorSubtaskState_2); long totalSize = stateHandle_1.getStateSize() + stateHandle_2.getStateSize(); Assert.assertEquals(totalSize, taskStateSnapshot.getStateSize()); }