Search in sources :

Example 1 with LogEvent

use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.LogEvent 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 2 with LogEvent

use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.LogEvent 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 3 with LogEvent

use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.LogEvent 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 4 with LogEvent

use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.LogEvent 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)

Example 5 with LogEvent

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

the class ProxyLogOutputTest method testProxyLog.

@Test
public void testProxyLog() {
    ProxyLogOutput log = new ProxyLogOutput(mock(Daemon.class));
    log.log("log msg", Level.INFO);
    log.setObserver(observer);
    log.log("msg", Level.DEBUG);
    ArgumentCaptor<LogEvent> argument = ArgumentCaptor.forClass(LogEvent.class);
    verify(observer).onNext(argument.capture());
    LogEvent event = argument.getValue();
    assertThat(event.getIsDebug()).isTrue();
    assertThat(event.getLevel()).isEqualTo("DEBUG");
    assertThat(event.getLog()).isEqualTo("msg");
}
Also used : Daemon(org.sonarlint.daemon.Daemon) LogEvent(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.LogEvent) Test(org.junit.Test)

Aggregations

LogEvent (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.LogEvent)5 Void (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Void)4 Test (org.junit.Test)3 Metadata (io.grpc.Metadata)2 Issue (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue)2 ManagedChannel (io.grpc.ManagedChannel)1 Daemon (org.sonarlint.daemon.Daemon)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