### Question:
ReconContainerManager extends SCMContainerManager { public void addNewContainer(long containerId, ContainerWithPipeline containerWithPipeline) throws IOException { ContainerInfo containerInfo = containerWithPipeline.getContainerInfo(); getLock().lock(); try { boolean success = false; if (containerInfo.getState().equals(HddsProtos.LifeCycleState.OPEN)) { PipelineID pipelineID = containerWithPipeline.getPipeline().getId(); if (getPipelineManager().containsPipeline(pipelineID)) { getContainerStateManager().addContainerInfo(containerId, containerInfo, getPipelineManager(), containerWithPipeline.getPipeline()); success = true; } else { LOG.warn(String.format( "Pipeline %s not found. Cannot add container %s", pipelineID, containerInfo.containerID())); } } else { getContainerStateManager().addContainerInfo(containerId, containerInfo, getPipelineManager(), null); success = true; } if (success) { addContainerToDB(containerInfo); LOG.info("Successfully added container {} to Recon.", containerInfo.containerID()); } } catch (IOException ex) { LOG.info("Exception while adding container {} .", containerInfo.containerID(), ex); getPipelineManager().removeContainerFromPipeline( containerInfo.getPipelineID(), new ContainerID(containerInfo.getContainerID())); throw ex; } finally { getLock().unlock(); } } ReconContainerManager(
      ConfigurationSource conf,
      Table<ContainerID, ContainerInfo> containerStore,
      BatchOperationHandler batchHandler,
      PipelineManager pipelineManager,
      StorageContainerServiceProvider scm,
      ContainerSchemaManager containerSchemaManager); void checkAndAddNewContainer(ContainerID containerID,
      ContainerReplicaProto.State replicaState,
      DatanodeDetails datanodeDetails); void addNewContainer(long containerId,
                              ContainerWithPipeline containerWithPipeline); @Override void updateContainerReplica(ContainerID containerID,
      ContainerReplica replica); ContainerSchemaManager getContainerSchemaManager();  }### Answer:
@Test public void testAddNewOpenContainer() throws IOException { ContainerWithPipeline containerWithPipeline = getTestContainer(LifeCycleState.OPEN); ContainerID containerID = containerWithPipeline.getContainerInfo().containerID(); ContainerInfo containerInfo = containerWithPipeline.getContainerInfo(); ReconContainerManager containerManager = getContainerManager(); assertFalse(containerManager.exists(containerID)); assertFalse(getContainerTable().isExist(containerID)); containerManager.addNewContainer( containerID.getId(), containerWithPipeline); assertTrue(containerManager.exists(containerID)); List<ContainerInfo> containers = containerManager.getContainers(LifeCycleState.OPEN); assertEquals(1, containers.size()); assertEquals(containerInfo, containers.get(0)); NavigableSet<ContainerID> containersInPipeline = getPipelineManager().getContainersInPipeline( containerWithPipeline.getPipeline().getId()); assertEquals(1, containersInPipeline.size()); assertEquals(containerID, containersInPipeline.first()); assertTrue(getContainerTable().isExist(containerID)); }
@Test public void testAddNewClosedContainer() throws IOException { ContainerWithPipeline containerWithPipeline = getTestContainer(CLOSED); ContainerID containerID = containerWithPipeline.getContainerInfo().containerID(); ContainerInfo containerInfo = containerWithPipeline.getContainerInfo(); ReconContainerManager containerManager = getContainerManager(); assertFalse(containerManager.exists(containerID)); assertFalse(getContainerTable().isExist(containerID)); containerManager.addNewContainer( containerID.getId(), containerWithPipeline); assertTrue(containerManager.exists(containerID)); List<ContainerInfo> containers = containerManager.getContainers(CLOSED); assertEquals(1, containers.size()); assertEquals(containerInfo, containers.get(0)); assertTrue(getContainerTable().isExist(containerID)); }