Search in sources :

Example 1 with ModuleDefineTesting

use of org.apache.skywalking.oap.server.testing.module.ModuleDefineTesting in project incubator-skywalking by apache.

the class RemoteServiceHandlerTestCase method callTest.

@Test
public void callTest() throws DuplicateProviderException, ProviderNotFoundException, IOException {
    final String testWorkerId = "mock-worker";
    ModuleManagerTesting moduleManager = new ModuleManagerTesting();
    ModuleDefineTesting moduleDefine = new ModuleDefineTesting();
    moduleManager.put(CoreModule.NAME, moduleDefine);
    WorkerInstancesService workerInstancesService = new WorkerInstancesService();
    moduleDefine.provider().registerServiceImplementation(IWorkerInstanceGetter.class, workerInstancesService);
    moduleDefine.provider().registerServiceImplementation(IWorkerInstanceSetter.class, workerInstancesService);
    TestWorker worker = new TestWorker(moduleManager);
    workerInstancesService.put(testWorkerId, worker, TestRemoteData.class);
    String serverName = InProcessServerBuilder.generateName();
    MetricsCreator metricsCreator = mock(MetricsCreator.class);
    when(metricsCreator.createCounter(any(), any(), any(), any())).thenReturn(new CounterMetrics() {

        @Override
        public void inc() {
        }

        @Override
        public void inc(double value) {
        }
    });
    when(metricsCreator.createHistogramMetric(any(), any(), any(), any())).thenReturn(new HistogramMetrics() {

        @Override
        public Timer createTimer() {
            return super.createTimer();
        }

        @Override
        public void observe(double value) {
        }
    });
    ModuleDefineTesting telemetryModuleDefine = new ModuleDefineTesting();
    moduleManager.put(TelemetryModule.NAME, telemetryModuleDefine);
    telemetryModuleDefine.provider().registerServiceImplementation(MetricsCreator.class, metricsCreator);
    gRPCCleanup.register(InProcessServerBuilder.forName(serverName).directExecutor().addService(new RemoteServiceHandler(moduleManager)).build().start());
    RemoteServiceGrpc.RemoteServiceStub remoteServiceStub = RemoteServiceGrpc.newStub(gRPCCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build()));
    StreamObserver<RemoteMessage> streamObserver = remoteServiceStub.call(new StreamObserver<Empty>() {

        @Override
        public void onNext(Empty empty) {
        }

        @Override
        public void onError(Throwable throwable) {
        }

        @Override
        public void onCompleted() {
        }
    });
    RemoteMessage.Builder remoteMessage = RemoteMessage.newBuilder();
    remoteMessage.setNextWorkerName(testWorkerId);
    RemoteData.Builder remoteData = RemoteData.newBuilder();
    remoteData.addDataStrings("test1");
    remoteData.addDataStrings("test2");
    remoteData.addDataLongs(10);
    remoteData.addDataLongs(20);
    remoteMessage.setRemoteData(remoteData);
    streamObserver.onNext(remoteMessage.build());
    streamObserver.onCompleted();
}
Also used : RemoteMessage(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteMessage) CounterMetrics(org.apache.skywalking.oap.server.telemetry.api.CounterMetrics) WorkerInstancesService(org.apache.skywalking.oap.server.core.worker.WorkerInstancesService) MetricsCreator(org.apache.skywalking.oap.server.telemetry.api.MetricsCreator) RemoteData(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData) ModuleManagerTesting(org.apache.skywalking.oap.server.testing.module.ModuleManagerTesting) ModuleDefineTesting(org.apache.skywalking.oap.server.testing.module.ModuleDefineTesting) Empty(org.apache.skywalking.oap.server.core.remote.grpc.proto.Empty) RemoteServiceGrpc(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteServiceGrpc) HistogramMetrics(org.apache.skywalking.oap.server.telemetry.api.HistogramMetrics) Test(org.junit.Test)

Example 2 with ModuleDefineTesting

use of org.apache.skywalking.oap.server.testing.module.ModuleDefineTesting in project incubator-skywalking by apache.

the class GRPCRemoteClientRealServer method main.

public static void main(String[] args) throws ServerException, InterruptedException {
    ModuleManagerTesting moduleManager = new ModuleManagerTesting();
    ModuleDefineTesting moduleDefine = new ModuleDefineTesting();
    moduleManager.put(CoreModule.NAME, moduleDefine);
    GRPCServer server = new GRPCServer("localhost", 10000);
    server.initialize();
    server.addHandler(new RemoteServiceHandler(moduleManager));
    server.start();
    TimeUnit.MINUTES.sleep(10);
}
Also used : GRPCServer(org.apache.skywalking.oap.server.library.server.grpc.GRPCServer) RemoteServiceHandler(org.apache.skywalking.oap.server.core.remote.RemoteServiceHandler) ModuleManagerTesting(org.apache.skywalking.oap.server.testing.module.ModuleManagerTesting) ModuleDefineTesting(org.apache.skywalking.oap.server.testing.module.ModuleDefineTesting)

