-
Notifications
You must be signed in to change notification settings - Fork 998
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preload spec in serving cache (#152)
* Preload spec in serving cache * Disable async refresh and only periodically refresh cache
- Loading branch information
1 parent
0a89bd6
commit 1c6b893
Showing
5 changed files
with
160 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
serving/src/test/java/feast/serving/service/CachedSpecStorageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package feast.serving.service; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.google.common.testing.FakeTicker; | ||
import feast.specs.EntitySpecProto.EntitySpec; | ||
import feast.specs.FeatureSpecProto.FeatureSpec; | ||
import feast.specs.StorageSpecProto.StorageSpec; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class CachedSpecStorageTest { | ||
|
||
private CoreService coreService; | ||
private CachedSpecStorage cachedSpecStorage; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
coreService = mock(CoreService.class); | ||
cachedSpecStorage = new CachedSpecStorage(coreService); | ||
} | ||
|
||
@Test | ||
public void testPopulateCache() { | ||
Map<String, FeatureSpec> featureSpecMap = new HashMap<>(); | ||
featureSpecMap.put("feature_1", mock(FeatureSpec.class)); | ||
|
||
Map<String, StorageSpec> storageSpecMap = new HashMap<>(); | ||
storageSpecMap.put("storage_1", mock(StorageSpec.class)); | ||
|
||
Map<String, EntitySpec> entitySpecMap = new HashMap<>(); | ||
entitySpecMap.put("entity_1", mock(EntitySpec.class)); | ||
|
||
when(coreService.getAllFeatureSpecs()).thenReturn(featureSpecMap); | ||
when(coreService.getAllEntitySpecs()).thenReturn(entitySpecMap); | ||
when(coreService.getAllStorageSpecs()).thenReturn(storageSpecMap); | ||
|
||
cachedSpecStorage.populateCache(); | ||
Map<String, FeatureSpec> result = | ||
cachedSpecStorage.getFeatureSpecs(Collections.singletonList("feature_1")); | ||
Map<String, StorageSpec> result1 = | ||
cachedSpecStorage.getStorageSpecs(Collections.singletonList("storage_1")); | ||
Map<String, EntitySpec> result2 = | ||
cachedSpecStorage.getEntitySpecs(Collections.singletonList("entity_1")); | ||
|
||
assertThat(result.size(), equalTo(1)); | ||
assertThat(result1.size(), equalTo(1)); | ||
assertThat(result2.size(), equalTo(1)); | ||
|
||
verify(coreService, times(0)).getFeatureSpecs(any(Iterable.class)); | ||
verify(coreService, times(0)).getStorageSpecs(any(Iterable.class)); | ||
verify(coreService, times(0)).getEntitySpecs(any(Iterable.class)); | ||
} | ||
|
||
@Test | ||
public void reloadFailureShouldReturnOldValue() { | ||
Map<String, FeatureSpec> featureSpecMap = new HashMap<>(); | ||
featureSpecMap.put("feature_1", mock(FeatureSpec.class)); | ||
|
||
Map<String, StorageSpec> storageSpecMap = new HashMap<>(); | ||
storageSpecMap.put("storage_1", mock(StorageSpec.class)); | ||
|
||
Map<String, EntitySpec> entitySpecMap = new HashMap<>(); | ||
entitySpecMap.put("entity_1", mock(EntitySpec.class)); | ||
|
||
when(coreService.getAllFeatureSpecs()).thenReturn(featureSpecMap); | ||
when(coreService.getFeatureSpecs(any(Iterable.class))).thenThrow(new RuntimeException("error")); | ||
when(coreService.getAllEntitySpecs()).thenReturn(entitySpecMap); | ||
when(coreService.getEntitySpecs(any(Iterable.class))).thenThrow(new RuntimeException("error")); | ||
when(coreService.getAllStorageSpecs()).thenReturn(storageSpecMap); | ||
when(coreService.getStorageSpecs(any(Iterable.class))).thenThrow(new RuntimeException("error")); | ||
|
||
cachedSpecStorage.populateCache(); | ||
Map<String, FeatureSpec> result = | ||
cachedSpecStorage.getFeatureSpecs(Collections.singletonList("feature_1")); | ||
Map<String, StorageSpec> result1 = | ||
cachedSpecStorage.getStorageSpecs(Collections.singletonList("storage_1")); | ||
Map<String, EntitySpec> result2 = | ||
cachedSpecStorage.getEntitySpecs(Collections.singletonList("entity_1")); | ||
|
||
assertThat(result.size(), equalTo(1)); | ||
assertThat(result1.size(), equalTo(1)); | ||
assertThat(result2.size(), equalTo(1)); | ||
verify(coreService, times(0)).getFeatureSpecs(any(Iterable.class)); | ||
verify(coreService, times(0)).getStorageSpecs(any(Iterable.class)); | ||
verify(coreService, times(0)).getEntitySpecs(any(Iterable.class)); | ||
|
||
result = cachedSpecStorage.getFeatureSpecs(Collections.singletonList("feature_1")); | ||
result1 = cachedSpecStorage.getStorageSpecs(Collections.singletonList("storage_1")); | ||
result2 = cachedSpecStorage.getEntitySpecs(Collections.singletonList("entity_1")); | ||
assertThat(result.size(), equalTo(1)); | ||
assertThat(result1.size(), equalTo(1)); | ||
assertThat(result2.size(), equalTo(1)); | ||
} | ||
} |