public static SegmentHelper getSegmentHelperMock() { SegmentHelper helper = spy(new SegmentHelper()); doReturn(NodeUri.newBuilder().setEndpoint("localhost").setPort(SERVICE_PORT).build()).when(helper).getSegmentUri( anyString(), anyString(), anyLong(), any()); doReturn(CompletableFuture.completedFuture(true)).when(helper).sealSegment( anyString(), anyString(), anyLong(), any(), any(), any(), anyLong()); doReturn(CompletableFuture.completedFuture(true)).when(helper).createSegment( anyString(), anyString(), anyLong(), any(), any(), any(), any(), anyLong()); doReturn(CompletableFuture.completedFuture(true)).when(helper).deleteSegment( anyString(), anyString(), anyLong(), any(), any(), any(), anyLong()); doReturn(CompletableFuture.completedFuture(true)).when(helper).createTransaction( anyString(), anyString(), anyLong(), any(), any(), any(), any()); doReturn(CompletableFuture.completedFuture(true)).when(helper).abortTransaction( anyString(), anyString(), anyLong(), any(), any(), any(), any()); doReturn(CompletableFuture.completedFuture(true)).when(helper).commitTransaction( anyString(), anyString(), anyLong(), anyLong(), any(), any(), any(), any()); doReturn(CompletableFuture.completedFuture(true)).when(helper).updatePolicy( anyString(), anyString(), any(), anyLong(), any(), any(), any(), anyLong()); doReturn(CompletableFuture.completedFuture(true)).when(helper).truncateSegment( anyString(), anyString(), anyLong(), anyLong(), any(), any(), any(), anyLong()); doReturn(CompletableFuture.completedFuture(new WireCommands.StreamSegmentInfo(0L, "", true, true, false, 0L, 0L, 0L))).when(helper).getSegmentInfo( anyString(), anyString(), anyLong(), any(), any(), anyString()); return helper; }
servers = controllerServerList.getNodeURIList().stream() .map(node -> new EquivalentAddressGroup(new InetSocketAddress(node.getEndpoint(), node.getPort()))) .collect(Collectors.toList()); } else {
/** * <code>repeated .io.pravega.controller.stream.api.grpc.v1.NodeUri nodeURI = 1;</code> */ public io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri.Builder addNodeURIBuilder( int index) { return getNodeURIFieldBuilder().addBuilder( index, io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri.getDefaultInstance()); } /**
@io.grpc.stub.annotations.RpcMethod( fullMethodName = SERVICE_NAME + '/' + "getURI", requestType = io.pravega.controller.stream.api.grpc.v1.Controller.SegmentId.class, responseType = io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri.class, methodType = io.grpc.MethodDescriptor.MethodType.UNARY) public static io.grpc.MethodDescriptor<io.pravega.controller.stream.api.grpc.v1.Controller.SegmentId, io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri> getGetURIMethod() { io.grpc.MethodDescriptor<io.pravega.controller.stream.api.grpc.v1.Controller.SegmentId, io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri> getGetURIMethod; if ((getGetURIMethod = ControllerServiceGrpc.getGetURIMethod) == null) { synchronized (ControllerServiceGrpc.class) { if ((getGetURIMethod = ControllerServiceGrpc.getGetURIMethod) == null) { ControllerServiceGrpc.getGetURIMethod = getGetURIMethod = io.grpc.MethodDescriptor.<io.pravega.controller.stream.api.grpc.v1.Controller.SegmentId, io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri>newBuilder() .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "io.pravega.controller.stream.api.grpc.v1.ControllerService", "getURI")) .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.pravega.controller.stream.api.grpc.v1.Controller.SegmentId.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri.getDefaultInstance())) .setSchemaDescriptor(new ControllerServiceMethodDescriptorSupplier("getURI")) .build(); } } } return getGetURIMethod; }
@Before public void setup() throws Exception { zkServer = new TestingServerStarter().start(); zkServer.start(); zkClient = CuratorFrameworkFactory.newClient(zkServer.getConnectString(), new ExponentialBackoffRetry(200, 10, 5000)); zkClient.start(); streamStore = StreamStoreFactory.createZKStore(zkClient, executor); TaskMetadataStore taskMetadataStore = TaskStoreFactory.createZKStore(zkClient, executor); HostControllerStore hostStore = HostStoreFactory.createInMemoryStore(HostMonitorConfigImpl.dummyConfig()); segmentHelperMock = spy(new SegmentHelper()); doReturn(Controller.NodeUri.newBuilder().setEndpoint("localhost").setPort(Config.SERVICE_PORT).build()).when(segmentHelperMock).getSegmentUri( anyString(), anyString(), anyInt(), any()); ConnectionFactoryImpl connectionFactory = new ConnectionFactoryImpl(ClientConfig.builder().build()); streamMetadataTasks = new StreamMetadataTasks(streamStore, hostStore, taskMetadataStore, segmentHelperMock, executor, "host", connectionFactory, AuthHelper.getDisabledAuthHelper(), requestTracker); streamTransactionMetadataTasks = new StreamTransactionMetadataTasks( streamStore, hostStore, segmentHelperMock, executor, "host", connectionFactory, AuthHelper.getDisabledAuthHelper()); controllerService = new ControllerService(streamStore, hostStore, streamMetadataTasks, streamTransactionMetadataTasks, segmentHelperMock, executor, null); controllerService.createScope(SCOPE).get(); }
public static SegmentHelper getFailingSegmentHelperMock() { SegmentHelper helper = spy(new SegmentHelper()); doReturn(NodeUri.newBuilder().setEndpoint("localhost").setPort(SERVICE_PORT).build()).when(helper).getSegmentUri( anyString(), anyString(), anyLong(), any()); doReturn(Futures.failedFuture(new RuntimeException())).when(helper).sealSegment( anyString(), anyString(), anyLong(), any(), any(), any(), anyLong()); doReturn(Futures.failedFuture(new RuntimeException())).when(helper).createSegment( anyString(), anyString(), anyLong(), any(), any(), any(), any(), anyLong()); doReturn(Futures.failedFuture(new RuntimeException())).when(helper).deleteSegment( anyString(), anyString(), anyLong(), any(), any(), any(), anyLong()); doReturn(Futures.failedFuture(new RuntimeException())).when(helper).createTransaction( anyString(), anyString(), anyLong(), any(), any(), any(), any()); doReturn(Futures.failedFuture(new RuntimeException())).when(helper).abortTransaction( anyString(), anyString(), anyLong(), any(), any(), any(), any()); doReturn(Futures.failedFuture(new RuntimeException())).when(helper).commitTransaction( anyString(), anyString(), anyLong(), anyLong(), any(), any(), any(), any()); doReturn(Futures.failedFuture(new RuntimeException())).when(helper).updatePolicy( anyString(), anyString(), any(), anyLong(), any(), any(), any(), anyLong()); return helper; } }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri)) { return super.equals(obj); } io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri other = (io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri) obj; boolean result = true; result = result && getEndpoint() .equals(other.getEndpoint()); result = result && (getPort() == other.getPort()); result = result && unknownFields.equals(other.unknownFields); return result; }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
public CompletableFuture<List<NodeUri>> getControllerServerList() { if (cluster == null) { return Futures.failedFuture(new IllegalStateException("Controller cluster not initialized")); } return CompletableFuture.supplyAsync(() -> { try { return cluster.getClusterMembers().stream() .map(host -> NodeUri.newBuilder().setEndpoint(host.getIpAddr()).setPort(host.getPort()).build()) .collect(Collectors.toList()); } catch (ClusterException e) { // cluster implementation throws checked exceptions which cannot be thrown inside completable futures. throw Exceptions.sneakyThrow(e); } }, executor); }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + ENDPOINT_FIELD_NUMBER; hash = (53 * hash) + getEndpoint().hashCode(); hash = (37 * hash) + PORT_FIELD_NUMBER; hash = (53 * hash) + getPort(); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
public io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri getDefaultInstanceForType() { return io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri.getDefaultInstance(); }
public Builder mergeFrom(io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri other) { if (other == io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri.getDefaultInstance()) return this; if (!other.getEndpoint().isEmpty()) { endpoint_ = other.endpoint_; onChanged(); } if (other.getPort() != 0) { setPort(other.getPort()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
/** * <code>repeated .io.pravega.controller.stream.api.grpc.v1.NodeUri nodeURI = 1;</code> */ public io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri.Builder addNodeURIBuilder() { return getNodeURIFieldBuilder().addBuilder( io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri.getDefaultInstance()); } /**
public io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri buildPartial() { io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri result = new io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri(this); result.endpoint_ = endpoint_; result.port_ = port_; onBuilt(); return result; }
/** * Converts PravegaNodeURI into NodeURI. * * @param uri The PravegaNodeURI string. * @return Node URI string. */ public static final NodeUri decode(final PravegaNodeUri uri) { Preconditions.checkNotNull(uri, "uri"); return NodeUri.newBuilder().setEndpoint(uri.getEndpoint()).setPort(uri.getPort()).build(); }
@Override public void getURI(SegmentId request, StreamObserver<NodeUri> responseObserver) { responseObserver.onNext(NodeUri.newBuilder().setEndpoint("localhost2").setPort(2).build()); responseObserver.onCompleted(); } };
@Override public void getControllerServerList(ServerRequest request, StreamObserver<ServerResponse> responseObserver) { responseObserver.onNext(ServerResponse.newBuilder() .addNodeURI(NodeUri.newBuilder().setEndpoint("localhost").setPort(serverPort1).build()) .addNodeURI(NodeUri.newBuilder().setEndpoint("localhost").setPort(serverPort2).build()) .addNodeURI(NodeUri.newBuilder().setEndpoint("localhost").setPort(serverPort3).build()) .build()); responseObserver.onCompleted(); }
/** * Helper to convert NodeURI into PravegaNodeURI. * * @param uri Node URI. * @return PravegaNodeURI. */ public static final PravegaNodeUri encode(final NodeUri uri) { Preconditions.checkNotNull(uri, "uri"); return new PravegaNodeUri(uri.getEndpoint(), uri.getPort()); }
@Override public void getURI(SegmentId request, StreamObserver<NodeUri> responseObserver) { responseObserver.onNext(NodeUri.newBuilder().setEndpoint("localhost3").setPort(3).build()); responseObserver.onCompleted(); } };
@Override public void getControllerServerList(ServerRequest request, StreamObserver<ServerResponse> responseObserver) { responseObserver.onNext(ServerResponse.newBuilder() .addNodeURI(NodeUri.newBuilder().setEndpoint("localhost").setPort(serverPort1).build()) .addNodeURI(NodeUri.newBuilder().setEndpoint("localhost").setPort(serverPort2).build()) .addNodeURI(NodeUri.newBuilder().setEndpoint("localhost").setPort(serverPort3).build()) .build()); responseObserver.onCompleted(); }