use of com.amazonaws.services.logs.AWSLogsClient in project cloudwatch-logback-appender by j256.
the class SystemPropertyConverterTest method testStuff.
@Test(timeout = 5000)
public void testStuff() throws InterruptedException {
String propName = "os.version";
String propValue = System.getProperty(propName);
assertNotNull(propValue);
AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
appender.setAwsLogsClient(awsLogClient);
String prefix = "logstream-";
appender.setLogStream(prefix + "%systemProperty{" + propName + "}");
final String expectedLogStream = prefix + propValue;
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 Ec2InstanceIdConverterTest method testInstanceId.
@Test(timeout = 10000)
public void testInstanceId() throws InterruptedException {
String instanceId = "fewhwehpewpf";
Ec2InstanceIdConverter.setInstanceId(instanceId);
AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
appender.setAwsLogsClient(awsLogClient);
String prefix = "logstream-";
appender.setLogStream(prefix + "%instanceId");
final String expectedLogStream = prefix + instanceId;
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 testStuff.
@Test(timeout = 5000)
public void testStuff() throws InterruptedException {
String envName = "SHELL";
String envValue = System.getenv(envName);
AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
appender.setAwsLogsClient(awsLogClient);
String prefix = "logstream-";
appender.setLogStream(prefix + "%systemEnviron{" + envName + "}");
final String expectedLogStream = prefix + envValue;
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 UuidConverterTest method testStuff.
@Test(timeout = 5000)
public void testStuff() throws InterruptedException {
String uuidString = UUID.randomUUID().toString();
UuidConverter.setUuidString(uuidString);
AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
appender.setAwsLogsClient(awsLogClient);
String prefix = "logstream-";
appender.setLogStream(prefix + "%uuid");
final String expectedLogStream = prefix + uuidString;
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 aws-codebuild-jenkins-plugin by awslabs.
the class AWSClientFactory method getCloudWatchLogsClient.
public AWSLogsClient getCloudWatchLogsClient() throws InvalidInputException {
AWSLogsClient client = new AWSLogsClient(awsCredentialsProvider, getClientConfiguration());
client.setEndpoint("https://logs." + region + getAwsClientSuffix(region));
return client;
}
Aggregations