### Question:
AssignableInstance { public TaskAssignResult restoreTaskAssignResult(String taskId, TaskConfig taskConfig, String quotaType) { TaskAssignResult assignResult = new TaskAssignResult(taskConfig, quotaType, this, true, fitnessScoreFactor, null, "Recovered TaskAssignResult from current state"); try { assign(assignResult); } catch (IllegalStateException e) { logger.error("Failed to restore current TaskAssignResult for task {}.", taskId, e); return new TaskAssignResult(taskConfig, quotaType, this, false, fitnessScoreFactor, null, "Recovered TaskAssignResult from current state"); } return assignResult; } AssignableInstance(ClusterConfig clusterConfig, InstanceConfig instanceConfig,
      LiveInstance liveInstance); void updateConfigs(ClusterConfig clusterConfig, InstanceConfig instanceConfig,
      LiveInstance liveInstance); synchronized TaskAssignResult tryAssign(TaskConfig task, String quotaType); synchronized void assign(TaskAssignResult result); synchronized void release(TaskConfig taskConfig, String quotaType); TaskAssignResult restoreTaskAssignResult(String taskId, TaskConfig taskConfig,
      String quotaType); Set<String> getCurrentAssignments(); String getInstanceName(); Map<String, Map<String, Integer>> getTotalCapacity(); Map<String, Map<String, Integer>> getUsedCapacity(); static final String DEFAULT_QUOTA_TYPE; }### Answer:
@Test public void testRestoreTaskAssignResult() { AssignableInstance ai = new AssignableInstance(createClusterConfig(testQuotaTypes, testQuotaRatio, true), new InstanceConfig(testInstanceName), createLiveInstance(new String[] { LiveInstance.InstanceResourceType.TASK_EXEC_THREAD.name() }, new String[] { "40" })); Map<String, TaskConfig> currentAssignments = new HashMap<>(); TaskConfig supportedTask = new TaskConfig("", null, "supportedTask", ""); currentAssignments.put("supportedTask", supportedTask); TaskConfig unsupportedTask = new TaskConfig("", null, "unsupportedTask", ""); currentAssignments.put("unsupportedTask", unsupportedTask); Map<String, TaskAssignResult> results = Maps.newHashMap(); for (Map.Entry<String, TaskConfig> entry : currentAssignments.entrySet()) { String taskID = entry.getKey(); TaskConfig taskConfig = entry.getValue(); String quotaType = (taskID.equals("supportedTask")) ? AssignableInstance.DEFAULT_QUOTA_TYPE : "UnsupportedQuotaType"; TaskAssignResult taskAssignResult = ai.restoreTaskAssignResult(taskID, taskConfig, quotaType); if (taskAssignResult.isSuccessful()) { results.put(taskID, taskAssignResult); } } for (TaskAssignResult rst : results.values()) { Assert.assertTrue(rst.isSuccessful()); Assert.assertEquals(rst.getAssignableInstance(), ai); } Assert.assertEquals(ai.getCurrentAssignments().size(), 2); Assert.assertEquals( (int) ai.getUsedCapacity().get(LiveInstance.InstanceResourceType.TASK_EXEC_THREAD.name()) .get(AssignableInstance.DEFAULT_QUOTA_TYPE), 2); }