forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoreTest.java
More file actions
95 lines (79 loc) · 3.59 KB
/
Copy pathStoreTest.java
File metadata and controls
95 lines (79 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2018-2020 The Feast Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package feast.common.models;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertTrue;
import feast.proto.core.StoreProto.Store.Subscription;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
public class StoreTest {
private List<Subscription> allSubscriptions;
@Before
public void setUp() {
Subscription emptySubscription = Subscription.newBuilder().build();
Subscription subscription1 = Subscription.newBuilder().setProject("*").setName("*").build();
Subscription subscription2 =
Subscription.newBuilder().setProject("project1").setName("fs_2").build();
Subscription subscription3 =
Subscription.newBuilder().setProject("project1").setName("fs_1").setExclude(true).build();
allSubscriptions =
Arrays.asList(emptySubscription, subscription1, subscription2, subscription3);
}
@Test
public void shouldReturnSubscriptionsBasedOnStr() {
String subscriptions = "project1:fs_1:true,project1:fs_2";
List<Subscription> actual1 = Store.parseSubFromStr(subscriptions);
List<Subscription> expected1 = Arrays.asList(allSubscriptions.get(2), allSubscriptions.get(3));
List<Subscription> actual2 = Store.parseSubFromStrWithoutExclusions(subscriptions);
List<Subscription> expected2 = Arrays.asList(allSubscriptions.get(2));
assertTrue(actual1.containsAll(expected1) && expected1.containsAll(actual1));
assertTrue(actual2.containsAll(expected2) && expected2.containsAll(actual2));
}
@Test
public void shouldReturnStringBasedOnSubscription() {
// Case: default exclude should be false
String actual1 = Store.parseSubscriptionFrom(allSubscriptions.get(2));
Subscription sub1 = allSubscriptions.get(2);
String expected1 = sub1.getProject() + ":" + sub1.getName() + ":" + sub1.getExclude();
// Case: explicit setting of exclude to true
String actual2 = Store.parseSubscriptionFrom(allSubscriptions.get(3));
Subscription sub2 = allSubscriptions.get(3);
String expected2 = sub2.getProject() + ":" + sub2.getName() + ":" + sub2.getExclude();
assertThat(actual1, equalTo(expected1));
assertThat(actual2, equalTo(expected2));
}
@Test
public void shouldSubscribeToFeatureSet() {
allSubscriptions = allSubscriptions.subList(2, 4);
// Case: excluded flag = true
boolean actual1 = Store.isSubscribedToFeatureSet(allSubscriptions, "project1", "fs_1");
boolean expected1 = false;
// Case: excluded flag = false
boolean actual2 = Store.isSubscribedToFeatureSet(allSubscriptions, "project1", "fs_2");
boolean expected2 = true;
// Case: featureset does not exist
boolean actual3 =
Store.isSubscribedToFeatureSet(allSubscriptions, "project1", "fs_nonexistent");
boolean expected3 = false;
assertThat(actual1, equalTo(expected1));
assertThat(actual2, equalTo(expected2));
assertThat(actual3, equalTo(expected3));
}
}