Skip to content
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

Reduced jacoco exclusions and added more tests #446

Merged
merged 3 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,16 @@ List<String> jacocoExclusions = [
// code for configuration, settings, etc is excluded from coverage
'org.opensearch.ad.AnomalyDetectorPlugin',

// rest layer is tested in integration testing mostly, difficult to mock all of it
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer to this PR to write unit test for REST actions opensearch-project/ml-commons#228?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will take a look! Will try to add those in a separate PR if thats fine

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that's fine.

'org.opensearch.ad.rest.*',

'org.opensearch.ad.model.ModelProfileOnNode',
'org.opensearch.ad.model.InitProgressProfile',
'org.opensearch.ad.model.ADTaskProfile',
'org.opensearch.ad.model.AnomalyResultBucket',
'org.opensearch.ad.model.EntityProfileName',
'org.opensearch.ad.rest.*',
'org.opensearch.ad.AnomalyDetectorJobRunner',

// Class containing just constants. Don't need to test
// Class containing just constants. Don't need to test
'org.opensearch.ad.constant.*',

//'org.opensearch.ad.common.exception.AnomalyDetectionException',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Set;

import org.opensearch.ad.Name;
import org.opensearch.ad.constant.CommonErrorMessages;
import org.opensearch.ad.constant.CommonName;

public enum EntityProfileName implements Name {
Expand Down Expand Up @@ -50,7 +51,7 @@ public static EntityProfileName getName(String name) {
case CommonName.MODELS:
return MODELS;
default:
throw new IllegalArgumentException("Unsupported profile types");
throw new IllegalArgumentException(CommonErrorMessages.UNSUPPORTED_PROFILE_TYPE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ public void testFailRCFPolling() throws IOException, InterruptedException {
public void testInitProgressProfile() {
InitProgressProfile progressOne = new InitProgressProfile("0%", 0, requiredSamples);
InitProgressProfile progressTwo = new InitProgressProfile("0%", 0, requiredSamples);
InitProgressProfile progressThree = new InitProgressProfile("96%", 2, requiredSamples);
assertTrue(progressOne.equals(progressTwo));
assertFalse(progressOne.equals(progressThree));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,21 @@ public void testSerializeAnomalyResultBucket() throws IOException {
assertTrue(parsedAnomalyResultBucket.equals(anomalyResultBucket));
}

public void testAnomalyResultBucketEquals() {
Map<String, Object> keyOne = new HashMap<>();
keyOne.put("test-field-1", "test-value-1");
Map<String, Object> keyTwo = new HashMap<>();
keyTwo.put("test-field-2", "test-value-2");
AnomalyResultBucket testBucketOne = new AnomalyResultBucket(keyOne, 3, 0.5);
AnomalyResultBucket testBucketTwo = new AnomalyResultBucket(keyOne, 5, 0.75);
AnomalyResultBucket testBucketThree = new AnomalyResultBucket(keyTwo, 7, 0.2);
assertFalse(testBucketOne.equals(testBucketTwo));
assertFalse(testBucketTwo.equals(testBucketThree));
}

@SuppressWarnings("unchecked")
public void testToXContent() throws IOException {
Map<String, Object> key = new HashMap<String, Object>() {
Map<String, Object> key = new HashMap<>() {
{
put("test-field-1", "test-value-1");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.opensearch.ad.cluster.HashRing;
import org.opensearch.ad.common.exception.AnomalyDetectionException;
import org.opensearch.ad.common.exception.JsonPathNotFoundException;
import org.opensearch.ad.constant.CommonErrorMessages;
import org.opensearch.ad.constant.CommonName;
import org.opensearch.ad.model.Entity;
import org.opensearch.ad.model.EntityProfileName;
Expand Down Expand Up @@ -372,4 +373,11 @@ public void testResponseHashCodeEquals() {
set.add(response);
assertTrue(set.contains(response));
}

public void testEntityProfileName() {
assertEquals("state", EntityProfileName.getName(CommonName.STATE).getName());
assertEquals("models", EntityProfileName.getName(CommonName.MODELS).getName());
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> EntityProfileName.getName("abc"));
assertEquals(exception.getMessage(), CommonErrorMessages.UNSUPPORTED_PROFILE_TYPE);
}
}