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));
}
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;
}
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);
}
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;
}
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");
}
Aggregations