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: support setting compression option #192
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7244291
feat: support setting compression option
olavloite 73dfbc8
fix: use correct encoding header
olavloite 193dfee
fix: add project id
olavloite eb967c6
docs: fix typo + missing end tag
olavloite 2435e88
chore: resolve merge conflicts
olavloite afbd975
tests: fix test failure on emulator
olavloite 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
50 changes: 50 additions & 0 deletions
50
google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/EncodingInterceptor.java
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.cloud.spanner.spi.v1; | ||
|
||
import io.grpc.CallOptions; | ||
import io.grpc.Channel; | ||
import io.grpc.ClientCall; | ||
import io.grpc.ClientInterceptor; | ||
import io.grpc.ForwardingClientCall; | ||
import io.grpc.Metadata; | ||
import io.grpc.Metadata.Key; | ||
import io.grpc.MethodDescriptor; | ||
|
||
class EncodingInterceptor implements ClientInterceptor { | ||
private static final String RESPONSE_ENCODING_KEY_NAME = "x-response-encoding"; | ||
private static final Key<String> RESPONSE_ENCODING_KEY = | ||
Metadata.Key.of(RESPONSE_ENCODING_KEY_NAME, Metadata.ASCII_STRING_MARSHALLER); | ||
|
||
private final String encoding; | ||
|
||
EncodingInterceptor(String encoding) { | ||
this.encoding = encoding; | ||
} | ||
|
||
@Override | ||
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall( | ||
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) { | ||
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>( | ||
next.newCall(method, callOptions)) { | ||
@Override | ||
public void start(Listener<RespT> responseListener, Metadata headers) { | ||
headers.put(RESPONSE_ENCODING_KEY, encoding); | ||
super.start(responseListener, headers); | ||
} | ||
}; | ||
} | ||
} |
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
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
68 changes: 68 additions & 0 deletions
68
google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITSpannerOptionsTest.java
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.spanner.it; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import com.google.cloud.spanner.Database; | ||
import com.google.cloud.spanner.DatabaseClient; | ||
import com.google.cloud.spanner.IntegrationTestEnv; | ||
import com.google.cloud.spanner.ParallelIntegrationTest; | ||
import com.google.cloud.spanner.ResultSet; | ||
import com.google.cloud.spanner.Spanner; | ||
import com.google.cloud.spanner.SpannerOptions; | ||
import com.google.cloud.spanner.Statement; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@Category(ParallelIntegrationTest.class) | ||
@RunWith(JUnit4.class) | ||
public class ITSpannerOptionsTest { | ||
@ClassRule public static IntegrationTestEnv env = new IntegrationTestEnv(); | ||
private static Database db; | ||
|
||
@BeforeClass | ||
public static void setUp() throws Exception { | ||
db = env.getTestHelper().createTestDatabase(); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDown() throws Exception { | ||
db.drop(); | ||
} | ||
|
||
@Test | ||
public void testCompression() { | ||
for (String compressorName : new String[] {"gzip", "identity", null}) { | ||
SpannerOptions options = | ||
env.getTestHelper().getOptions().toBuilder().setCompressorName(compressorName).build(); | ||
try (Spanner spanner = options.getService()) { | ||
DatabaseClient client = spanner.getDatabaseClient(db.getId()); | ||
try (ResultSet rs = client.singleUse().executeQuery(Statement.of("SELECT 1 AS COL1"))) { | ||
assertThat(rs.next()).isTrue(); | ||
assertThat(rs.getLong(0)).isEqualTo(1L); | ||
assertThat(rs.next()).isFalse(); | ||
} | ||
} | ||
} | ||
} | ||
} |
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.
Would it be possible to test an end to end compression and verify that the compressor is actually used.
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.
Yes absolutely. Once the support is in the staging environment, we can run this IT against it to test the change. @olavloite I'll give you a heads up when the feature is available in staging.