Search in sources :

Example 1 with MatchListener

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);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) MatchListener(build.buildfarm.instance.MatchListener) Test(org.junit.Test)

Example 2 with MatchListener

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();
}
Also used : MatchListener(build.buildfarm.instance.MatchListener) Test(org.junit.Test)

Example 3 with MatchListener

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);
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) Operation(com.google.longrunning.Operation) MatchListener(build.buildfarm.instance.MatchListener) QueueEntry(build.buildfarm.v1test.QueueEntry) Test(org.junit.Test)

Example 4 with MatchListener

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));
}
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)

Example 5 with MatchListener

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);
}
Also used : Platform(build.bazel.remote.execution.v2.Platform) WorkerContext(build.buildfarm.worker.WorkerContext) QueueEntry(build.buildfarm.v1test.QueueEntry) MatchListener(build.buildfarm.instance.MatchListener) Test(org.junit.Test)

Aggregations

MatchListener (build.buildfarm.instance.MatchListener)6 Test (org.junit.Test)6 QueueEntry (build.buildfarm.v1test.QueueEntry)4 ImmutableList (com.google.common.collect.ImmutableList)3 Platform (build.bazel.remote.execution.v2.Platform)2 List (java.util.List)2 Digest (build.bazel.remote.execution.v2.Digest)1 Property (build.bazel.remote.execution.v2.Platform.Property)1 Instance (build.buildfarm.instance.Instance)1 ExecutionPolicy (build.buildfarm.v1test.ExecutionPolicy)1 WorkerContext (build.buildfarm.worker.WorkerContext)1 Operation (com.google.longrunning.Operation)1 ByteString (com.google.protobuf.ByteString)1 Nullable (javax.annotation.Nullable)1 RunWith (org.junit.runner.RunWith)1 JUnit4 (org.junit.runners.JUnit4)1 Mockito.any (org.mockito.Mockito.any)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 Mockito.eq (org.mockito.Mockito.eq)1 Mockito.mock (org.mockito.Mockito.mock)1