Search in sources :

Example 1 with ConnectedSonarLintBlockingStub

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

use of org.sonarsource.sonarlint.daemon.proto.ConnectedSonarLintGrpc.ConnectedSonarLintBlockingStub in project sonarlint-core by SonarSource.

the class ConnectedDaemonTest method testError.

@Test
public void testError() throws IOException {
    daemon.run();
    daemon.waitReady();
    ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8050).usePlaintext(true).build();
    ConnectedSonarLintBlockingStub sonarlint = ConnectedSonarLintGrpc.newBlockingStub(channel);
    sonarlint.start(createConnectedConfig());
    // Analyze without update -> error
    Iterator<Issue> analyze = sonarlint.analyze(createAnalysisConfig(PROJECT_KEY_JAVA));
    exception.expectMessage("Please update server 'storage'");
    exception.expect(StatusRuntimeException.class);
    analyze.hasNext();
    sonarlint.shutdown(null);
}
Also used : ConnectedSonarLintBlockingStub(org.sonarsource.sonarlint.daemon.proto.ConnectedSonarLintGrpc.ConnectedSonarLintBlockingStub) Issue(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue) ManagedChannel(io.grpc.ManagedChannel) Test(org.junit.Test)

Example 3 with ConnectedSonarLintBlockingStub

use of org.sonarsource.sonarlint.daemon.proto.ConnectedSonarLintGrpc.ConnectedSonarLintBlockingStub in project sonarlint-core by SonarSource.

the class ConnectedDaemonTest method testPort.

@Test
public void testPort() throws IOException {
    daemon.run("--port", "8051");
    daemon.waitReady();
    ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8051).usePlaintext(true).build();
    ConnectedSonarLintBlockingStub sonarlint = ConnectedSonarLintGrpc.newBlockingStub(channel);
    sonarlint.start(createConnectedConfig());
}
Also used : ConnectedSonarLintBlockingStub(org.sonarsource.sonarlint.daemon.proto.ConnectedSonarLintGrpc.ConnectedSonarLintBlockingStub) ManagedChannel(io.grpc.ManagedChannel) Test(org.junit.Test)

Aggregations

ManagedChannel (io.grpc.ManagedChannel)3 Test (org.junit.Test)3 ConnectedSonarLintBlockingStub (org.sonarsource.sonarlint.daemon.proto.ConnectedSonarLintGrpc.ConnectedSonarLintBlockingStub)3 Issue (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue)2 LogEvent (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.LogEvent)1 ModuleUpdateReq (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.ModuleUpdateReq)1 ServerConfig (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.ServerConfig)1 Void (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Void)1