From 696b04020b87c28aec761c559e438c4a70e5a20c Mon Sep 17 00:00:00 2001 From: Dhruv Parthasarathy Date: Thu, 1 Aug 2013 18:28:48 -0700 Subject: [PATCH] wrote regression test --- .../druid/master/CostBalancerStrategy.java | 10 ++- .../druid/master/DruidMasterBalancerTest.java | 68 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/metamx/druid/master/CostBalancerStrategy.java b/server/src/main/java/com/metamx/druid/master/CostBalancerStrategy.java index 18930b97e45..e7c01bc6dff 100644 --- a/server/src/main/java/com/metamx/druid/master/CostBalancerStrategy.java +++ b/server/src/main/java/com/metamx/druid/master/CostBalancerStrategy.java @@ -47,7 +47,15 @@ public class CostBalancerStrategy implements BalancerStrategy DataSegment proposalSegment, List serverHolders ) { - return chooseBestServer(proposalSegment, serverHolders, false).rhs; + ServerHolder holder= chooseBestServer(proposalSegment, serverHolders, false).rhs; + if (!holder.isServingSegment(proposalSegment)) + { + return holder; + } + else + { + return null; + } } diff --git a/server/src/test/java/com/metamx/druid/master/DruidMasterBalancerTest.java b/server/src/test/java/com/metamx/druid/master/DruidMasterBalancerTest.java index bbdb194b0c4..87ada744cb9 100644 --- a/server/src/test/java/com/metamx/druid/master/DruidMasterBalancerTest.java +++ b/server/src/test/java/com/metamx/druid/master/DruidMasterBalancerTest.java @@ -132,6 +132,74 @@ public class DruidMasterBalancerTest EasyMock.verify(druidServer4); } + @Test + public void testMoveToEmptyServer() + { + EasyMock.expect(druidServer1.getName()).andReturn("from").atLeastOnce(); + EasyMock.expect(druidServer1.getCurrSize()).andReturn(30L).atLeastOnce(); + EasyMock.expect(druidServer1.getMaxSize()).andReturn(100L).atLeastOnce(); + EasyMock.expect(druidServer1.getSegments()).andReturn(segments).anyTimes(); + EasyMock.expect(druidServer1.getSegment(EasyMock.anyObject())).andReturn(null).anyTimes(); + EasyMock.replay(druidServer1); + + EasyMock.expect(druidServer2.getName()).andReturn("to").atLeastOnce(); + EasyMock.expect(druidServer2.getTier()).andReturn("normal").anyTimes(); + EasyMock.expect(druidServer2.getCurrSize()).andReturn(0L).atLeastOnce(); + EasyMock.expect(druidServer2.getMaxSize()).andReturn(100L).atLeastOnce(); + EasyMock.expect(druidServer2.getSegments()).andReturn(new HashMap()).anyTimes(); + EasyMock.expect(druidServer2.getSegment(EasyMock.anyObject())).andReturn(null).anyTimes(); + EasyMock.replay(druidServer2); + + EasyMock.replay(druidServer3); + EasyMock.replay(druidServer4); + + // Mock stuff that the master needs + master.moveSegment( + EasyMock.anyObject(), + EasyMock.anyObject(), + EasyMock.anyObject(), + EasyMock.anyObject() + ); + EasyMock.expectLastCall().anyTimes(); + EasyMock.replay(master); + + LoadQueuePeonTester fromPeon = new LoadQueuePeonTester(); + LoadQueuePeonTester toPeon = new LoadQueuePeonTester(); + + DruidMasterRuntimeParams params = + DruidMasterRuntimeParams.newBuilder() + .withDruidCluster( + new DruidCluster( + ImmutableMap.>of( + "normal", + MinMaxPriorityQueue.orderedBy(DruidMasterBalancerTester.percentUsedComparator) + .create( + Arrays.asList( + new ServerHolder(druidServer1, fromPeon), + new ServerHolder(druidServer2, toPeon) + ) + ) + ) + ) + ) + .withLoadManagementPeons( + ImmutableMap.of( + "from", + fromPeon, + "to", + toPeon + ) + ) + .withAvailableSegments(segments.values()) + .withMaxSegmentsToMove(MAX_SEGMENTS_TO_MOVE) + .withBalancerReferenceTimestamp(new DateTime("2013-01-01")) + .build(); + + params = new DruidMasterBalancerTester(master).run(params); + Assert.assertTrue(params.getMasterStats().getPerTierStats().get("movedCount").get("normal").get() > 0); + Assert.assertTrue(params.getMasterStats().getPerTierStats().get("movedCount").get("normal").get() < segments.size()); + } + @Test public void testRun1() {