-
Notifications
You must be signed in to change notification settings - Fork 978
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
Preload spec in serving cache #152
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a test for what happens when you exceed the max size of cache in populating. So we're explicit about the intended behaviour. |
||
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)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With a MAX_SPEC_COUNT of 1000, once you have more than that, you're going to be evicting things that might actually be commonly used every 5 minutes. Is that a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's probably introduce problem. Do you think it's better to not limit the cache size based on the number of entry?