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();
}
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();
}
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");
}
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);
}
}
}
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));
}
Aggregations