connecting to Bigtable emulator using environment variable by rahulKQL · Pull Request #6067 · googleapis/google-cloud-java · GitHub
Skip to content

connecting to Bigtable emulator using environment variable#6067

Merged
igorbernstein2 merged 4 commits into
googleapis:masterfrom
rahulKQL:autoEmulator
Aug 19, 2019
Merged

connecting to Bigtable emulator using environment variable#6067
igorbernstein2 merged 4 commits into
googleapis:masterfrom
rahulKQL:autoEmulator

Conversation

@rahulKQL

Copy link
Copy Markdown
Contributor

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

@igorbernstein2 igorbernstein2 left a comment

Copy link
Copy Markdown
Contributor

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

codecov Bot commented Aug 19, 2019

Copy link
Copy Markdown

@igorbernstein2 igorbernstein2 left a comment

Copy link
Copy Markdown
Contributor

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) {

Copy link
Copy Markdown
Contributor

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")

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor 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".

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor 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().

@igorbernstein2 igorbernstein2 left a comment

Copy link
Copy Markdown
Contributor

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