ShardDeployOperation extends AbstractShardOperation { @Override protected void execute(NodeContext context, String shardName, DeployResult deployResult) throws Exception { String shardPath = getShardPath(shardName); File localShardFolder = context.getShardManager().installShard(shardName, shardPath); IContentServer contentServer = context.getContentServer(); if (!contentServer.getShards().contains(shardName)) { contentServer.addShard(shardName, localShardFolder); Map<String, String> shardMetaData = context.getContentServer().getShardMetaData(shardName); if (shardMetaData == null) { throw new IllegalStateException("node managed '" + context.getContentServer() + "' does return NULL as shard metadata"); } deployResult.addShardMetaDataMap(shardName, shardMetaData); } publishShard(shardName, context); }    }
@Test public void testDeploy() throws Exception { ShardDeployOperation operation = new ShardDeployOperation(); operation.addShard("shard1", "shardPath1"); operation.addShard("shard2", "shardPath2"); File shardFolder = new File("shardFolder"); Map<String, String> shardMD = new HashMap<String, String>(); when(_shardManager.installShard((String) notNull(), (String) notNull())).thenReturn(shardFolder); when(_contentServer.getShardMetaData((String) notNull())).thenReturn(shardMD); DeployResult result = operation.execute(_context); InOrder inOrder = inOrder(_protocol, _shardManager, _contentServer); for (String shard : operation.getShardNames()) { inOrder.verify(_shardManager).installShard(shard, operation.getShardPath(shard)); inOrder.verify(_contentServer).addShard(shard, shardFolder); inOrder.verify(_protocol).publishShard(_node, shard); } assertEquals(0, result.getShardExceptions().size()); assertEquals(2, result.getShardMetaDataMaps().size()); System.out.println(result.getShardMetaDataMaps()); for (String shardName : operation.getShardNames()) { assertTrue(result.getShardMetaDataMaps().containsKey(shardName)); } }
@Test public void testDeployWithOneFailingShard() throws Exception { ShardDeployOperation operation = new ShardDeployOperation(); operation.addShard("shard1", "shardPath1"); operation.addShard("shard2", "shardPath2"); File shardFolder = new File("shardFolder"); Map<String, String> shardMD = new HashMap<String, String>(); when(_shardManager.installShard((String) notNull(), (String) notNull())).thenReturn(shardFolder); when(_contentServer.getShardMetaData((String) notNull())).thenReturn(shardMD); String failingShard = operation.getShardNames().iterator().next(); doThrow(new Exception("testException")).when(_contentServer).addShard(failingShard, shardFolder); DeployResult result = operation.execute(_context); InOrder inOrder = inOrder(_protocol, _shardManager, _contentServer); for (String shard : operation.getShardNames()) { inOrder.verify(_shardManager).installShard(shard, operation.getShardPath(shard)); inOrder.verify(_contentServer).addShard(shard, shardFolder); if (!shard.equals(failingShard)) { inOrder.verify(_protocol).publishShard(_node, shard); } } assertEquals(1, result.getShardMetaDataMaps().size()); assertEquals(1, result.getShardExceptions().size()); assertEquals(failingShard, result.getShardExceptions().entrySet().iterator().next().getKey()); verify(_shardManager).uninstallShard(eq(failingShard)); }