Skip to content
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

Persistent mock database #637

Merged
merged 4 commits into from
Sep 20, 2018
Merged

Persistent mock database #637

merged 4 commits into from
Sep 20, 2018

Conversation

AlexandraRoatis
Copy link
Contributor

Description

Database implementation to be used in testing when we want to check behavior for persistent databases. The class PersistentMockDB inherits most of the functionality from MockDB with the addition that data is read from a file on disk at open (if the file exists) and it is stored to disk at close.

Fixes Issue #636.

Type of change

Insert x into the following checkboxes to confirm (eg. [x]):

  • Bug fix.
  • New feature.
  • Enhancement.
  • Unit test.
  • Breaking change (a fix or feature that causes existing functionality to not work as expected).
  • Requires documentation update.

Testing

Please describe the tests you used to validate this pull request. Provide any relevant details for test configurations as well as any instructions to reproduce these results.

  • The new class was added to the existing array of database tests.

Verification

Insert x into the following checkboxes to confirm (eg. [x]):

  • I have self-reviewed my own code and conformed to the style guidelines of this project.
  • New and existing tests pass locally with my changes.
  • I have added tests for my fix or feature.
  • I have made appropriate changes to the corresponding documentation.
  • My code generates no new warnings.
  • Any dependent changes have been made.

@AlexandraRoatis
Copy link
Contributor Author

Since persistence is loosely defined for the class PersistentMockDB (data gets stored to disk only at database close), I've excluded it from two of the tests from DatabaseFactory.

@AlexandraRoatis AlexandraRoatis added this to the 0.3.2 milestone Sep 14, 2018
File dbFile = new File(path);

if (dbFile.exists()) {
BufferedReader reader = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This little block could be cleaned up a bit using a try-with-resources statement

}

private static final byte[] convertToByteArray(String commaSeparatedNumbers) {
String[] numbers =
Copy link
Contributor

@aionick aionick Sep 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The end index is exclusive in substring, not sure if this is intentional that you want to chop off the last character or not, just checking

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm eliminating the [ and ] that are added when calling Arrays.toString(...) which is used for storing the data in the file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it


FileWriter writer = null;

try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd do a try-with-resources here

@@ -575,8 +579,9 @@ public void testDrop() {
}

@Test
/** This test is non-deterministic and may fail. If it does, re-run the test suite. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we know if failure is problematic or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I don't see much value in it. It's a legacy test. I almost removed it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got confirmation that the test can be ignored.

if (reader != null) {
reader.close();
}
} catch (IOException e) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print e.printStackTrace()?

Copy link
Collaborator

@AionJayT AionJayT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@arajasek arajasek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍

@AionJayT AionJayT merged commit b47245f into master-pre-merge Sep 20, 2018
@AlexandraRoatis AlexandraRoatis deleted the db-mock branch September 20, 2018 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants