use of com.amazonaws.services.logs.AWSLogsClient in project cloudwatch-logback-appender by j256.
the class Ec2InstanceNameConverterTest method testInstanceNameUnknown.
@Test(timeout = 10000)
public void testInstanceNameUnknown() throws InterruptedException {
Ec2InstanceNameConverter.setInstanceName(null);
AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
appender.setAwsLogsClient(awsLogClient);
String prefix = "logstream-";
appender.setLogStream(prefix + "%instanceName");
final String expectedLogStream = prefix + "unknown";
PatternLayout layout = new PatternLayout();
layout.setPattern("%msg");
layout.setContext(LOGGER_CONTEXT);
layout.start();
appender.setLayout(layout);
LoggingEvent event = new LoggingEvent();
event.setTimeStamp(System.currentTimeMillis());
event.setLoggerName("name");
event.setLevel(Level.DEBUG);
event.setMessage("message");
final PutLogEventsResult result = new PutLogEventsResult();
result.setNextSequenceToken("ewopjfewfj");
expect(awsLogClient.putLogEvents(isA(PutLogEventsRequest.class))).andAnswer(new IAnswer<PutLogEventsResult>() {
@Override
public PutLogEventsResult answer() {
PutLogEventsRequest request = (PutLogEventsRequest) getCurrentArguments()[0];
assertEquals(LOG_GROUP, request.getLogGroupName());
assertEquals(expectedLogStream, request.getLogStreamName());
return result;
}
});
awsLogClient.shutdown();
// =====================================
replay(awsLogClient);
appender.start();
appender.append(event);
while (appender.getEventsWrittenCount() < 1) {
Thread.sleep(10);
}
appender.stop();
verify(awsLogClient);
}
use of com.amazonaws.services.logs.AWSLogsClient in project cloudwatch-logback-appender by j256.
the class HostNameConverterTest method testStuff.
@Test(timeout = 5000)
public void testStuff() throws InterruptedException, UnknownHostException {
String hostAddr = InetAddress.getLocalHost().getHostName();
AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
appender.setAwsLogsClient(awsLogClient);
String prefix = "logstream-";
appender.setLogStream(prefix + "%hostName");
final String expectedLogStream = prefix + hostAddr;
PatternLayout layout = new PatternLayout();
layout.setPattern("%msg");
layout.setContext(LOGGER_CONTEXT);
layout.start();
appender.setLayout(layout);
LoggingEvent event = new LoggingEvent();
event.setTimeStamp(System.currentTimeMillis());
event.setLoggerName("name");
event.setLevel(Level.DEBUG);
event.setMessage("message");
final PutLogEventsResult result = new PutLogEventsResult();
result.setNextSequenceToken("ewopjfewfj");
expect(awsLogClient.putLogEvents(isA(PutLogEventsRequest.class))).andAnswer(new IAnswer<PutLogEventsResult>() {
@Override
public PutLogEventsResult answer() {
PutLogEventsRequest request = (PutLogEventsRequest) getCurrentArguments()[0];
assertEquals(LOG_GROUP, request.getLogGroupName());
assertEquals(expectedLogStream, request.getLogStreamName());
return result;
}
});
awsLogClient.shutdown();
// =====================================
replay(awsLogClient);
appender.start();
appender.append(event);
while (appender.getEventsWrittenCount() < 1) {
Thread.sleep(10);
}
appender.stop();
verify(awsLogClient);
}
use of com.amazonaws.services.logs.AWSLogsClient in project cloudwatch-logback-appender by j256.
the class SystemEnvironConverterTest method testUnknownEnvNameSpecified.
@Test(timeout = 5000)
public void testUnknownEnvNameSpecified() throws InterruptedException {
AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
appender.setAwsLogsClient(awsLogClient);
String prefix = "logstream-";
appender.setLogStream(prefix + "%systemEnviron{NOTKNOWNVARIABLE}");
final String expectedLogStream = prefix + null;
PatternLayout layout = new PatternLayout();
layout.setPattern("%msg");
layout.setContext(LOGGER_CONTEXT);
layout.start();
appender.setLayout(layout);
LoggingEvent event = new LoggingEvent();
event.setTimeStamp(System.currentTimeMillis());
event.setLoggerName("name");
event.setLevel(Level.DEBUG);
event.setMessage("message");
final PutLogEventsResult result = new PutLogEventsResult();
result.setNextSequenceToken("ewopjfewfj");
expect(awsLogClient.putLogEvents(isA(PutLogEventsRequest.class))).andAnswer(new IAnswer<PutLogEventsResult>() {
@Override
public PutLogEventsResult answer() {
PutLogEventsRequest request = (PutLogEventsRequest) getCurrentArguments()[0];
assertEquals(LOG_GROUP, request.getLogGroupName());
assertEquals(expectedLogStream, request.getLogStreamName());
return result;
}
});
awsLogClient.shutdown();
// =====================================
replay(awsLogClient);
appender.start();
appender.append(event);
while (appender.getEventsWrittenCount() < 1) {
Thread.sleep(10);
}
appender.stop();
verify(awsLogClient);
}
use of com.amazonaws.services.logs.AWSLogsClient in project cloudwatch-logback-appender by j256.
the class HostAddressConverterTest method testStuff.
@Test(timeout = 5000)
public void testStuff() throws InterruptedException, UnknownHostException {
String hostAddr = InetAddress.getLocalHost().getHostAddress();
AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
appender.setAwsLogsClient(awsLogClient);
String prefix = "logstream-";
appender.setLogStream(prefix + "%hostAddress");
final String expectedLogStream = prefix + hostAddr;
PatternLayout layout = new PatternLayout();
layout.setPattern("%msg");
layout.setContext(LOGGER_CONTEXT);
layout.start();
appender.setLayout(layout);
LoggingEvent event = new LoggingEvent();
event.setTimeStamp(System.currentTimeMillis());
event.setLoggerName("name");
event.setLevel(Level.DEBUG);
event.setMessage("message");
final PutLogEventsResult result = new PutLogEventsResult();
result.setNextSequenceToken("ewopjfewfj");
expect(awsLogClient.putLogEvents(isA(PutLogEventsRequest.class))).andAnswer(new IAnswer<PutLogEventsResult>() {
@Override
public PutLogEventsResult answer() {
PutLogEventsRequest request = (PutLogEventsRequest) getCurrentArguments()[0];
assertEquals(LOG_GROUP, request.getLogGroupName());
assertEquals(expectedLogStream, request.getLogStreamName());
return result;
}
});
awsLogClient.shutdown();
// =====================================
replay(awsLogClient);
appender.start();
appender.append(event);
while (appender.getEventsWrittenCount() < 1) {
Thread.sleep(10);
}
appender.stop();
verify(awsLogClient);
}
use of com.amazonaws.services.logs.AWSLogsClient in project cloudwatch-logback-appender by j256.
the class SystemPropertyConverterTest method testUnknownEnvNameSpecified.
@Test(timeout = 5000)
public void testUnknownEnvNameSpecified() throws InterruptedException {
AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
appender.setAwsLogsClient(awsLogClient);
String prefix = "logstream-";
appender.setLogStream(prefix + "%systemProperty{NOTKNOWNPROPERTY}");
final String expectedLogStream = prefix + null;
PatternLayout layout = new PatternLayout();
layout.setPattern("%msg");
layout.setContext(LOGGER_CONTEXT);
layout.start();
appender.setLayout(layout);
LoggingEvent event = new LoggingEvent();
event.setTimeStamp(System.currentTimeMillis());
event.setLoggerName("name");
event.setLevel(Level.DEBUG);
event.setMessage("message");
final PutLogEventsResult result = new PutLogEventsResult();
result.setNextSequenceToken("ewopjfewfj");
expect(awsLogClient.putLogEvents(isA(PutLogEventsRequest.class))).andAnswer(new IAnswer<PutLogEventsResult>() {
@Override
public PutLogEventsResult answer() {
PutLogEventsRequest request = (PutLogEventsRequest) getCurrentArguments()[0];
assertEquals(LOG_GROUP, request.getLogGroupName());
assertEquals(expectedLogStream, request.getLogStreamName());
return result;
}
});
awsLogClient.shutdown();
// =====================================
replay(awsLogClient);
appender.start();
appender.append(event);
while (appender.getEventsWrittenCount() < 1) {
Thread.sleep(10);
}
appender.stop();
verify(awsLogClient);
}
Aggregations