-
Notifications
You must be signed in to change notification settings - Fork 18
PM- added testing case for sorting data from storage #1458
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
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis pull request adds a new method, Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test Suite
participant Interface as IStorageUtilityIndexed
participant Dummy as DummyIndexedStorageUtility
participant Reflect as Reflection (getFieldValue)
Test->>Interface: call getSortedRecordsForValues(metaFieldNames, values, orderby)
Interface->>Dummy: delegate call to getSortedRecordsForValues
Dummy->>Reflect: retrieve field values for each record
Reflect-->>Dummy: return field value
Dummy-->>Test: return sorted record list
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 6
🧹 Nitpick comments (1)
src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java (1)
132-133: Add assertion message for better test failure diagnostics.The assertion message incorrectly references "vans" instead of "adidas".
- Assert.assertArrayEquals("Failed index match [brand,style][vans,mens]", fiveSortedSizesOfMensAddidas,matchedSortedRecords.toArray()); + Assert.assertArrayEquals("Failed index match [brand,style][adidas,mens]", fiveSortedSizesOfMensAdidas,matchedSortedRecords.toArray());
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java(1 hunks)src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java(2 hunks)src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: task-list-completed
- GitHub Check: task-list-completed
- GitHub Check: task-list-completed
- GitHub Check: task-list-completed
src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java
Outdated
Show resolved
Hide resolved
src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java
Outdated
Show resolved
Hide resolved
src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java
Outdated
Show resolved
Hide resolved
src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java
Show resolved
Hide resolved
src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java
Outdated
Show resolved
Hide resolved
src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java
Outdated
Show resolved
Hide resolved
|
@coderabbitai I pushed a fix in commit f2a04ae, please review it |
|
@pm-dimagi The changes look good! You've made several improvements:
(`∇´ゞ) 🔗 Analysis chain🏁 Scripts executedThe following scripts were executed for the analysis: Script: Length of output: 8288 ✅ Actions performedComments resolved. |
| * they may need to clean up if the bulk read doesn't complete | ||
| */ | ||
|
|
||
| Vector<E> getSortedRecordsForValues(String[] metaFieldNames, Object[] values,String orderby); |
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.
Java docs are out of order
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.
@pm-dimagi stil seems pending
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.
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.
uff! Java docs are still wrong for this method, they copy the text from another java doc which is not relevant to this method at all - "If the provided recordMap already contains entries for any ids, it is not
* required for them to be retrieved from storage again." .
| } catch (Exception e) { | ||
| // Log error and continue with no ordering | ||
| System.err.println("Failed to compare records: " + e.getMessage()); |
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.
we should not be catching generic exceptions
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.
@pm-dimagi stil seems pending
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.
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 ask here was to remove the catch clause, not to rename the variable.
src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java
Outdated
Show resolved
Hide resolved
src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java
Outdated
Show resolved
Hide resolved
| Vector<Shoe> matchedAscSortedRecords = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"vans", "mens"},Shoe.META_SIZE+" ASC"); | ||
| Assert.assertArrayEquals("Failed index match [brand,style][adidas,mens]", matchedAscSortedRecords.toArray(),fiveSizesOfMensVans); | ||
|
|
||
| Vector<Shoe> matchedAscSortedRecordsTest = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"vans", "mens"},Shoe.META_SIZE+" ASSC"); |
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.
this call should fail right given ASSC is not the right keyword ?
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.
revert the array is asc order as default value is ascending
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 don't think we should be allowing for incorrrect keywords in this method and should do a strict match and else throw an error.
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.
added in the new commit 9007023
| Vector<Shoe> matchedAscSortedRecordsWithoutKey = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"vans", "mens"}, " DESC"); | ||
| Assert.assertArrayEquals("Failed the sorted match [brand,style][vans,mens]", fiveSizesOfMensVans, fiveSizesOfMensVans); | ||
| }catch (IllegalArgumentException e){ | ||
| Assert.assertArrayEquals(e.getMessage(), matchedAscSortedRecords.toArray(), fiveSizesOfMensVans); |
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.
why should the array be sorted in case of an exception ?
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.
|
|
||
| try { | ||
| Vector<Shoe> matchedAscSortedRecordsWithoutKey = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"vans", "mens"}, " DESC"); | ||
| Assert.assertArrayEquals("Failed the sorted match [brand,style][vans,mens]", fiveSizesOfMensVans, fiveSizesOfMensVans); |
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.
looks incorrect as we are comparing the same array fiveSizesOfMensVans to itself
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.
shubham1g5
left a comment
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.
Code formatting seems quite off, please format ANY NEW code in Android Studio with the code style files
src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java
Outdated
Show resolved
Hide resolved
| new Shoe("vans", "mens", i + 5); | ||
| } | ||
|
|
||
| fiveSortedSizesOfMensAdidas = new Shoe[5]; |
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.
as I see this is only used for matching an expected outcome of a test, so this must only be used in that particular test case and should not be written to db at all.
| try { | ||
| Vector<Shoe> matchedDescSortedRecordsWithoutKey = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"adidas", "mens"}, " DESC"); | ||
| Assert.assertArrayEquals("Failed the sorted match [brand,style][adidas,mens]", matchedDescSortedRecordsWithoutKey.toArray(), fiveSortedSizesOfMensAdidas); | ||
| }catch (IllegalArgumentException e){ |
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.
why catch anything here ?
| try { | ||
| Vector<Shoe> matchedAscSortedRecordsTest = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"vans", "mens"}, Shoe.META_SIZE + " ASSC"); | ||
| Assert.assertArrayEquals("Failed the sorted match [brand,style][adidas,mens]", matchedAscSortedRecordsTest.toArray(), fiveSizesOfMensVans); | ||
| }catch (IllegalArgumentException e){ | ||
| System.out.println(e.getMessage()); | ||
| } |
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.
this code needs to verify the exception by following this pattern -
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
// Code that should throw an exception
});
// check the exception message
assertEquals("Invalid argument", exception.getMessage());
|
@pm-dimagi The build seems to failing as well |
| Shoe[] fiveSizesOfMensVans; | ||
| Shoe[] fiveSortedSizesOfMensAdidas; | ||
|
|
||
| Shoe[] combinedCollection; |
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.
should not be global
| } | ||
| } | ||
|
|
||
| void combineAllList(){ |
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.
code formatting is still off in the method
23eee32 to
1cd3db9
Compare
f26c8c0 to
1d65258
Compare
# Conflicts: # src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java # src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java # src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java
|
Closing since we are not maintaining data types correctly on Android database which results in sort like this doing a String sort and changing/correcting data types at this point will require a careful db migration which we want to avoid doing. We should revisit this though if in-memory sort on top of Sqlite becomes a bottleneck for any of the features. |
Product Description
Test cases to test the sorting of an table from the storage through SQL query
Technical Summary
Sort function take the field through which sorting need to be done and take value ASC or DESC to describe the order of the sorting
Safety Assurance
Safety story
there is the test case written so it is all passed so there is no safety threat in this
Automated test coverage
Local test cases written
QA Plan
Special deploy instructions
Rollback instructions
Review
Duplicate PR
Automatically duplicate this PR as defined in contributing.md.
Summary by CodeRabbit
New Features
Tests