use of com.yahoo.athenz.common.metrics.Metric in project athenz by yahoo.
the class MetricsTest method testMetricInterface.
@Test
public void testMetricInterface() {
Metric metric = new Metric() {
@Override
public void increment(String metric) {
}
@Override
public void increment(String metric, String requestDomainName) {
}
@Override
public void increment(String metric, String requestDomainName, int count) {
}
@Override
public void increment(String metric, String requestDomainName, String principalDomainName, String httpMethod, int httpStatus, String apiName) {
}
@Override
public Object startTiming(String metric, String requestDomainName) {
return null;
}
@Override
public void stopTiming(Object timerMetric) {
}
@Override
public void stopTiming(Object timerMetric, String requestDomainName, String principalDomainName, String httpMethod, int httpStatus, String apiName) {
}
@Override
public void flush() {
}
@Override
public void quit() {
}
};
metric.increment("metric1");
metric.increment("metric1", "athenz", 3);
metric.increment("metric1", "athenz", "sports");
metric.increment("metric1", "athenz", "sports", 3);
metric.increment("apiRquestsMetric", "athenz", "sports", "POST", 200, "caller");
String[] attributes = new String[] { "tag1", "value1", "tag2", "value2", "tag3", "value3" };
metric.increment("metric1", attributes);
assertNull(metric.startTiming("metric1", "athenz", "sports"));
assertNull(metric.startTiming("apiRquestsMetric", "athenz", "sports", "POST", "caller"));
metric.stopTiming("metric1", "athenz", "sports");
metric.stopTiming("apiRquestsMetric", "athenz", "sports", "POST", 200, "caller");
metric.flush();
metric.quit();
}
use of com.yahoo.athenz.common.metrics.Metric in project athenz by yahoo.
the class JettyConnectionLoggerTest method testStartStopConnectionFailedHandshake.
@Test
public void testStartStopConnectionFailedHandshake() throws Exception {
// First start 2 connections
ConnectionLog connectionLog = Mockito.mock(ConnectionLog.class);
Metric metric = Mockito.mock(Metric.class);
JettyConnectionLogger jettyConnectionLogger = new JettyConnectionLogger(connectionLog, metric);
MockedConnection failedMockedConnection = getMockConnection();
SslConnection mockConnection2 = failedMockedConnection.sslConnection;
// Now simulate handshake failure for mockConnection2
SslHandshakeListener.Event event = Mockito.mock(SslHandshakeListener.Event.class);
when(event.getSSLEngine()).thenReturn(failedMockedConnection.sslEngine);
SSLHandshakeException sslHandshakeException = new SSLHandshakeException("no cipher suites in common");
ArgumentCaptor<ConnectionLogEntry> connectionLogEntryArgumentCaptor = ArgumentCaptor.forClass(ConnectionLogEntry.class);
ArgumentCaptor<String[]> metricArgumentCaptor = ArgumentCaptor.forClass(String[].class);
when(mockConnection2.getEndPoint().isOpen()).thenReturn(false);
jettyConnectionLogger.handshakeFailed(event, sslHandshakeException);
Mockito.verify(connectionLog, Mockito.times(1)).log(connectionLogEntryArgumentCaptor.capture());
Mockito.verify(metric, Mockito.times(1)).increment(Mockito.eq(CONNECTION_LOGGER_METRIC_DEFAULT_NAME), metricArgumentCaptor.capture());
assertEquals("no cipher suites in common", connectionLogEntryArgumentCaptor.getValue().sslHandshakeFailureMessage().get());
assertFalse(connectionLogEntryArgumentCaptor.getValue().sslHandshakeFailureCause().isPresent());
List<String[]> allMetricValues = metricArgumentCaptor.getAllValues();
assertEquals(2, allMetricValues.size());
assertEquals("failureType", allMetricValues.get(0));
assertEquals("INCOMPATIBLE_CLIENT_CIPHER_SUITES", allMetricValues.get(1));
}
use of com.yahoo.athenz.common.metrics.Metric in project athenz by yahoo.
the class JettyConnectionLoggerTest method testFailedHandshakeInnerCause.
@Test
public void testFailedHandshakeInnerCause() throws Exception {
// First start q connection
ConnectionLog connectionLog = Mockito.mock(ConnectionLog.class);
Metric metric = Mockito.mock(Metric.class);
JettyConnectionLogger jettyConnectionLogger = new JettyConnectionLogger(connectionLog, metric);
MockedConnection failedMockedConnection = getMockConnection();
SslConnection mockConnection = failedMockedConnection.sslConnection;
// Now simulate handshake failure for mockConnection
SslHandshakeListener.Event event = Mockito.mock(SslHandshakeListener.Event.class);
when(event.getSSLEngine()).thenReturn(failedMockedConnection.sslEngine);
SSLHandshakeException sslHandshakeException = new SSLHandshakeException(GENERAL_SSL_ERROR);
SSLHandshakeException innerCause1 = new SSLHandshakeException(GENERAL_SSL_ERROR);
SSLHandshakeException innerCause2 = new SSLHandshakeException(GENERAL_SSL_ERROR);
SSLHandshakeException innerCause3 = new SSLHandshakeException("Last cause (most specific reason)");
innerCause2.initCause(innerCause3);
innerCause1.initCause(innerCause2);
sslHandshakeException.initCause(innerCause1);
ArgumentCaptor<ConnectionLogEntry> connectionLogEntryArgumentCaptor = ArgumentCaptor.forClass(ConnectionLogEntry.class);
when(mockConnection.getEndPoint().isOpen()).thenReturn(false);
jettyConnectionLogger.handshakeFailed(event, sslHandshakeException);
Mockito.verify(connectionLog, Mockito.times(1)).log(connectionLogEntryArgumentCaptor.capture());
assertEquals(GENERAL_SSL_ERROR, connectionLogEntryArgumentCaptor.getValue().sslHandshakeFailureMessage().get());
assertEquals("Last cause (most specific reason)", connectionLogEntryArgumentCaptor.getValue().sslHandshakeFailureCause().get());
}
use of com.yahoo.athenz.common.metrics.Metric in project athenz by yahoo.
the class JettyConnectionLoggerFactory method create.
public JettyConnectionLogger create() {
ConnectionLog connectionLog = getSslConnectionLog();
Metric metric = getMetric();
return new JettyConnectionLogger(connectionLog, metric);
}
use of com.yahoo.athenz.common.metrics.Metric in project athenz by yahoo.
the class RsrcCtxWrapperTest method testAuthorize.
@Test
public void testAuthorize() {
HttpServletRequest reqMock = Mockito.mock(HttpServletRequest.class);
HttpServletResponse resMock = Mockito.mock(HttpServletResponse.class);
AuthorityList authListMock = new AuthorityList();
Authorizer authorizerMock = Mockito.mock(Authorizer.class);
Authority authMock = Mockito.mock(Authority.class);
Metric metricMock = Mockito.mock(Metric.class);
Object timerMetricMock = Mockito.mock(Object.class);
Principal prin = Mockito.mock(Principal.class);
Mockito.when(authMock.getHeader()).thenReturn("testheader");
Mockito.when(reqMock.getHeader("testheader")).thenReturn("testcred");
Mockito.when(authMock.getCredSource()).thenReturn(com.yahoo.athenz.auth.Authority.CredSource.HEADER);
Mockito.when(authMock.authenticate(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(prin);
Mockito.when(reqMock.getRemoteAddr()).thenReturn("1.1.1.1");
Mockito.when(reqMock.getMethod()).thenReturn("POST");
authListMock.add(authMock);
// force true access right
Mockito.when(authorizerMock.access(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(true);
RsrcCtxWrapper wrapper = new RsrcCtxWrapper(reqMock, resMock, authListMock, false, authorizerMock, metricMock, timerMetricMock, "apiName");
wrapper.authorize("add-domain", "test", "test");
// after authorize success, principal should be set
assertEquals(wrapper.principal(), prin);
}
Aggregations