Skip to content

Conversation

@rahulKQL
Copy link

Fixes #6057

User can now connect to Bigtable emulator in three ways:

  • By settings hostName:portNum in BIGTABLE_EMULATOR_HOST environment variable.
  • By providing only the port number within the local workstation.
  • By providing hostName & port Number.

Now user can connect to Bigtable emulator in three ways:
 - By settings hostName:portNum in BIGTABLE_EMULATOR_HOST environment variable.
 - By providing only port number within the local workstation.
 - By providing hostName & port Number.
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Aug 12, 2019
Copy link

@igorbernstein2 igorbernstein2 left a comment

Choose a reason for hiding this comment

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

A couple more things:

  • please add a log statement notifying the user that the client is targeting the emulator.
  • in the test rule please add a precondition preventing tests from running when the environment variable is set. The test environment should be controlled via maven profiles not environment variables and the mixture will just create confusion
  • Please add a safe guard to the instance admin client that prevents its use when the env var is set (the emulator doesn't support instance admin api)

Thanks!

@codecov
Copy link

codecov bot commented Aug 19, 2019

Codecov Report

Merging #6067 into master will increase coverage by 0.26%.
The diff coverage is 20%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #6067      +/-   ##
============================================
+ Coverage     47.11%   47.38%   +0.26%     
+ Complexity    27195    27182      -13     
============================================
  Files          2522     2523       +1     
  Lines        274264   274599     +335     
  Branches      31326    31383      +57     
============================================
+ Hits         129231   130124     +893     
- Misses       134602   134862     +260     
+ Partials      10431     9613     -818
Impacted Files Coverage Δ Complexity Δ
...e/cloud/bigtable/data/v2/BigtableDataSettings.java 33.33% <16.66%> (-1.45%) 4 <2> (+1)
.../bigtable/admin/v2/BigtableTableAdminSettings.java 63.63% <18.18%> (-8.11%) 8 <2> (+1)
...gtable/admin/v2/BigtableInstanceAdminSettings.java 96.55% <50%> (-3.45%) 6 <1> (ø)
...ain/java/com/google/cloud/storage/StorageImpl.java 77.81% <0%> (-8.39%) 98% <0%> (-5%)
...rc/main/java/com/google/cloud/storage/Storage.java 79.72% <0%> (-5.45%) 0% <0%> (ø)
...ud/storage/contrib/nio/testing/FakeStorageRpc.java 59.66% <0%> (-1.29%) 44% <0%> (ø)
...om/google/cloud/storage/spi/v1/HttpStorageRpc.java 1.64% <0%> (-0.18%) 1% <0%> (ø)
...e/cloud/vision/v1p4beta1/ImageAnnotatorClient.java 62% <0%> (ø) 19% <0%> (ø) ⬇️
...ogle/cloud/storage/spi/v1/HttpStorageRpcSpans.java 100% <0%> (ø) 3% <0%> (ø) ⬇️
...rc/main/java/com/google/cloud/storage/HmacKey.java 5.73% <0%> (ø) 0% <0%> (?)
... and 151 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1c9c48c...5b9688b. Read the comment docs.

Copy link

@igorbernstein2 igorbernstein2 left a comment

Choose a reason for hiding this comment

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

This is looking good.

try {
port = Integer.parseInt(hostAndPort.substring(hostAndPort.lastIndexOf(":") + 1));
return newBuilderForEmulator(hostAndPort.substring(0, hostAndPort.lastIndexOf(":")), port);
} catch (NumberFormatException ex) {

Choose a reason for hiding this comment

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

Please handle IndexOutOfBoundsException as well

builder
.stubSettings()
.setProjectId("fake-project")
.setInstanceId("fake-instance")

Choose a reason for hiding this comment

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

This diverges from the other clients. I don't think we should set project & instance ids any more

* Create a new builder preconfigured to connect to the Bigtable emulator with host & port number.
*/
public static Builder newBuilderForEmulator(String hostname, int port) {
Builder builder = new Builder().setProjectId("fake-project").setInstanceId("fake-instance");

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 setting the project instance ids to stay consistent with other languages

Copy link
Author

Choose a reason for hiding this comment

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

For Java, we have projectId & instanceId required. Shall I remove the Preconditions checks for projectId & InstanceId?
I would vote to keep these checks and continue with "fake-project" & "fake-instance".

Choose a reason for hiding this comment

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

I'm not sure what you mean by that. I'm picturing something along the lines of:

BigtableTableAdminSettings.newBuilderForEmulator("localhost", 1234).setProjectId("blah").setInstanceId("blah2").build()

I think the other client languages require something similar

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the explanation, I mistook it as emulator without any projectId & instanceId. Have updated with the suggestion. please have a look.

- Updated null check with String.isNullOrEmpty
- Handled IndexOutOfBoundsException
- fixed java doc in newBuilder()
- Adapted with TruthJunit.assume() instead of Assert.assume().
Copy link

@igorbernstein2 igorbernstein2 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for implementing this!

@igorbernstein2 igorbernstein2 merged commit 13fc06a into googleapis:master Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement BIGTABLE_EMULATOR_HOST environment variable support as in golang

3 participants