@Inject public SegmentLoaderLocalCacheManager( IndexIO indexIO, SegmentLoaderConfig config, @Json ObjectMapper mapper ) { this.indexIO = indexIO; this.config = config; this.jsonMapper = mapper; this.locations = new ArrayList<>(); for (StorageLocationConfig locationConfig : config.getLocations()) { locations.add(new StorageLocation( locationConfig.getPath(), locationConfig.getMaxSize(), locationConfig.getFreeSpacePercent() )); } }
private StorageLocation fakeLocation(long total, long free, long max, Double percent) { File file = EasyMock.mock(File.class); EasyMock.expect(file.getTotalSpace()).andReturn(total).anyTimes(); EasyMock.expect(file.getFreeSpace()).andReturn(free).anyTimes(); EasyMock.replay(file); return new StorageLocation(file, max, percent); }
@Test public void testStorageLocation() { long expectedAvail = 1000L; StorageLocation loc = new StorageLocation(new File("/tmp"), expectedAvail, null); verifyLoc(expectedAvail, loc); final DataSegment secondSegment = makeSegment("2012-01-02/2012-01-03", 23); loc.addSegment(makeSegment("2012-01-01/2012-01-02", 10)); expectedAvail -= 10; verifyLoc(expectedAvail, loc); loc.addSegment(makeSegment("2012-01-01/2012-01-02", 10)); verifyLoc(expectedAvail, loc); loc.addSegment(secondSegment); expectedAvail -= 23; verifyLoc(expectedAvail, loc); loc.removeSegment(makeSegment("2012-01-01/2012-01-02", 10)); expectedAvail += 10; verifyLoc(expectedAvail, loc); loc.removeSegment(makeSegment("2012-01-01/2012-01-02", 10)); verifyLoc(expectedAvail, loc); loc.removeSegment(secondSegment); expectedAvail += 23; verifyLoc(expectedAvail, loc); }
@Inject public SegmentLoaderLocalCacheManager( IndexIO indexIO, SegmentLoaderConfig config, @Json ObjectMapper mapper ) { this.indexIO = indexIO; this.config = config; this.jsonMapper = mapper; this.locations = Lists.newArrayList(); for (StorageLocationConfig locationConfig : config.getLocations()) { locations.add(new StorageLocation( locationConfig.getPath(), locationConfig.getMaxSize(), locationConfig.getFreeSpacePercent() )); } }