Example 3 with ModuleDefineTesting

use of org.apache.skywalking.oap.server.testing.module.ModuleDefineTesting in project incubator-skywalking by apache.

the class GRPCRemoteClientTestCase method testPush.

@Test
public void testPush() throws InterruptedException {
    MetricsCreator metricsCreator = mock(MetricsCreator.class);
    when(metricsCreator.createCounter(any(), any(), any(), any())).thenReturn(new CounterMetrics() {

        @Override
        public void inc() {
        }

        @Override
        public void inc(double value) {
        }
    });
    when(metricsCreator.createHistogramMetric(any(), any(), any(), any())).thenReturn(new HistogramMetrics() {

        @Override
        public Timer createTimer() {
            return super.createTimer();
        }

        @Override
        public void observe(double value) {
        }
    });
    ModuleDefineTesting telemetryModuleDefine = new ModuleDefineTesting();
    moduleManager.put(TelemetryModule.NAME, telemetryModuleDefine);
    telemetryModuleDefine.provider().registerServiceImplementation(MetricsCreator.class, metricsCreator);
    grpcServerRule.getServiceRegistry().addService(new RemoteServiceHandler(moduleManager));
    Address address = new Address("not-important", 11, false);
    GRPCRemoteClient remoteClient = spy(new GRPCRemoteClient(moduleManager, address, 1, 10, 10, null));
    remoteClient.connect();
    doReturn(grpcServerRule.getChannel()).when(remoteClient).getChannel();
    for (int i = 0; i < 12; i++) {
        remoteClient.push(nextWorkerName, new TestStreamData());
    }
    TimeUnit.SECONDS.sleep(2);
}
Also used : RemoteServiceHandler(org.apache.skywalking.oap.server.core.remote.RemoteServiceHandler) CounterMetrics(org.apache.skywalking.oap.server.telemetry.api.CounterMetrics) MetricsCreator(org.apache.skywalking.oap.server.telemetry.api.MetricsCreator) HistogramMetrics(org.apache.skywalking.oap.server.telemetry.api.HistogramMetrics) ModuleDefineTesting(org.apache.skywalking.oap.server.testing.module.ModuleDefineTesting) Test(org.junit.Test)

Example 4 with ModuleDefineTesting

use of org.apache.skywalking.oap.server.testing.module.ModuleDefineTesting in project skywalking by apache.

the class RemoteClientManagerTestCase method setup.

@Before
public void setup() {
    ModuleManagerTesting moduleManager = new ModuleManagerTesting();
    ModuleDefineTesting clusterModuleDefine = new ModuleDefineTesting();
    moduleManager.put(ClusterModule.NAME, clusterModuleDefine);
    ModuleDefineTesting coreModuleDefine = new ModuleDefineTesting();
    moduleManager.put(CoreModule.NAME, coreModuleDefine);
    this.clusterNodesQuery = mock(ClusterNodesQuery.class);
    clusterModuleDefine.provider().registerServiceImplementation(ClusterNodesQuery.class, clusterNodesQuery);
    MetricsCreator metricsCreator = mock(MetricsCreator.class);
    when(metricsCreator.createGauge(any(), any(), any(), any())).thenReturn(new GaugeMetrics() {

        @Override
        public void inc() {
        }

        @Override
        public void inc(double value) {
        }

        @Override
        public void dec() {
        }

        @Override
        public void dec(double value) {
        }

        @Override
        public void setValue(double value) {
        }

        @Override
        public double getValue() {
            return 0;
        }
    });
    ModuleDefineTesting telemetryModuleDefine = new ModuleDefineTesting();
    moduleManager.put(TelemetryModule.NAME, telemetryModuleDefine);
    telemetryModuleDefine.provider().registerServiceImplementation(MetricsCreator.class, metricsCreator);
    this.clientManager = spy(new RemoteClientManager(moduleManager, 10));
}
Also used : ClusterNodesQuery(org.apache.skywalking.oap.server.core.cluster.ClusterNodesQuery) GaugeMetrics(org.apache.skywalking.oap.server.telemetry.api.GaugeMetrics) MetricsCreator(org.apache.skywalking.oap.server.telemetry.api.MetricsCreator) ModuleManagerTesting(org.apache.skywalking.oap.server.testing.module.ModuleManagerTesting) ModuleDefineTesting(org.apache.skywalking.oap.server.testing.module.ModuleDefineTesting) Before(org.junit.Before)

Example 5 with ModuleDefineTesting

use of org.apache.skywalking.oap.server.testing.module.ModuleDefineTesting in project skywalking by apache.

the class RemoteServiceHandlerTestCase method callTest.

@Test
public void callTest() throws DuplicateProviderException, ProviderNotFoundException, IOException {
    final String testWorkerId = "mock-worker";
    ModuleManagerTesting moduleManager = new ModuleManagerTesting();
    ModuleDefineTesting moduleDefine = new ModuleDefineTesting();
    moduleManager.put(CoreModule.NAME, moduleDefine);
    WorkerInstancesService workerInstancesService = new WorkerInstancesService();
    moduleDefine.provider().registerServiceImplementation(IWorkerInstanceGetter.class, workerInstancesService);
    moduleDefine.provider().registerServiceImplementation(IWorkerInstanceSetter.class, workerInstancesService);
    TestWorker worker = new TestWorker(moduleManager);
    workerInstancesService.put(testWorkerId, worker, TestRemoteData.class);
    String serverName = InProcessServerBuilder.generateName();
    MetricsCreator metricsCreator = mock(MetricsCreator.class);
    when(metricsCreator.createCounter(any(), any(), any(), any())).thenReturn(new CounterMetrics() {

        @Override
        public void inc() {
        }

        @Override
        public void inc(double value) {
        }
    });
    when(metricsCreator.createHistogramMetric(any(), any(), any(), any())).thenReturn(new HistogramMetrics() {

        @Override
        public Timer createTimer() {
            return super.createTimer();
        }

        @Override
        public void observe(double value) {
        }
    });
    ModuleDefineTesting telemetryModuleDefine = new ModuleDefineTesting();
    moduleManager.put(TelemetryModule.NAME, telemetryModuleDefine);
    telemetryModuleDefine.provider().registerServiceImplementation(MetricsCreator.class, metricsCreator);
    gRPCCleanup.register(InProcessServerBuilder.forName(serverName).directExecutor().addService(new RemoteServiceHandler(moduleManager)).build().start());
    RemoteServiceGrpc.RemoteServiceStub remoteServiceStub = RemoteServiceGrpc.newStub(gRPCCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build()));
    StreamObserver<RemoteMessage> streamObserver = remoteServiceStub.call(new StreamObserver<Empty>() {

        @Override
        public void onNext(Empty empty) {
        }

        @Override
        public void onError(Throwable throwable) {
        }

        @Override
        public void onCompleted() {
        }
    });
    RemoteMessage.Builder remoteMessage = RemoteMessage.newBuilder();
    remoteMessage.setNextWorkerName(testWorkerId);
    RemoteData.Builder remoteData = RemoteData.newBuilder();
    remoteData.addDataStrings("test1");
    remoteData.addDataStrings("test2");
    remoteData.addDataLongs(10);
    remoteData.addDataLongs(20);
    remoteMessage.setRemoteData(remoteData);
    streamObserver.onNext(remoteMessage.build());
    streamObserver.onCompleted();
}
Also used : RemoteMessage(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteMessage) CounterMetrics(org.apache.skywalking.oap.server.telemetry.api.CounterMetrics) WorkerInstancesService(org.apache.skywalking.oap.server.core.worker.WorkerInstancesService) MetricsCreator(org.apache.skywalking.oap.server.telemetry.api.MetricsCreator) RemoteData(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData) ModuleManagerTesting(org.apache.skywalking.oap.server.testing.module.ModuleManagerTesting) ModuleDefineTesting(org.apache.skywalking.oap.server.testing.module.ModuleDefineTesting) Empty(org.apache.skywalking.oap.server.core.remote.grpc.proto.Empty) RemoteServiceGrpc(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteServiceGrpc) HistogramMetrics(org.apache.skywalking.oap.server.telemetry.api.HistogramMetrics) Test(org.junit.Test)

Aggregations

ModuleDefineTesting (org.apache.skywalking.oap.server.testing.module.ModuleDefineTesting)14 ModuleManagerTesting (org.apache.skywalking.oap.server.testing.module.ModuleManagerTesting)12 MetricsCreator (org.apache.skywalking.oap.server.telemetry.api.MetricsCreator)8 CounterMetrics (org.apache.skywalking.oap.server.telemetry.api.CounterMetrics)6 RemoteServiceHandler (org.apache.skywalking.oap.server.core.remote.RemoteServiceHandler)4 WorkerInstancesService (org.apache.skywalking.oap.server.core.worker.WorkerInstancesService)4 HistogramMetrics (org.apache.skywalking.oap.server.telemetry.api.HistogramMetrics)4 Before (org.junit.Before)4 Test (org.junit.Test)4 CoreModuleConfig (org.apache.skywalking.oap.server.core.CoreModuleConfig)2 ClusterNodesQuery (org.apache.skywalking.oap.server.core.cluster.ClusterNodesQuery)2 ConfigService (org.apache.skywalking.oap.server.core.config.ConfigService)2 Empty (org.apache.skywalking.oap.server.core.remote.grpc.proto.Empty)2 RemoteData (org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData)2 RemoteMessage (org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteMessage)2 RemoteServiceGrpc (org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteServiceGrpc)2 GRPCServer (org.apache.skywalking.oap.server.library.server.grpc.GRPCServer)2 GaugeMetrics (org.apache.skywalking.oap.server.telemetry.api.GaugeMetrics)2 MetricsCreatorNoop (org.apache.skywalking.oap.server.telemetry.none.MetricsCreatorNoop)2