### Question:
RoundRobinVolumeChoosingPolicy implements VolumeChoosingPolicy { @Override public HddsVolume chooseVolume(List<HddsVolume> volumes, long maxContainerSize) throws IOException { if (volumes.size() < 1) { throw new DiskOutOfSpaceException("No more available volumes"); } int nextIndex = nextVolumeIndex.get(); int currentVolumeIndex = nextIndex < volumes.size() ? nextIndex : 0; int startVolumeIndex = currentVolumeIndex; long maxAvailable = 0; while (true) { final HddsVolume volume = volumes.get(currentVolumeIndex); long availableVolumeSize = volume.getAvailable() - volume.getCommittedBytes(); currentVolumeIndex = (currentVolumeIndex + 1) % volumes.size(); if (availableVolumeSize > maxContainerSize) { nextVolumeIndex.compareAndSet(nextIndex, currentVolumeIndex); return volume; } if (availableVolumeSize > maxAvailable) { maxAvailable = availableVolumeSize; } if (currentVolumeIndex == startVolumeIndex) { throw new DiskOutOfSpaceException("Out of space: " + "The volume with the most available space (=" + maxAvailable + " B) is less than the container size (=" + maxContainerSize + " B)."); } } }  @Override HddsVolume chooseVolume(List<HddsVolume> volumes,
      long maxContainerSize); static final Log LOG; }### Answer:
@Test public void testRRVolumeChoosingPolicy() throws Exception { HddsVolume hddsVolume1 = volumes.get(0); HddsVolume hddsVolume2 = volumes.get(1); Assert.assertEquals(100L, hddsVolume1.getAvailable()); Assert.assertEquals(200L, hddsVolume2.getAvailable()); Assert.assertEquals(hddsVolume1, policy.chooseVolume(volumes, 0)); Assert.assertEquals(hddsVolume2, policy.chooseVolume(volumes, 0)); Assert.assertEquals(hddsVolume1, policy.chooseVolume(volumes, 0)); Assert.assertEquals(hddsVolume2, policy.chooseVolume(volumes, 0)); Assert.assertEquals(hddsVolume2, policy.chooseVolume(volumes, 150)); try { policy.chooseVolume(volumes, Long.MAX_VALUE); Assert.fail(); } catch (IOException e) { } }
@Test public void testRRPolicyExceptionMessage() throws Exception { int blockSize = 300; try { policy.chooseVolume(volumes, blockSize); Assert.fail("expected to throw DiskOutOfSpaceException"); } catch(DiskOutOfSpaceException e) { Assert.assertEquals("Not returning the expected message", "Out of space: The volume with the most available space (=" + 200 + " B) is less than the container size (=" + blockSize + " B).", e.getMessage()); } }