use of com.facebook.buck.distributed.thrift.LogDir in project buck by facebook.
the class DistBuildLogStateTrackerTest method testMaterializesBuckOutDirForRuns.
@Test
public void testMaterializesBuckOutDirForRuns() throws IOException {
BuildSlaveInfo runOneSlaveInfo = new BuildSlaveInfo();
RunId runOneId = new RunId();
runOneId.setId(RUN_ONE_ID);
runOneSlaveInfo.setRunId(runOneId);
runOneSlaveInfo.setLogDirZipWritten(true);
BuildSlaveInfo runTwoSlaveInfo = new BuildSlaveInfo();
RunId runTwoId = new RunId();
runTwoId.setId(RUN_TWO_ID);
runTwoSlaveInfo.setRunId(runTwoId);
runTwoSlaveInfo.setLogDirZipWritten(true);
List<BuildSlaveInfo> slaveInfos = ImmutableList.of(runOneSlaveInfo, runTwoSlaveInfo);
List<RunId> runIdsToMaterialize = distBuildLogStateTracker.runIdsToMaterializeLogDirsFor(slaveInfos);
assertThat(runIdsToMaterialize.size(), Matchers.equalTo(2));
assertThat(runIdsToMaterialize, Matchers.contains(runOneId, runTwoId));
LogDir logDirOne = new LogDir();
logDirOne.setRunId(runOneId);
logDirOne.setData(readTestData(RUN_ONE_BUCK_OUT_ZIP));
LogDir logDirTwo = new LogDir();
logDirTwo.setRunId(runTwoId);
logDirTwo.setData(readTestData(RUN_TWO_BUCK_OUT_ZIP));
List<LogDir> logDirs = ImmutableList.of(logDirOne, logDirTwo);
distBuildLogStateTracker.materializeLogDirs(logDirs);
Path runOneBuckOutDir = logDir.resolve(RUN_ONE_BUCK_OUT_DIR);
assertTrue(runOneBuckOutDir.toFile().exists());
assertTrue(runOneBuckOutDir.resolve(FILE_ONE_PATH).toFile().exists());
assertTrue(runOneBuckOutDir.resolve(FILE_TWO_PATH).toFile().exists());
String fileOneContents = new String(Files.readAllBytes(runOneBuckOutDir.resolve(FILE_ONE_PATH)));
assertThat(fileOneContents, Matchers.equalTo(FILE_ONE_CONTENTS));
String fileTwoContents = new String(Files.readAllBytes(runOneBuckOutDir.resolve(FILE_TWO_PATH)));
assertThat(fileTwoContents, Matchers.equalTo(FILE_TWO_CONTENTS));
Path runTwoBuckOutDir = logDir.resolve(RUN_TWO_BUCK_OUT_DIR);
assertTrue(runTwoBuckOutDir.toFile().exists());
assertTrue(runTwoBuckOutDir.resolve(FILE_THREE_PATH).toFile().exists());
assertTrue(runTwoBuckOutDir.resolve(FILE_FOUR_PATH).toFile().exists());
String fileThreeContents = new String(Files.readAllBytes(runTwoBuckOutDir.resolve(FILE_THREE_PATH)));
assertThat(fileThreeContents, Matchers.equalTo(FILE_THREE_CONTENTS));
String fileFourContents = new String(Files.readAllBytes(runTwoBuckOutDir.resolve(FILE_FOUR_PATH)));
assertThat(fileFourContents, Matchers.equalTo(FILE_FOUR_CONTENTS));
}
Aggregations