Search in sources :

Example 96 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class WorkerProcessTest method testDoesNotBlockOnLargeStderr.

@Test(timeout = 20 * 1000)
public void testDoesNotBlockOnLargeStderr() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "worker_process", temporaryPaths);
    workspace.setUp();
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(workspace.getDestPath());
    Console console = new Console(Verbosity.ALL, System.out, System.err, Ansi.withoutTty());
    String script;
    if (Platform.detect() == Platform.WINDOWS) {
        script = workspace.getDestPath().resolve("script.bat").toString();
    } else {
        script = "./script.py";
    }
    WorkerProcess workerProcess = new WorkerProcess(new DefaultProcessExecutor(console), ProcessExecutorParams.builder().setCommand(ImmutableList.of(script)).setDirectory(workspace.getDestPath()).build(), projectFilesystem, temporaryPaths.newFolder());
    try {
        workerProcess.ensureLaunchAndHandshake();
        fail("Handshake should have failed");
    } catch (HumanReadableException e) {
        // Check that all of the process's stderr was reported.
        assertThat(e.getMessage().length(), is(greaterThan(1024 * 1024)));
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) HumanReadableException(com.facebook.buck.util.HumanReadableException) Console(com.facebook.buck.util.Console) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 97 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class WorkerProcessProtocolZeroTest method testReceiveHandshakeWithIncorrectID.

@Test
public void testReceiveHandshakeWithIncorrectID() throws IOException {
    int handshakeID = 123;
    int differentHandshakeID = 456;
    JsonReader jsonReader = createMockJsonReaderForReceiveHandshake(differentHandshakeID, "handshake", "0");
    WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, dummyJsonWriter, jsonReader, newTempFile());
    try {
        protocol.receiveHandshake(handshakeID);
    } catch (HumanReadableException e) {
        assertThat(e.getMessage(), Matchers.containsString(String.format("Expected handshake response's \"id\" value to be \"%d\"", handshakeID)));
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) JsonReader(com.google.gson.stream.JsonReader) Test(org.junit.Test)

Example 98 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class WorkerProcessProtocolZeroTest method testReceiveCommandResponseWithInvalidType.

@Test
public void testReceiveCommandResponseWithInvalidType() throws IOException {
    int messageID = 123;
    JsonReader jsonReader = createMockJsonReaderForReceiveCommandResponse(messageID, "INVALID RESPONSE TYPE", 0);
    WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, dummyJsonWriter, jsonReader, newTempFile());
    try {
        protocol.receiveCommandResponse(messageID);
    } catch (HumanReadableException e) {
        assertThat(e.getMessage(), Matchers.containsString("Expected response's \"type\" to be one of"));
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) JsonReader(com.google.gson.stream.JsonReader) Test(org.junit.Test)

Example 99 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class WorkerProcessProtocolZeroTest method testSendCommandResponseWithWrongType.

@Test
public void testSendCommandResponseWithWrongType() throws IOException {
    StringWriter jsonSentToWorkerProcess = new StringWriter();
    WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, new JsonWriter(jsonSentToWorkerProcess), dummyJsonReader, newTempFile());
    try {
        protocol.sendCommandResponse(123, "WRONG_TYPE", 1);
    } catch (HumanReadableException e) {
        assertThat(e.getMessage(), Matchers.containsString("Expected response's \"type\" to be one of"));
    }
}
Also used : StringWriter(java.io.StringWriter) HumanReadableException(com.facebook.buck.util.HumanReadableException) JsonWriter(com.google.gson.stream.JsonWriter) Test(org.junit.Test)

Example 100 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class WorkerProcessProtocolZeroTest method testReceiveCommandWithInvalidType.

@Test
public void testReceiveCommandWithInvalidType() throws IOException {
    int messageID = 123;
    JsonReader jsonReader = createMockJsonReaderForReceiveCommand(messageID, "INVALID RESPONSE TYPE", "/path/to/args", "/path/to/stdout", "/path/to/stderr");
    WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, dummyJsonWriter, jsonReader, newTempFile());
    try {
        protocol.receiveCommand(messageID);
    } catch (HumanReadableException e) {
        assertThat(e.getMessage(), Matchers.containsString("Expected command's \"type\" to be \"command\""));
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) JsonReader(com.google.gson.stream.JsonReader) Test(org.junit.Test)

Aggregations

HumanReadableException (com.facebook.buck.util.HumanReadableException)195 Path (java.nio.file.Path)79 SourcePath (com.facebook.buck.rules.SourcePath)50 BuildTarget (com.facebook.buck.model.BuildTarget)49 Test (org.junit.Test)46 IOException (java.io.IOException)45 ImmutableList (com.google.common.collect.ImmutableList)39 BuildRule (com.facebook.buck.rules.BuildRule)31 ImmutableSet (com.google.common.collect.ImmutableSet)30 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)29 ImmutableMap (com.google.common.collect.ImmutableMap)26 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)22 Optional (java.util.Optional)21 PathSourcePath (com.facebook.buck.rules.PathSourcePath)20 VisibleForTesting (com.google.common.annotations.VisibleForTesting)18 Map (java.util.Map)18 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)17 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)16 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)15 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)15