use of build.buildfarm.instance.MatchListener in project bazel-buildfarm by bazelbuild.
the class ShardWorkerInstanceTest method dispatchOperationThrowsOnSocketException.
@SuppressWarnings("unchecked")
@Test(expected = SocketException.class)
public void dispatchOperationThrowsOnSocketException() throws IOException, InterruptedException {
when(backplane.dispatchOperation(any(List.class))).thenThrow(SocketException.class);
MatchListener listener = mock(MatchListener.class);
instance.dispatchOperation(listener);
}
use of build.buildfarm.instance.MatchListener in project bazel-buildfarm by bazelbuild.
the class MemoryInstanceTest method matchCancelRemovesFromWorkers.
@Test
public void matchCancelRemovesFromWorkers() throws InterruptedException {
MatchListener listener = mock(MatchListener.class);
instance.match(Platform.getDefaultInstance(), listener);
ArgumentCaptor<Runnable> onCancelHandlerCaptor = ArgumentCaptor.forClass(Runnable.class);
verify(listener, times(1)).setOnCancelHandler(onCancelHandlerCaptor.capture());
onCancelHandlerCaptor.getValue().run();
assertThat(workers).isEmpty();
}
use of build.buildfarm.instance.MatchListener in project bazel-buildfarm by bazelbuild.
the class MemoryInstanceTest method requeueRemovesRequeuers.
@Test
public void requeueRemovesRequeuers() throws InterruptedException {
Digest actionDigest = createAction(Action.newBuilder());
instance.execute(actionDigest, /* skipCacheLookup=*/
true, ExecutionPolicy.getDefaultInstance(), ResultsCachePolicy.getDefaultInstance(), RequestMetadata.getDefaultInstance(), (operation) -> {
});
MatchListener listener = mock(MatchListener.class);
when(listener.onEntry(any(QueueEntry.class))).thenReturn(true);
instance.match(Platform.getDefaultInstance(), listener);
ArgumentCaptor<QueueEntry> queueEntryCaptor = ArgumentCaptor.forClass(QueueEntry.class);
verify(listener, times(1)).onEntry(queueEntryCaptor.capture());
QueueEntry queueEntry = queueEntryCaptor.getValue();
assertThat(queueEntry).isNotNull();
String operationName = queueEntry.getExecuteEntry().getOperationName();
assertThat(requeuers).isNotEmpty();
Operation queuedOperation = outstandingOperations.get(operationName);
assertThat(AbstractServerInstance.isQueued(queuedOperation)).isTrue();
// requeue
instance.putOperation(queuedOperation);
assertThat(requeuers).isEmpty();
assertThat(outstandingOperations.get(operationName)).isEqualTo(queuedOperation);
}
use of build.buildfarm.instance.MatchListener 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));
}
use of build.buildfarm.instance.MatchListener in project bazel-buildfarm by bazelbuild.
the class ShardWorkerContextTest method queueEntryWithExecutionPolicyPlatformMatches.
@SuppressWarnings("unchecked")
@Test
public void queueEntryWithExecutionPolicyPlatformMatches() throws Exception {
WorkerContext context = createTestContext(Platform.getDefaultInstance(), ImmutableList.of(ExecutionPolicy.newBuilder().setName("foo").build()));
Platform matchPlatform = Platform.newBuilder().addProperties(Property.newBuilder().setName("execution-policy").setValue("foo").build()).build();
QueueEntry queueEntry = QueueEntry.newBuilder().setPlatform(matchPlatform).build();
when(backplane.dispatchOperation(any(List.class))).thenReturn(queueEntry).thenReturn(// provide a match completion in failure case
null);
MatchListener listener = mock(MatchListener.class);
context.match(listener);
verify(listener, times(1)).onEntry(queueEntry);
}
Aggregations