Search in sources :

Example 1 with PerformanceMeasures

use of io.joynr.messaging.info.PerformanceMeasures in project joynr by bmwcarit.

the class MonitoringServiceImplTest method testUpdatePerformanceMeasures.

@Test
public void testUpdatePerformanceMeasures() {
    Mockito.when(bpDirectoryMock.containsBounceProxy("X.Y")).thenReturn(true);
    Mockito.when(bpDirectoryMock.getBounceProxy("X.Y")).thenReturn(new BounceProxyRecord(new ControlledBounceProxyInformation("X.Y", null)));
    PerformanceMeasures performanceMeasures = new PerformanceMeasures();
    performanceMeasures.addMeasure(Key.ACTIVE_LONGPOLL_COUNT, 5);
    monitoringService.updatePerformanceMeasures("X.Y", performanceMeasures);
    ArgumentCaptor<BounceProxyRecord> argument = ArgumentCaptor.forClass(BounceProxyRecord.class);
    Mockito.verify(bpDirectoryMock).updateBounceProxy(argument.capture());
    Assert.assertEquals("X.Y", argument.getValue().getBounceProxyId());
    Assert.assertEquals(5, argument.getValue().getPerformanceMeasures().getMeasure(Key.ACTIVE_LONGPOLL_COUNT));
    Assert.assertEquals(BounceProxyStatus.ACTIVE, argument.getValue().getStatus());
}
Also used : BounceProxyRecord(io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord) PerformanceMeasures(io.joynr.messaging.info.PerformanceMeasures) ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) Test(org.junit.Test)

Example 2 with PerformanceMeasures

use of io.joynr.messaging.info.PerformanceMeasures in project joynr by bmwcarit.

the class InMemoryBounceProxyDirectoryTest method testUpdateBounceProxyPerformance.

@Test
public void testUpdateBounceProxyPerformance() {
    Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(100l);
    directory.addBounceProxy(new ControlledBounceProxyInformation("X.Y", URI.create("http://www.location.de")));
    BounceProxyRecord bounceProxyRecord = directory.getBounceProxy("X.Y");
    PerformanceMeasures performanceMeasures = new PerformanceMeasures();
    performanceMeasures.addMeasure(Key.ACTIVE_LONGPOLL_COUNT, 5);
    performanceMeasures.addMeasure(Key.ASSIGNED_CHANNELS_COUNT, 13);
    bounceProxyRecord.setPerformanceMeasures(performanceMeasures);
    Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(200l);
    directory.updateBounceProxy(bounceProxyRecord);
    PerformanceMeasures result = directory.getBounceProxy("X.Y").getPerformanceMeasures();
    assertEquals(5, result.getMeasure(Key.ACTIVE_LONGPOLL_COUNT));
    assertEquals(13, result.getMeasure(Key.ASSIGNED_CHANNELS_COUNT));
    assertEquals(200, directory.getBounceProxy("X.Y").getFreshness().getTime());
}
Also used : PerformanceMeasures(io.joynr.messaging.info.PerformanceMeasures) ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) Test(org.junit.Test)

Example 3 with PerformanceMeasures

use of io.joynr.messaging.info.PerformanceMeasures in project joynr by bmwcarit.

the class MonitoringServiceRestAdapter method reportPerformance.

/**
 * Refreshes the performance measures of a bounce proxy instance, e.g.
 * active long polls.
 *
 * @param bpId
 *            the identifier of the bounce proxy
 * @param performanceMap
 *            key-value pairs of performance measures
 * @return empty response
 */
@POST
@Path("/{bpid: ([A-Z,a-z,0-9,_,\\-]+)(\\.)([A-Z,a-z,0-9,_,\\-]+)}/performance")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.TEXT_PLAIN })
public Response reportPerformance(@PathParam("bpid") String bpId, Map<String, Integer> performanceMap) {
    if (!monitoringService.isRegistered(bpId)) {
        throw new JoynrHttpException(Status.BAD_REQUEST, JoynrBounceProxyControlErrorCode.BOUNCEPROXY_UNKNOWN, "bounce proxy '" + bpId + "'");
    }
    PerformanceMeasures performanceMeasures = new PerformanceMeasures();
    performanceMeasures.addMeasures(performanceMap);
    monitoringService.updatePerformanceMeasures(bpId, performanceMeasures);
    return Response.noContent().build();
}
Also used : JoynrHttpException(io.joynr.communications.exceptions.JoynrHttpException) PerformanceMeasures(io.joynr.messaging.info.PerformanceMeasures) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 4 with PerformanceMeasures

use of io.joynr.messaging.info.PerformanceMeasures in project joynr by bmwcarit.

the class BounceProxyInstanceLifeCycleTest method testReportPerformanceWithUnknownMeasureName.

@Test
public void testReportPerformanceWithUnknownMeasureName() {
    Mockito.when(mock.isRegistered("0.0")).thenReturn(true);
    // 
    Response response = // 
    given().when().contentType(ContentType.JSON).body("{ \"active\" : 5 }").post(serverUrl + "0.0/performance");
    assertEquals(204, /* No Content */
    response.getStatusCode());
    Mockito.verify(mock).updatePerformanceMeasures("0.0", new PerformanceMeasures());
    Mockito.verify(mock).isRegistered("0.0");
    Mockito.verifyNoMoreInteractions(mock);
}
Also used : PerformanceMeasures(io.joynr.messaging.info.PerformanceMeasures) Test(org.junit.Test)

Aggregations

PerformanceMeasures (io.joynr.messaging.info.PerformanceMeasures)4 Test (org.junit.Test)3 ControlledBounceProxyInformation (io.joynr.messaging.info.ControlledBounceProxyInformation)2 JoynrHttpException (io.joynr.communications.exceptions.JoynrHttpException)1 BounceProxyRecord (io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1