Skip to content

Added more unit tests #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ allprojects {
targetCompatibility = '1.8'
}

version = '1.0.1'
version = '1.0.2'
}

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package software.amazon.cloudwatchlogs.emf.logger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;

import java.util.List;
Expand Down Expand Up @@ -176,6 +177,30 @@ public void testUseDefaultEnvironmentOnResolverException() {
expectDimension("ServiceType", serviceType);
}

@Test
public void testNoDefaultDimensions() {
MetricsLogger logger = new MetricsLogger(envProvider);
logger.setDimensions();
logger.putMetric("Count", 1);
logger.flush();
List<DimensionSet> dimensions = sink.getContext().getDimensions();

assertTrue(dimensions.size() == 0);
assertTrue(sink.getLogEvents().size() == 1);

String logEvent = sink.getLogEvents().get(0);
assertTrue(logEvent.contains("\"Dimensions\":[]"));
}

@Test
public void testNoDefaultDimensionsAfterSetDimension() {
MetricsLogger logger = new MetricsLogger(envProvider);

logger.setDimensions(DimensionSet.of("Name", "Test"));
logger.flush();
expectDimension("Name", "Test");
}

private void expectDimension(String dimension, String value) {
List<DimensionSet> dimensions = sink.getContext().getDimensions();
assertEquals(dimensions.size(), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ public void testPutMultipleDimensionSets() throws JsonProcessingException {
"{\"Dimensions\":[[\"Region\"],[\"Instance\"]],\"Metrics\":[],\"Namespace\":\"aws-embedded-metrics\"}");
}

@Test
public void testGetDimensionAfterSetDimensions() {
MetricDirective metricDirective = new MetricDirective();
metricDirective.setDefaultDimensions(DimensionSet.of("Dim", "Default"));
metricDirective.setDimensions(Arrays.asList(DimensionSet.of("Name", "Test")));

assertEquals(1, metricDirective.getAllDimensions().size());
}

@Test
public void testPutDimensionsWhenDefaultDimensionsDefined() throws JsonProcessingException {
MetricDirective metricDirective = new MetricDirective();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,30 @@

package software.amazon.cloudwatchlogs.emf.sinks;

import java.util.List;
import software.amazon.cloudwatchlogs.emf.model.MetricsContext;

public class SinkShunt implements ISink {

private MetricsContext context;

private List<String> logEvents;

@Override
public void accept(MetricsContext context) {
this.context = context;
try {
this.logEvents = context.serialize();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public MetricsContext getContext() {
return context;
}

public List<String> getLogEvents() {
return this.logEvents;
}
}