Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Terence <[email protected]>
  • Loading branch information
terryyylim committed Nov 19, 2020
1 parent 49cd60c commit 18bd370
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void updateFeatureSetStatus(
.build());
}

public Map<String, FeatureSetProto.FeatureSpec> simpleListFeatures(
public Map<String, FeatureProto.FeatureSpecV2> simpleListFeatures(
String projectName, Map<String, String> labels, List<String> entities) {
return stub.listFeatures(
CoreServiceProto.ListFeaturesRequest.newBuilder()
Expand All @@ -176,7 +176,7 @@ public Map<String, FeatureSetProto.FeatureSpec> simpleListFeatures(
.getFeaturesMap();
}

public Map<String, FeatureSetProto.FeatureSpec> simpleListFeatures(
public Map<String, FeatureProto.FeatureSpecV2> simpleListFeatures(
String projectName, String... entities) {
return simpleListFeatures(projectName, Collections.emptyMap(), Arrays.asList(entities));
}
Expand Down
18 changes: 6 additions & 12 deletions core/src/test/java/feast/core/controller/CoreServiceRestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,9 @@ public void listFeatureSets() {

@Test
public void listFeatures() {
// entities = [merchant_id]
// project = default
// should return 4 features
String uri1 =
UriComponentsBuilder.fromPath("/api/v1/features")
.queryParam("entities", "merchant_id")
UriComponentsBuilder.fromPath("/api/v2/features")
.queryParam("entities", "entity1", "entity2")
.buildAndExpand()
.toString();
get(uri1)
Expand All @@ -190,15 +187,12 @@ public void listFeatures() {
.everything()
.assertThat()
.contentType(ContentType.JSON)
.body("features", aMapWithSize(4));
.body("features", aMapWithSize(2));

// entities = [merchant_id]
// project = merchant
// should return 2 features
String uri2 =
UriComponentsBuilder.fromPath("/api/v1/features")
.queryParam("entities", "merchant_id")
.queryParam("project", "merchant")
UriComponentsBuilder.fromPath("/api/v2/features")
.queryParam("entities", "entity1", "entity2")
.queryParam("project", "default")
.buildAndExpand()
.toString();
get(uri2)
Expand Down
81 changes: 54 additions & 27 deletions core/src/test/java/feast/core/service/SpecServiceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ public void initState() {
.setBatchSource(
DataGenerator.createFileDataSourceSpec("file:///path/to/file", "ts_col", ""))
.build());
apiClient.applyFeatureTable(
"default",
DataGenerator.createFeatureTableSpec(
"featuretable2",
Arrays.asList("entity1", "entity2"),
new HashMap<>() {
{
put("feature3", ValueProto.ValueType.Enum.STRING);
put("feature4", ValueProto.ValueType.Enum.FLOAT);
}
},
7200,
ImmutableMap.of("feat_key4", "feat_value4"))
.toBuilder()
.setBatchSource(
DataGenerator.createFileDataSourceSpec("file:///path/to/file", "ts_col", ""))
.build());
apiClient.simpleApplyEntity(
"project1",
DataGenerator.createEntitySpecV2(
Expand Down Expand Up @@ -311,11 +328,15 @@ public void shouldUseDefaultProjectIfProjectUnspecified() {
.build();
List<FeatureTableProto.FeatureTable> featureTables =
apiClient.simpleListFeatureTables(filter);
System.out.println(featureTables);

assertThat(featureTables, hasSize(1));
assertThat(featureTables, hasSize(2));
assertThat(
featureTables,
hasItem(hasProperty("spec", hasProperty("name", equalTo("featuretable1")))));
assertThat(
featureTables,
hasItem(hasProperty("spec", hasProperty("name", equalTo("featuretable2")))));
}

@Test
Expand Down Expand Up @@ -1005,49 +1026,55 @@ class ListFeatures {
@Test
public void shouldFilterFeaturesByEntitiesAndLabels() {
// Case 1: Only filter by entities
Map<String, FeatureSetProto.FeatureSpec> result1 =
apiClient.simpleListFeatures("project1", "user_id");
Map<String, FeatureProto.FeatureSpecV2> result1 =
apiClient.simpleListFeatures("default", "entity1", "entity2");

assertThat(result1, aMapWithSize(2));
assertThat(result1, hasKey(equalTo("project1/fs3:feature1")));
assertThat(result1, hasKey(equalTo("project1/fs3:feature2")));
assertThat(result1, aMapWithSize(4));
assertThat(result1, hasKey(equalTo("featuretable1:feature1")));
assertThat(result1, hasKey(equalTo("featuretable1:feature2")));
assertThat(result1, hasKey(equalTo("featuretable2:feature3")));
assertThat(result1, hasKey(equalTo("featuretable2:feature4")));

// Case 2: Filter by entities and labels
Map<String, FeatureSetProto.FeatureSpec> result2 =
Map<String, FeatureProto.FeatureSpecV2> result2 =
apiClient.simpleListFeatures(
"project1",
ImmutableMap.of("app", "feast", "version", "one"),
ImmutableList.of("customer_id"));
"default",
ImmutableMap.of("feat_key2", "feat_value2"),
ImmutableList.of("entity1", "entity2"));

assertThat(result2, aMapWithSize(1));
assertThat(result2, hasKey(equalTo("project1/fs4:feature2")));
assertThat(result2, aMapWithSize(2));
assertThat(result2, hasKey(equalTo("featuretable1:feature1")));
assertThat(result2, hasKey(equalTo("featuretable1:feature2")));

// Case 3: Filter by labels
Map<String, FeatureSetProto.FeatureSpec> result3 =
Map<String, FeatureProto.FeatureSpecV2> result3 =
apiClient.simpleListFeatures(
"project1", ImmutableMap.of("app", "feast"), Collections.emptyList());
"default", ImmutableMap.of("feat_key4", "feat_value4"), Collections.emptyList());

assertThat(result3, aMapWithSize(2));
assertThat(result3, hasKey(equalTo("project1/fs4:feature2")));
assertThat(result3, hasKey(equalTo("project1/fs5:feature3")));
assertThat(result3, hasKey(equalTo("featuretable2:feature3")));
assertThat(result3, hasKey(equalTo("featuretable2:feature4")));

// Case 4: Filter by nothing, except project
Map<String, FeatureSetProto.FeatureSpec> result4 =
Map<String, FeatureProto.FeatureSpecV2> result4 =
apiClient.simpleListFeatures("project1", ImmutableMap.of(), Collections.emptyList());

assertThat(result4, aMapWithSize(4));
assertThat(result4, hasKey(equalTo("project1/fs3:feature1")));
assertThat(result4, hasKey(equalTo("project1/fs3:feature1")));
assertThat(result4, hasKey(equalTo("project1/fs4:feature2")));
assertThat(result4, hasKey(equalTo("project1/fs5:feature3")));
assertThat(result4, aMapWithSize(0));

// Case 5: Filter by nothing; will use default project
Map<String, FeatureSetProto.FeatureSpec> result5 =
Map<String, FeatureProto.FeatureSpecV2> result5 =
apiClient.simpleListFeatures("", ImmutableMap.of(), Collections.emptyList());

assertThat(result5, aMapWithSize(2));
assertThat(result5, hasKey(equalTo("default/fs1:total")));
assertThat(result5, hasKey(equalTo("default/fs2:sum")));
assertThat(result5, aMapWithSize(4));
assertThat(result5, hasKey(equalTo("featuretable1:feature1")));
assertThat(result5, hasKey(equalTo("featuretable1:feature2")));
assertThat(result5, hasKey(equalTo("featuretable2:feature3")));
assertThat(result5, hasKey(equalTo("featuretable2:feature4")));

// Case 6: Filter by mismatched entity
Map<String, FeatureProto.FeatureSpecV2> result6 =
apiClient.simpleListFeatures("default", ImmutableMap.of(), ImmutableList.of("entity1"));
assertThat(result6, aMapWithSize(0));
}
}

Expand Down Expand Up @@ -1359,7 +1386,7 @@ public void shouldReturnNoTables() {
StatusRuntimeException.class,
() -> apiClient.simpleGetFeatureTable(projectName, featureTableName));

assertThat(featureTables.size(), equalTo(0));
assertThat(featureTables.size(), equalTo(1));
assertThat(
exc.getMessage(),
equalTo(
Expand Down

0 comments on commit 18bd370

Please sign in to comment.