### Question:
ThreadNumberBalancing implements LoadBalancingStrategy { @Override public LoadBalancingOperation balance(TrackingEventProcessor processor) { return new MoveSegmentAlgorithm<>(new Move(processor)).balance(instanceClones(processor)); } ThreadNumberBalancing(InstancesRepo instances, OperationFactory operationFactory); @Override LoadBalancingOperation balance(TrackingEventProcessor processor);  }### Answer:
@Test public void testTwoSegmentForTwoInstances() { segments.put("instanceOne", of(0, 1)); segments.put("instanceTwo", of()); testSubject.balance(eventProcessor).perform(); assertEquals(1, segments.get("instanceOne").size()); assertEquals(1, segments.get("instanceTwo").size()); }
@Test public void testFourSegmentForThreeInstances() { segments.put("instanceOne", of(0, 1, 3, 4)); segments.put("instanceTwo", of()); segments.put("instanceThree", of()); testSubject.balance(eventProcessor).perform(); assertEquals(2, segments.get("instanceOne").size()); assertEquals(1, segments.get("instanceTwo").size()); assertEquals(1, segments.get("instanceThree").size()); }
@Test public void testNineSegmentForFiveInstances() { segments.put("instanceOne", of()); segments.put("instanceTwo", of(0, 1, 2, 3)); segments.put("instanceThree", of(4)); segments.put("instanceFour", of(5, 6, 7)); segments.put("instanceFive", of(8)); testSubject.balance(eventProcessor).perform(); assertEquals(1, segments.get("instanceOne").size()); assertEquals(3, segments.get("instanceTwo").size()); assertEquals(1, segments.get("instanceThree").size()); assertEquals(3, segments.get("instanceFour").size()); assertEquals(1, segments.get("instanceFive").size()); }
@Test public void testSameThreadPoolSize() { segments.put("instanceOne", of()); segments.put("instanceTwo", of(0, 1, 2, 3)); segments.put("instanceThree", of(4)); segments.put("instanceFour", of(5, 6, 7)); segments.put("instanceFive", of(8, 9)); threadPoolSize.put("instanceOne", 5); threadPoolSize.put("instanceTwo", 5); threadPoolSize.put("instanceThree", 5); threadPoolSize.put("instanceFour", 5); threadPoolSize.put("instanceFive", 5); testSubject.balance(eventProcessor).perform(); assertEquals(2, segments.get("instanceOne").size()); assertEquals(2, segments.get("instanceTwo").size()); assertEquals(2, segments.get("instanceThree").size()); assertEquals(2, segments.get("instanceFour").size()); assertEquals(2, segments.get("instanceFive").size()); }
@Test public void testDifferentThreadPoolSize() { segments.put("instanceOne", of()); segments.put("instanceTwo", of(0, 1, 2, 3, 7)); segments.put("instanceThree", of(4)); segments.put("instanceFour", of(5, 6)); segments.put("instanceFive", of(8, 9)); threadPoolSize.put("instanceOne", 1); threadPoolSize.put("instanceTwo", 5); threadPoolSize.put("instanceThree", 1); threadPoolSize.put("instanceFour", 5); threadPoolSize.put("instanceFive", 6); testSubject.balance(eventProcessor).perform(); assertEquals(1, segments.get("instanceOne").size()); assertEquals(3, segments.get("instanceTwo").size()); assertEquals(1, segments.get("instanceThree").size()); assertEquals(2, segments.get("instanceFour").size()); assertEquals(3, segments.get("instanceFive").size()); }
@Test public void testTwoEqualsNodes() { segments.put("instanceOne", of(0,1,2)); segments.put("instanceTwo", of(3,4,5)); segments.put("instanceThree", of()); threadPoolSize.put("instanceOne", 4); threadPoolSize.put("instanceTwo", 4); threadPoolSize.put("instanceThree", 4); testSubject.balance(eventProcessor).perform(); assertEquals(2, segments.get("instanceOne").size()); assertEquals(2, segments.get("instanceTwo").size()); assertEquals(2, segments.get("instanceThree").size()); }