-
Notifications
You must be signed in to change notification settings - Fork 613
Add implementation for listDownloadedModels. #2154
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
Conversation
Coverage ReportAffected SDKs
Test Logs
NotesHTML coverage reports can be produced locally with Head commit (06ce22d8) is created by Prow via merging commits: 4f3ffc5 f21799f. |
Binary Size ReportAffected SDKs
Test Logs
NotesHead commit (06ce22d8) is created by Prow via merging commits: 4f3ffc5 f21799f. |
@@ -84,7 +94,7 @@ public static FirebaseModelDownloader getInstance(@NonNull FirebaseApp app) { | |||
/** @return The set of all models that are downloaded to this device. */ | |||
@NonNull | |||
public Task<Set<CustomModel>> listDownloadedModels() { | |||
throw new UnsupportedOperationException("Not yet implemented."); | |||
return Tasks.forResult(sharedPreferencesUtil.listDownloadedModels()); |
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.
Since sharedPreferences are sync, you could try to create an actual task here to get concurrency.
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.
Done - thanks.
@@ -190,6 +196,24 @@ public synchronized void clearModelDetails(@NonNull String modelName, boolean cl | |||
.commit(); | |||
} | |||
|
|||
public synchronized Set<CustomModel> listDownloadedModels() { | |||
Set<CustomModel> customModels = new HashSet<>(); | |||
Set<String> keySet = getSharedPreferences().getAll().keySet(); |
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.
Since you're reading all the keys at once and not dealing with the sharedpreferences anymore, it may not be necessary to sync the whole method.
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.
The second part (added todo) will need to coordinate with android download manager, so I'll need the sync when I add that.
} | ||
} | ||
return customModels; | ||
} | ||
|
||
synchronized CustomModel isDownloadCompleted(String modelName) { |
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.
the is
prefix in the name suggests a boolean response. What about using maybe
, like maybeGetUpdatedModel
? It's a bit more verbose.
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.
Done
...downloader/src/main/java/com/google/firebase/ml/modeldownloader/FirebaseModelDownloader.java
Show resolved
Hide resolved
FirebaseApp.clearInstancesForTest(); | ||
// default app | ||
FirebaseApp.initializeApp(ApplicationProvider.getApplicationContext(), FIREBASE_OPTIONS); | ||
firebaseModelDownloader = new FirebaseModelDownloader(FIREBASE_OPTIONS, mockPrefs); | ||
|
||
executor = new ThreadPoolExecutor(0, 1, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue<>()); |
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.
You could use a singleThread executor like in
Line 53 in fe51be9
executor = Executors.newSingleThreadExecutor(); |
That way the test shouldn't finish before running the tasks.
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.
Done
|
||
@After | ||
public void cleanUp() { | ||
try { |
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.
AFAIK this is no longer needed when using the single thread executor.
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.
thanks - going too fast.
assertThat(task.isComplete()).isTrue(); | ||
assertEquals(customModelSet, Collections.singleton(CUSTOM_MODEL)); | ||
|
||
executor.awaitTermination(500, TimeUnit.MILLISECONDS); |
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.
You can probably get rid of this too.
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.
done
TestOnCompleteListener<Set<CustomModel>> onCompleteListener = new TestOnCompleteListener<>(); | ||
Task<Set<CustomModel>> task = firebaseModelDownloader.listDownloadedModels(); | ||
task.addOnCompleteListener(executor, onCompleteListener); | ||
Set<CustomModel> customModelSet = onCompleteListener.await(); |
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.
I wonder if Tasks.await(task)
could be used instead here?
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.
I had tried that got - "java.lang.IllegalStateException: Must not be called on the main application thread", found this solution was used elsewhere.
@annzimmer: The following test failed, say
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
smoke test keeps failing but I don't think it's related to my change. |
It's OK to ignore for now, it's a bug in the tests themselves. |
No description provided.