Search in sources :

Example 1 with InsightsStatusData

use of com.datastax.dse.driver.internal.core.insights.schema.InsightsStatusData in project java-driver by datastax.

the class InsightsClientTest method should_construct_json_event_status_message.

@Test
public void should_construct_json_event_status_message() throws IOException {
    // given
    InsightsClient insightsClient = new InsightsClient(mockDefaultDriverContext(), MOCK_TIME_SUPPLIER, INSIGHTS_CONFIGURATION, null, null, null, null, null, EMPTY_STACK_TRACE);
    // when
    String statusMessage = insightsClient.createStatusMessage();
    // then
    Insight<InsightsStatusData> insight = new ObjectMapper().readValue(statusMessage, new TypeReference<Insight<InsightsStatusData>>() {
    });
    assertThat(insight.getMetadata()).isEqualTo(new InsightMetadata("driver.status", 1L, ImmutableMap.of("language", "java"), InsightType.EVENT, "v1"));
    InsightsStatusData insightData = insight.getInsightData();
    assertThat(insightData.getClientId()).isEqualTo("client-id");
    assertThat(insightData.getSessionId()).isNotNull();
    assertThat(insightData.getControlConnection()).isEqualTo("127.0.0.1:10");
    assertThat(insightData.getConnectedNodes()).isEqualTo(ImmutableMap.of("127.0.0.1:10", new SessionStateForNode(1, 10), "127.0.0.1:20", new SessionStateForNode(2, 20)));
}
Also used : InsightsStatusData(com.datastax.dse.driver.internal.core.insights.schema.InsightsStatusData) SessionStateForNode(com.datastax.dse.driver.internal.core.insights.schema.SessionStateForNode) Insight(com.datastax.dse.driver.internal.core.insights.schema.Insight) InsightMetadata(com.datastax.dse.driver.internal.core.insights.schema.InsightMetadata) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with InsightsStatusData

use of com.datastax.dse.driver.internal.core.insights.schema.InsightsStatusData in project java-driver by datastax.

the class InsightsClient method createStatusMessage.

@VisibleForTesting
String createStatusMessage() {
    InsightMetadata insightMetadata = createMetadata(STATUS_MESSAGE_NAME, STATUS_VERSION_1_ID);
    InsightsStatusData data = createStatusData();
    try {
        return OBJECT_MAPPER.writeValueAsString(new Insight<>(insightMetadata, data));
    } catch (JsonProcessingException e) {
        throw new InsightEventFormatException("Problem when creating: " + STATUS_MESSAGE_NAME, e);
    }
}
Also used : InsightEventFormatException(com.datastax.dse.driver.internal.core.insights.exceptions.InsightEventFormatException) InsightsStatusData(com.datastax.dse.driver.internal.core.insights.schema.InsightsStatusData) InsightMetadata(com.datastax.dse.driver.internal.core.insights.schema.InsightMetadata) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) VisibleForTesting(com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting)

Aggregations

InsightMetadata (com.datastax.dse.driver.internal.core.insights.schema.InsightMetadata)2 InsightsStatusData (com.datastax.dse.driver.internal.core.insights.schema.InsightsStatusData)2 InsightEventFormatException (com.datastax.dse.driver.internal.core.insights.exceptions.InsightEventFormatException)1 Insight (com.datastax.dse.driver.internal.core.insights.schema.Insight)1 SessionStateForNode (com.datastax.dse.driver.internal.core.insights.schema.SessionStateForNode)1 VisibleForTesting (com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Test (org.junit.Test)1