use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project alluxio by Alluxio.
the class BlockMasterWorkerServiceHandlerTest method workerHeartbeatFailsOnDuplicateBlockLocation.
@Test
public void workerHeartbeatFailsOnDuplicateBlockLocation() throws Exception {
long workerId = mBlockMaster.getWorkerId(NET_ADDRESS_1);
// Prepare LocationBlockIdListEntry objects
BlockStoreLocation loc = new BlockStoreLocation("MEM", 0);
BlockStoreLocationProto locationProto = BlockStoreLocationProto.newBuilder().setTierAlias(loc.tierAlias()).setMediumType(loc.mediumType()).build();
BlockIdList blockIdList1 = BlockIdList.newBuilder().addAllBlockId(ImmutableList.of(1L, 2L)).build();
LocationBlockIdListEntry listEntry1 = LocationBlockIdListEntry.newBuilder().setKey(locationProto).setValue(blockIdList1).build();
BlockIdList blockIdList2 = BlockIdList.newBuilder().addAllBlockId(ImmutableList.of(3L, 4L)).build();
LocationBlockIdListEntry listEntry2 = LocationBlockIdListEntry.newBuilder().setKey(locationProto).setValue(blockIdList2).build();
BlockHeartbeatPRequest request = BlockHeartbeatPRequest.newBuilder().setWorkerId(workerId).addAddedBlocks(listEntry1).addAddedBlocks(listEntry2).build();
// Noop response observer
StreamObserver<BlockHeartbeatPResponse> noopResponseObserver = new StreamObserver<BlockHeartbeatPResponse>() {
@Override
public void onNext(BlockHeartbeatPResponse response) {
}
@Override
public void onError(Throwable t) {
}
@Override
public void onCompleted() {
}
};
assertThrows(AssertionError.class, () -> {
mHandler.blockHeartbeat(request, noopResponseObserver);
});
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project alluxio by Alluxio.
the class BlockMasterWorkerServiceHandlerTest method registerWorkerFailsOnDuplicateBlockLocation.
@Test
public void registerWorkerFailsOnDuplicateBlockLocation() throws Exception {
long workerId = mBlockMaster.getWorkerId(NET_ADDRESS_1);
// Prepare LocationBlockIdListEntry objects
BlockStoreLocation loc = new BlockStoreLocation("MEM", 0);
BlockStoreLocationProto locationProto = BlockStoreLocationProto.newBuilder().setTierAlias(loc.tierAlias()).setMediumType(loc.mediumType()).build();
BlockIdList blockIdList1 = BlockIdList.newBuilder().addAllBlockId(ImmutableList.of(1L, 2L)).build();
LocationBlockIdListEntry listEntry1 = LocationBlockIdListEntry.newBuilder().setKey(locationProto).setValue(blockIdList1).build();
BlockIdList blockIdList2 = BlockIdList.newBuilder().addAllBlockId(ImmutableList.of(3L, 4L)).build();
LocationBlockIdListEntry listEntry2 = LocationBlockIdListEntry.newBuilder().setKey(locationProto).setValue(blockIdList2).build();
// Prepare a lease
GetRegisterLeasePRequest leaseRequest = GetRegisterLeasePRequest.newBuilder().setWorkerId(workerId).setBlockCount(blockIdList1.getBlockIdCount() + blockIdList2.getBlockIdCount()).build();
Optional<RegisterLease> lease = mBlockMaster.tryAcquireRegisterLease(leaseRequest);
assertTrue(lease.isPresent());
// The request is not deduplicated
RegisterWorkerPRequest request = RegisterWorkerPRequest.newBuilder().setWorkerId(workerId).addStorageTiers("MEM").putTotalBytesOnTiers("MEM", 1000L).putUsedBytesOnTiers("MEM", 0L).setOptions(RegisterWorkerPOptions.getDefaultInstance()).addCurrentBlocks(listEntry1).addCurrentBlocks(listEntry2).build();
// Noop response observer
StreamObserver<RegisterWorkerPResponse> noopResponseObserver = new StreamObserver<RegisterWorkerPResponse>() {
@Override
public void onNext(RegisterWorkerPResponse response) {
}
@Override
public void onError(Throwable t) {
}
@Override
public void onCompleted() {
}
};
assertThrows(AssertionError.class, () -> {
mHandler.registerWorker(request, noopResponseObserver);
});
mBlockMaster.releaseRegisterLease(workerId);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project alluxio by Alluxio.
the class BlockMasterWorkerServiceHandlerTest method registerLeaseTurnedOff.
@Test
public void registerLeaseTurnedOff() throws Exception {
initServiceHandler(false);
long workerId = mBlockMaster.getWorkerId(NET_ADDRESS_1);
// Prepare LocationBlockIdListEntry objects
BlockStoreLocation loc = new BlockStoreLocation("MEM", 0);
BlockStoreLocationProto locationProto = BlockStoreLocationProto.newBuilder().setTierAlias(loc.tierAlias()).setMediumType(loc.mediumType()).build();
BlockIdList blockIdList1 = BlockIdList.newBuilder().addAllBlockId(ImmutableList.of(1L, 2L)).build();
LocationBlockIdListEntry listEntry1 = LocationBlockIdListEntry.newBuilder().setKey(locationProto).setValue(blockIdList1).build();
// No lease is acquired
RegisterWorkerPRequest request = RegisterWorkerPRequest.newBuilder().setWorkerId(workerId).addStorageTiers("MEM").putTotalBytesOnTiers("MEM", 1000L).putUsedBytesOnTiers("MEM", 0L).setOptions(RegisterWorkerPOptions.getDefaultInstance()).addCurrentBlocks(listEntry1).build();
Queue<Throwable> errors = new ConcurrentLinkedDeque<>();
StreamObserver<RegisterWorkerPResponse> noopResponseObserver = new StreamObserver<RegisterWorkerPResponse>() {
@Override
public void onNext(RegisterWorkerPResponse response) {
}
@Override
public void onError(Throwable t) {
errors.offer(t);
}
@Override
public void onCompleted() {
}
};
mHandler.registerWorker(request, noopResponseObserver);
assertEquals(0, errors.size());
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project beam by apache.
the class ServerFactoryTest method runTestUsing.
private Endpoints.ApiServiceDescriptor runTestUsing(ServerFactory serverFactory, ManagedChannelFactory channelFactory) throws Exception {
Endpoints.ApiServiceDescriptor.Builder apiServiceDescriptorBuilder = Endpoints.ApiServiceDescriptor.newBuilder();
final Collection<Elements> serverElements = new ArrayList<>();
final CountDownLatch clientHangedUp = new CountDownLatch(1);
CallStreamObserver<Elements> serverInboundObserver = TestStreams.withOnNext(serverElements::add).withOnCompleted(clientHangedUp::countDown).build();
TestDataService service = new TestDataService(serverInboundObserver);
Server server = serverFactory.allocateAddressAndCreate(ImmutableList.of(service), apiServiceDescriptorBuilder);
assertFalse(server.isShutdown());
ManagedChannel channel = channelFactory.forDescriptor(apiServiceDescriptorBuilder.build());
BeamFnDataGrpc.BeamFnDataStub stub = BeamFnDataGrpc.newStub(channel);
final Collection<BeamFnApi.Elements> clientElements = new ArrayList<>();
final CountDownLatch serverHangedUp = new CountDownLatch(1);
CallStreamObserver<BeamFnApi.Elements> clientInboundObserver = TestStreams.withOnNext(clientElements::add).withOnCompleted(serverHangedUp::countDown).build();
StreamObserver<Elements> clientOutboundObserver = stub.data(clientInboundObserver);
StreamObserver<BeamFnApi.Elements> serverOutboundObserver = service.outboundObservers.take();
clientOutboundObserver.onNext(CLIENT_DATA);
serverOutboundObserver.onNext(SERVER_DATA);
clientOutboundObserver.onCompleted();
clientHangedUp.await();
serverOutboundObserver.onCompleted();
serverHangedUp.await();
assertThat(clientElements, contains(SERVER_DATA));
assertThat(serverElements, contains(CLIENT_DATA));
return apiServiceDescriptorBuilder.build();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project beam by apache.
the class BeamFnLoggingClientTest method testLogging.
@Test
public void testLogging() throws Exception {
BeamFnLoggingMDC.setInstructionId("instruction-1");
AtomicBoolean clientClosedStream = new AtomicBoolean();
Collection<BeamFnApi.LogEntry> values = new ConcurrentLinkedQueue<>();
AtomicReference<StreamObserver<BeamFnApi.LogControl>> outboundServerObserver = new AtomicReference<>();
CallStreamObserver<BeamFnApi.LogEntry.List> inboundServerObserver = TestStreams.withOnNext((BeamFnApi.LogEntry.List logEntries) -> values.addAll(logEntries.getLogEntriesList())).withOnCompleted(() -> {
// Remember that the client told us that this stream completed
clientClosedStream.set(true);
outboundServerObserver.get().onCompleted();
}).build();
Endpoints.ApiServiceDescriptor apiServiceDescriptor = Endpoints.ApiServiceDescriptor.newBuilder().setUrl(this.getClass().getName() + "-" + UUID.randomUUID().toString()).build();
Server server = InProcessServerBuilder.forName(apiServiceDescriptor.getUrl()).addService(new BeamFnLoggingGrpc.BeamFnLoggingImplBase() {
@Override
public StreamObserver<BeamFnApi.LogEntry.List> logging(StreamObserver<BeamFnApi.LogControl> outboundObserver) {
outboundServerObserver.set(outboundObserver);
return inboundServerObserver;
}
}).build();
server.start();
ManagedChannel channel = InProcessChannelBuilder.forName(apiServiceDescriptor.getUrl()).build();
try {
BeamFnLoggingClient client = new BeamFnLoggingClient(PipelineOptionsFactory.fromArgs(new String[] { "--defaultSdkHarnessLogLevel=OFF", "--sdkHarnessLogLevelOverrides={\"ConfiguredLogger\": \"DEBUG\"}" }).create(), apiServiceDescriptor, (Endpoints.ApiServiceDescriptor descriptor) -> channel);
// Keep a strong reference to the loggers in this block. Otherwise the call to client.close()
// removes the only reference and the logger may get GC'd before the assertions (BEAM-4136).
Logger rootLogger = LogManager.getLogManager().getLogger("");
Logger configuredLogger = LogManager.getLogManager().getLogger("ConfiguredLogger");
// Ensure that log levels were correctly set.
assertEquals(Level.OFF, rootLogger.getLevel());
assertEquals(Level.FINE, configuredLogger.getLevel());
// Should be filtered because the default log level override is OFF
rootLogger.log(FILTERED_RECORD);
// Should not be filtered because the default log level override for ConfiguredLogger is DEBUG
configuredLogger.log(TEST_RECORD);
configuredLogger.log(TEST_RECORD_WITH_EXCEPTION);
client.close();
// Verify that after close, log levels are reset.
assertEquals(Level.INFO, rootLogger.getLevel());
assertNull(configuredLogger.getLevel());
assertTrue(clientClosedStream.get());
assertTrue(channel.isShutdown());
assertThat(values, contains(TEST_ENTRY, TEST_ENTRY_WITH_EXCEPTION));
} finally {
server.shutdownNow();
}
}
Aggregations