Search in sources :

Example 1 with Platform

use of build.bazel.remote.execution.v2.Platform in project bazel-buildfarm by bazelbuild.

the class ResourceDeciderTest method decideResourceLimitationsTestEmptyEnvironmentParse.

// Function under test: decideResourceLimitations
// Reason for testing: if the user does not pass extra environment variables via platform
// properties they appear empty
// Failure explanation: the parsing crashed or did not provide an empty map
@Test
public void decideResourceLimitationsTestEmptyEnvironmentParse() throws Exception {
    // ARRANGE
    Command command = Command.newBuilder().setPlatform(Platform.newBuilder().addProperties(Platform.Property.newBuilder().setName("env-vars").setValue(""))).build();
    // ACT
    ResourceLimits limits = ResourceDecider.decideResourceLimitations(command, "worker", true, false, 100);
    // ASSERT
    assertThat(limits.extraEnvironmentVariables.isEmpty()).isTrue();
}
Also used : Command(build.bazel.remote.execution.v2.Command) Test(org.junit.Test)

Example 2 with Platform

use of build.bazel.remote.execution.v2.Platform in project bazel-buildfarm by bazelbuild.

the class ResourceDeciderTest method decideResourceLimitationsTestDefaultEnvironmentParse.

// Function under test: decideResourceLimitations
// Reason for testing: if the user does not pass extra environment variables via platform
// properties they appear empty
// Failure explanation: the parsing crashed or did not provide an empty map
@Test
public void decideResourceLimitationsTestDefaultEnvironmentParse() throws Exception {
    // ARRANGE
    Command command = Command.newBuilder().build();
    // ACT
    ResourceLimits limits = ResourceDecider.decideResourceLimitations(command, "worker", true, false, 100);
    // ASSERT
    assertThat(limits.extraEnvironmentVariables.isEmpty()).isTrue();
}
Also used : Command(build.bazel.remote.execution.v2.Command) Test(org.junit.Test)

Example 3 with Platform

use of build.bazel.remote.execution.v2.Platform in project bazel-buildfarm by bazelbuild.

the class ResourceDeciderTest method decideResourceLimitationsTestTwoIndividualEnvironmentVarParse.

// Function under test: decideResourceLimitations
// Reason for testing: if the user passes two extra individual environment variable via platform
// properties they should be parsed into the map
// Failure explanation: the parsing was not done correctly and the variables were ignored for some
// reason
@Test
public void decideResourceLimitationsTestTwoIndividualEnvironmentVarParse() throws Exception {
    // ARRANGE
    Command command = Command.newBuilder().setPlatform(Platform.newBuilder().addProperties(Platform.Property.newBuilder().setName("env-var:foo").setValue("bar")).addProperties(Platform.Property.newBuilder().setName("env-var:baz").setValue("qux"))).build();
    // ACT
    ResourceLimits limits = ResourceDecider.decideResourceLimitations(command, "worker", true, false, 100);
    // ASSERT
    assertThat(limits.extraEnvironmentVariables.size()).isEqualTo(2);
    assertThat(limits.extraEnvironmentVariables.containsKey("foo")).isTrue();
    assertThat(limits.extraEnvironmentVariables.get("foo")).isEqualTo("bar");
    assertThat(limits.extraEnvironmentVariables.containsKey("baz")).isTrue();
    assertThat(limits.extraEnvironmentVariables.get("baz")).isEqualTo("qux");
}
Also used : Command(build.bazel.remote.execution.v2.Command) Test(org.junit.Test)

Example 4 with Platform

use of build.bazel.remote.execution.v2.Platform in project bazel-buildfarm by bazelbuild.

the class MemoryInstance method matchSynchronized.

