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
feat: add support to customize gcloud command of LocalDatastoreHelper #137
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
15587f4
feat: add support to customize gcloud command of local datastore helper
athakor 8654955
feat: modified the code
athakor f49a94c
feat: code reftoring
athakor 098a97b
feat: update the create method and remove the duplicate constructor
athakor 0ffd3f2
feat: fix review changes
athakor d8b9176
feat: fixe the build log with timeout failure
athakor 1ffa1f0
feat: cleanup the tmp dir
athakor 13f7c7f
feat: used the deleteRecursively by making it package private
athakor File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,12 @@ | |
import com.google.cloud.datastore.Entity; | ||
import com.google.cloud.datastore.Key; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.concurrent.TimeoutException; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
@@ -43,6 +47,17 @@ public class ITLocalDatastoreHelperTest { | |
private static final double TOLERANCE = 0.00001; | ||
private static final String PROJECT_ID_PREFIX = "test-project-"; | ||
private static final String NAMESPACE = "namespace"; | ||
private Path dataDir; | ||
|
||
@Before | ||
public void setUp() throws IOException { | ||
dataDir = Files.createTempDirectory("gcd"); | ||
} | ||
|
||
@After | ||
public void tearDown() throws IOException { | ||
LocalDatastoreHelper.deleteRecursively(dataDir); | ||
} | ||
|
||
@Test | ||
public void testCreate() { | ||
|
@@ -54,6 +69,57 @@ public void testCreate() { | |
assertTrue(helper.getProjectId().startsWith(PROJECT_ID_PREFIX)); | ||
} | ||
|
||
@Test | ||
public void testCreateWithBuilder() { | ||
LocalDatastoreHelper helper = | ||
LocalDatastoreHelper.newBuilder() | ||
.setConsistency(0.75) | ||
.setPort(8081) | ||
.setStoreOnDisk(false) | ||
.setDataDir(dataDir) | ||
.build(); | ||
assertTrue(Math.abs(0.75 - helper.getConsistency()) < TOLERANCE); | ||
assertTrue(helper.getProjectId().startsWith(PROJECT_ID_PREFIX)); | ||
assertFalse(helper.isStoreOnDisk()); | ||
assertEquals(8081, helper.getPort()); | ||
assertEquals(dataDir, helper.getGcdPath()); | ||
LocalDatastoreHelper incompleteHelper = LocalDatastoreHelper.newBuilder().build(); | ||
assertTrue(Math.abs(0.9 - incompleteHelper.getConsistency()) < TOLERANCE); | ||
assertTrue(incompleteHelper.getProjectId().startsWith(PROJECT_ID_PREFIX)); | ||
} | ||
|
||
@Test | ||
public void testCreateWithToBuilder() throws IOException { | ||
LocalDatastoreHelper helper = | ||
LocalDatastoreHelper.newBuilder() | ||
.setConsistency(0.75) | ||
.setPort(8081) | ||
.setStoreOnDisk(false) | ||
.setDataDir(dataDir) | ||
.build(); | ||
assertTrue(Math.abs(0.75 - helper.getConsistency()) < TOLERANCE); | ||
assertTrue(helper.getProjectId().startsWith(PROJECT_ID_PREFIX)); | ||
assertFalse(helper.isStoreOnDisk()); | ||
assertEquals(8081, helper.getPort()); | ||
assertEquals(dataDir, helper.getGcdPath()); | ||
LocalDatastoreHelper actualHelper = helper.toBuilder().build(); | ||
assertLocalDatastoreHelpersEquivelent(helper, actualHelper); | ||
Path dataDir = Files.createTempDirectory("gcd_data_dir"); | ||
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. Cleanup dir like above 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. done |
||
actualHelper = | ||
helper | ||
.toBuilder() | ||
.setConsistency(0.85) | ||
.setPort(9091) | ||
.setStoreOnDisk(true) | ||
.setDataDir(dataDir) | ||
.build(); | ||
assertTrue(Math.abs(0.85 - actualHelper.getConsistency()) < TOLERANCE); | ||
assertTrue(actualHelper.isStoreOnDisk()); | ||
assertEquals(9091, actualHelper.getPort()); | ||
assertEquals(dataDir, actualHelper.getGcdPath()); | ||
LocalDatastoreHelper.deleteRecursively(dataDir); | ||
} | ||
|
||
@Test | ||
public void testCreatePort() { | ||
LocalDatastoreHelper helper = LocalDatastoreHelper.create(0.75, 8888); | ||
|
@@ -103,4 +169,31 @@ public void testStartStopReset() throws IOException, InterruptedException, Timeo | |
assertNotNull(ex.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testStartStopResetWithBuilder() | ||
throws IOException, InterruptedException, TimeoutException { | ||
try { | ||
LocalDatastoreHelper helper = LocalDatastoreHelper.newBuilder().build(); | ||
helper.start(); | ||
Datastore datastore = helper.getOptions().getService(); | ||
Key key = datastore.newKeyFactory().setKind("kind").newKey("name"); | ||
datastore.put(Entity.newBuilder(key).build()); | ||
assertNotNull(datastore.get(key)); | ||
helper.reset(); | ||
assertNull(datastore.get(key)); | ||
helper.stop(Duration.ofMinutes(1)); | ||
datastore.get(key); | ||
Assert.fail(); | ||
} catch (DatastoreException ex) { | ||
assertNotNull(ex.getMessage()); | ||
} | ||
} | ||
|
||
public void assertLocalDatastoreHelpersEquivelent( | ||
LocalDatastoreHelper expected, LocalDatastoreHelper actual) { | ||
assertEquals(expected.getConsistency(), actual.getConsistency(), 0); | ||
assertEquals(expected.isStoreOnDisk(), actual.isStoreOnDisk()); | ||
assertEquals(expected.getGcdPath(), actual.getGcdPath()); | ||
} | ||
} |
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.
Looks good, can you also add a delete in an
@After
so we're not leaving lots of directories around?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