Search in sources :

Example 1 with Void

use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Void in project sonarlint-core by SonarSource.

the class StandaloneDaemonTest method shutdown.

@After
public void shutdown() throws Exception {
    ClientCall<Void, Void> call = channel.newCall(StandaloneSonarLintGrpc.METHOD_SHUTDOWN, CallOptions.DEFAULT);
    call.start(new Listener<Void>() {
    }, new Metadata());
    call.sendMessage(Void.newBuilder().build());
    call.halfClose();
    call.request(1);
    channel.shutdownNow();
    channel.awaitTermination(2, TimeUnit.SECONDS);
}
Also used : Metadata(io.grpc.Metadata) Void(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Void) After(org.junit.After)

Example 2 with Void

use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Void in project sonarlint-core by SonarSource.

the class StandaloneDaemonTest method test.

@Test
public void test() throws InterruptedException, IOException {
    LogCollector logs = new LogCollector();
    StandaloneSonarLintBlockingStub sonarlint = StandaloneSonarLintGrpc.newBlockingStub(channel);
    AnalysisReq analysisConfig = createAnalysisConfig("sample-javascript");
    long start = System.currentTimeMillis();
    ClientCall<Void, LogEvent> call = getLogs(logs, channel);
    try {
        for (int i = 0; i < 10; i++) {
            System.out.println("ITERATION: " + i);
            Iterator<Issue> issues = sonarlint.analyze(analysisConfig);
            assertThat(issues).hasSize(1);
            // Give some time for logs to come
            Thread.sleep(500);
            List<String> logsLines = logs.getLogsAndClear();
            // To be sure logs are not flooded by low level logs
            assertThat(logsLines.size()).isLessThan(100);
            assertThat(logsLines).contains("1 files indexed");
        }
    } finally {
        call.cancel("no more logs needed", null);
    }
    System.out.println("TIME " + (System.currentTimeMillis() - start));
}
Also used : Issue(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue) LogEvent(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.LogEvent) AnalysisReq(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.AnalysisReq) StandaloneSonarLintBlockingStub(org.sonarsource.sonarlint.daemon.proto.StandaloneSonarLintGrpc.StandaloneSonarLintBlockingStub) Void(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Void) Test(org.junit.Test)

Example 3 with Void

use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Void in project sonarlint-core by SonarSource.

the class StandaloneDaemonTest method getLogs.

private ClientCall<Void, LogEvent> getLogs(LogCollector collector, Channel channel) {
    ClientCall<Void, LogEvent> call = channel.newCall(StandaloneSonarLintGrpc.METHOD_STREAM_LOGS, CallOptions.DEFAULT);
    call.start(collector, new Metadata());
    call.sendMessage(Void.newBuilder().build());
    call.halfClose();
    call.request(Integer.MAX_VALUE);
    return call;
}
Also used : LogEvent(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.LogEvent) Metadata(io.grpc.Metadata) Void(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Void)

Example 4 with Void

use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Void in project sonarlint-core by SonarSource.

the class ConnectedDaemonTest method testNormal.

@Test
public void testNormal() throws InterruptedException, IOException {
    daemon.run();
    daemon.waitReady();
    ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8050).usePlaintext(true).build();
    LogCollector logs = new LogCollector();
    ConnectedSonarLintBlockingStub sonarlint = ConnectedSonarLintGrpc.newBlockingStub(channel);
    // REGISTER
    sonarlint.start(createConnectedConfig());
    // STATE
    assertThat(sonarlint.getState(Void.newBuilder().build()).getState()).isEqualTo(StorageState.State.NEVER_UPDATED);
    // UPDATE GLOBAL
    ServerConfig serverConfig = ServerConfig.newBuilder().setHostUrl(ORCHESTRATOR.getServer().getUrl()).setCredentials(Credentials.newBuilder().setLogin(SONARLINT_USER).setPassword(SONARLINT_PWD).build()).build();
    sonarlint.update(serverConfig);
    // STATE
    assertThat(sonarlint.getState(Void.newBuilder().build()).getState()).isEqualTo(StorageState.State.UPDATED);
    // UPDATE MODULE
    ModuleUpdateReq moduleUpdate = ModuleUpdateReq.newBuilder().setModuleKey(PROJECT_KEY_JAVA).setServerConfig(serverConfig).build();
    sonarlint.updateModule(moduleUpdate);
    // ANALYSIS
    ClientCall<Void, LogEvent> call = getLogs(logs, channel);
    Iterator<Issue> issues = sonarlint.analyze(createAnalysisConfig(PROJECT_KEY_JAVA));
    assertThat(issues).hasSize(3);
    // assertThat(logs.getLogsAndClear()).contains("2 files indexed");
    call.cancel(null, null);
    channel.shutdownNow();
    channel.awaitTermination(2, TimeUnit.SECONDS);
}
Also used : ServerConfig(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.ServerConfig) ConnectedSonarLintBlockingStub(org.sonarsource.sonarlint.daemon.proto.ConnectedSonarLintGrpc.ConnectedSonarLintBlockingStub) Issue(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue) LogEvent(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.LogEvent) ModuleUpdateReq(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.ModuleUpdateReq) ManagedChannel(io.grpc.ManagedChannel) Void(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Void) Test(org.junit.Test)

Example 5 with Void

use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Void in project sonarlint-core by SonarSource.

the class ConnectedDaemonTest method getLogs.

private ClientCall<Void, LogEvent> getLogs(LogCollector collector, Channel channel) {
    ClientCall<Void, LogEvent> call = channel.newCall(StandaloneSonarLintGrpc.METHOD_STREAM_LOGS, CallOptions.DEFAULT);
    call.start(collector, new Metadata());
    call.sendMessage(Void.newBuilder().build());
    call.halfClose();
    call.request(Integer.MAX_VALUE);
    return call;
}
Also used : LogEvent(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.LogEvent) Metadata(io.grpc.Metadata) Void(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Void)

Aggregations

Void (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Void)5 LogEvent (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.LogEvent)4 Metadata (io.grpc.Metadata)3 Test (org.junit.Test)2 Issue (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue)2 ManagedChannel (io.grpc.ManagedChannel)1 After (org.junit.After)1 ConnectedSonarLintBlockingStub (org.sonarsource.sonarlint.daemon.proto.ConnectedSonarLintGrpc.ConnectedSonarLintBlockingStub)1 AnalysisReq (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.AnalysisReq)1 ModuleUpdateReq (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.ModuleUpdateReq)1 ServerConfig (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.ServerConfig)1 StandaloneSonarLintBlockingStub (org.sonarsource.sonarlint.daemon.proto.StandaloneSonarLintGrpc.StandaloneSonarLintBlockingStub)1