@SuppressWarnings("ConstantConditions")
private void matchSynchronized(Platform platform, MatchListener listener) throws InterruptedException {
    ImmutableList.Builder<Operation> rejectedOperations = ImmutableList.builder();
    boolean matched = false;
    SetMultimap<String, String> provisions = createProvisions(platform);
    WorkerQueue queue = queuedOperations.MatchEligibleQueue(provisions);
    while (!matched && !queue.operations.isEmpty()) {
        Operation operation = queue.operations.remove(0);
        ExecuteOperationMetadata metadata = expectExecuteOperationMetadata(operation);
        Preconditions.checkState(metadata != null, "metadata not found");
        Action action = getUnchecked(expect(metadata.getActionDigest(), Action.parser(), newDirectExecutorService(), RequestMetadata.getDefaultInstance()));
        Preconditions.checkState(action != null, "action not found");
        Command command = getUnchecked(expect(action.getCommandDigest(), Command.parser(), newDirectExecutorService(), RequestMetadata.getDefaultInstance()));
        Preconditions.checkState(command != null, "command not found");
        String operationName = operation.getName();
        DequeueMatchSettings settings = new DequeueMatchSettings();
        if (command == null) {
            cancelOperation(operationName);
        } else if (DequeueMatchEvaluator.shouldKeepOperation(settings, provisions, command)) {
            QueuedOperation queuedOperation = QueuedOperation.newBuilder().setAction(action).setCommand(command).setTree(getCompleteTree(action.getInputRootDigest())).build();
            ByteString queuedOperationBlob = queuedOperation.toByteString();
            Digest queuedOperationDigest = getDigestUtil().compute(queuedOperationBlob);
            // maybe do this elsewhere
            try {
                putBlob(this, queuedOperationDigest, queuedOperationBlob, 60, SECONDS, RequestMetadata.getDefaultInstance());
                QueueEntry queueEntry = QueueEntry.newBuilder().setExecuteEntry(ExecuteEntry.newBuilder().setOperationName(operationName).setActionDigest(metadata.getActionDigest()).setStdoutStreamName(metadata.getStdoutStreamName()).setStderrStreamName(metadata.getStderrStreamName()).setQueuedTimestamp(Timestamps.fromMillis(System.currentTimeMillis()))).setQueuedOperationDigest(queuedOperationDigest).setPlatform(command.getPlatform()).build();
                matched = true;
                if (listener.onEntry(queueEntry)) {
                    onDispatched(operation);
                } else {
                    enqueueOperation(operation);
                }
            } catch (StatusException | IOException e) {
                logger.log(Level.SEVERE, format("could not emplace queued operation: %s", operationName), e);
            }
        } else {
            rejectedOperations.add(operation);
        }
    }
    for (Operation operation : rejectedOperations.build()) {
        requeueOperation(operation);
    }
    if (!matched) {
        synchronized (queue.workers) {
            listener.setOnCancelHandler(() -> queuedOperations.removeWorker(listener));
            listener.onWaitStart();
            queuedOperations.AddWorker(provisions, listener);
        }
    }
}
Also used : WorkerQueue(build.buildfarm.instance.queues.WorkerQueue) Action(build.bazel.remote.execution.v2.Action) DequeueMatchSettings(build.buildfarm.worker.DequeueMatchSettings) Digest(build.bazel.remote.execution.v2.Digest) ImmutableList(com.google.common.collect.ImmutableList) ByteString(com.google.protobuf.ByteString) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) QueueEntry(build.buildfarm.v1test.QueueEntry) Command(build.bazel.remote.execution.v2.Command) QueuedOperation(build.buildfarm.v1test.QueuedOperation) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata)

Example 5 with Platform

use of build.bazel.remote.execution.v2.Platform in project bazel-buildfarm by bazelbuild.

the class OperationQueueClientTest method matchPlatformContainsExecutionPolicies.

@Test
public void matchPlatformContainsExecutionPolicies() throws InterruptedException {
    Instance instance = mock(Instance.class);
    doAnswer((Answer<Void>) invocation -> {
        MatchListener listener = (MatchListener) invocation.getArguments()[1];
        listener.onEntry(null);
        return null;
    }).when(instance).match(any(Platform.class), any(MatchListener.class));
    OperationQueueClient client = new OperationQueueClient(instance, Platform.getDefaultInstance(), ImmutableList.of(ExecutionPolicy.newBuilder().setName("foo").build()));
    MatchListener listener = new MatchListener() {

        @Override
        public void onWaitStart() {
        }

        @Override
        public void onWaitEnd() {
        }

        @Override
        public boolean onEntry(@Nullable QueueEntry queueEntry) {
            return true;
        }

        @Override
        public void onError(Throwable t) {
            t.printStackTrace();
        }

        @Override
        public void setOnCancelHandler(Runnable onCancelHandler) {
        }
    };
    client.match(listener);
    Platform matchPlatform = Platform.newBuilder().addProperties(Property.newBuilder().setName("execution-policy").setValue("foo").build()).build();
    verify(instance, times(1)).match(eq(matchPlatform), any(MatchListener.class));
}
Also used : ExecutionPolicy(build.buildfarm.v1test.ExecutionPolicy) Property(build.bazel.remote.execution.v2.Platform.Property) RunWith(org.junit.runner.RunWith) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Platform(build.bazel.remote.execution.v2.Platform) Instance(build.buildfarm.instance.Instance) Mockito.verify(org.mockito.Mockito.verify) MatchListener(build.buildfarm.instance.MatchListener) Answer(org.mockito.stubbing.Answer) ImmutableList(com.google.common.collect.ImmutableList) Mockito.doAnswer(org.mockito.Mockito.doAnswer) QueueEntry(build.buildfarm.v1test.QueueEntry) Mockito.any(org.mockito.Mockito.any) Nullable(javax.annotation.Nullable) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) Platform(build.bazel.remote.execution.v2.Platform) Instance(build.buildfarm.instance.Instance) MatchListener(build.buildfarm.instance.MatchListener) QueueEntry(build.buildfarm.v1test.QueueEntry) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 Command (build.bazel.remote.execution.v2.Command)7 Property (build.bazel.remote.execution.v2.Platform.Property)4 ImmutableList (com.google.common.collect.ImmutableList)4 ByteString (com.google.protobuf.ByteString)4 Platform (build.bazel.remote.execution.v2.Platform)3 QueueEntry (build.buildfarm.v1test.QueueEntry)3 MatchListener (build.buildfarm.instance.MatchListener)2 ExecutionPolicy (build.buildfarm.v1test.ExecutionPolicy)2 Action (build.bazel.remote.execution.v2.Action)1 EnvironmentVariable (build.bazel.remote.execution.v2.Command.EnvironmentVariable)1 Digest (build.bazel.remote.execution.v2.Digest)1 ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)1 Instance (build.buildfarm.instance.Instance)1 WorkerQueue (build.buildfarm.instance.queues.WorkerQueue)1 QueuedOperation (build.buildfarm.v1test.QueuedOperation)1 DequeueMatchSettings (build.buildfarm.worker.DequeueMatchSettings)1 WorkerContext (build.buildfarm.worker.WorkerContext)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 Operation (com.google.longrunning.Operation)1