Skip to content

Commit 8cb1942

Browse files
committed
udpate
1 parent 26ed4d1 commit 8cb1942

File tree

4 files changed

+110
-76
lines changed

4 files changed

+110
-76
lines changed

test-proxy/EnableAutoValue.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is a marker file to trigger auto-value injection into the annotation processor path
2+
https://github.com/googleapis/java-shared-config/blob/51c9f68ff1736761b21c921f078ab2c8675ff268/pom.xml#L758

test-proxy/pom.xml

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.google.cloud</groupId>
55
<artifactId>google-cloud-bigtable-test-proxy</artifactId>
6-
<version>1.0</version>
6+
<version>0.0.1-SNAPSHOT</version>
77
<packaging>jar</packaging>
88
<name>Google Cloud Bigtable Test Proxy</name>
99
<url>https://github.com/googleapis/java-bigtable</url>
10+
<description>Cloud Bigtable Java Client test proxy for running conformance tests.</description>
1011

1112
<parent>
1213
<artifactId>google-cloud-bigtable-parent</artifactId>
@@ -30,11 +31,6 @@
3031
<type>pom</type>
3132
<scope>import</scope>
3233
</dependency>
33-
<dependency>
34-
<groupId>com.google.auto.value</groupId>
35-
<artifactId>auto-value</artifactId>
36-
<version>1.9</version>
37-
</dependency>
3834
</dependencies>
3935
</dependencyManagement>
4036

@@ -55,10 +51,6 @@
5551
<groupId>com.google.protobuf</groupId>
5652
<artifactId>protobuf-java</artifactId>
5753
</dependency>
58-
<dependency>
59-
<groupId>com.google.auto.value</groupId>
60-
<artifactId>auto-value</artifactId>
61-
</dependency>
6254
</dependencies>
6355

6456
<build>
@@ -91,7 +83,6 @@
9183
<plugin>
9284
<groupId>org.apache.maven.plugins</groupId>
9385
<artifactId>maven-shade-plugin</artifactId>
94-
<version>3.2.4</version>
9586
<executions>
9687
<execution>
9788
<phase>package</phase>
@@ -121,6 +112,58 @@
121112
</execution>
122113
</executions>
123114
</plugin>
115+
<!-- start skip publishing to maven central -->
116+
<plugin>
117+
<groupId>org.apache.maven.plugins</groupId>
118+
<artifactId>maven-deploy-plugin</artifactId>
119+
<version>3.0.0-M2</version>
120+
<configuration>
121+
<skip>true</skip>
122+
</configuration>
123+
</plugin>
124+
<plugin>
125+
<groupId>org.sonatype.plugins</groupId>
126+
<artifactId>nexus-staging-maven-plugin</artifactId>
127+
<configuration>
128+
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
129+
</configuration>
130+
</plugin>
131+
<plugin>
132+
<groupId>org.apache.maven.plugins</groupId>
133+
<artifactId>maven-site-plugin</artifactId>
134+
<configuration>
135+
<skipDeploy>true</skipDeploy>
136+
</configuration>
137+
</plugin>
138+
<plugin>
139+
<groupId>org.apache.maven.plugins</groupId>
140+
<artifactId>maven-source-plugin</artifactId>
141+
<configuration>
142+
<skipSource>true</skipSource>
143+
</configuration>
144+
</plugin>
145+
<plugin>
146+
<groupId>org.apache.maven.plugins</groupId>
147+
<artifactId>maven-javadoc-plugin</artifactId>
148+
<configuration>
149+
<skip>true</skip>
150+
</configuration>
151+
</plugin>
152+
<plugin>
153+
<groupId>org.apache.maven.plugins</groupId>
154+
<artifactId>maven-gpg-plugin</artifactId>
155+
<configuration>
156+
<skip>true</skip>
157+
</configuration>
158+
</plugin>
159+
<plugin>
160+
<groupId>org.codehaus.mojo</groupId>
161+
<artifactId>clirr-maven-plugin</artifactId>
162+
<configuration>
163+
<skip>true</skip>
164+
</configuration>
165+
</plugin>
166+
<!-- end skip publishing to maven central -->
124167
</plugins>
125168
</build>
126169
</project>

test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxy.java

Lines changed: 50 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
2626
import com.google.api.gax.rpc.ApiException;
2727
import com.google.api.gax.rpc.ServerStream;
28-
import com.google.auth.oauth2.ServiceAccountJwtAccessCredentials;
28+
import com.google.auth.oauth2.GoogleCredentials;
2929
import com.google.auto.value.AutoValue;
3030
import com.google.bigtable.v2.Column;
3131
import com.google.bigtable.v2.Family;
@@ -42,6 +42,7 @@
4242
import com.google.cloud.bigtable.data.v2.models.RowMutation;
4343
import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings;
4444
import com.google.cloud.bigtable.testproxy.CloudBigtableV2TestProxyGrpc.CloudBigtableV2TestProxyImplBase;
45+
import com.google.common.base.Preconditions;
4546
import com.google.protobuf.ByteString;
4647
import com.google.protobuf.util.Durations;
4748
import com.google.rpc.Code;
@@ -201,18 +202,12 @@ private CbtClient getClient(String id) throws StatusException {
201202
@Override
202203
public synchronized void createClient(
203204
CreateClientRequest request, StreamObserver<CreateClientResponse> responseObserver) {
204-
if (request.getClientId().isEmpty()
205-
|| request.getProjectId().isEmpty()
206-
|| request.getInstanceId().isEmpty()
207-
|| request.getDataTarget().isEmpty()) {
208-
responseObserver.onError(
209-
Status.INVALID_ARGUMENT
210-
.withDescription("clientId, projectId, instanceId, and dataTarget must be provided.")
211-
.asException());
212-
return;
213-
}
205+
Preconditions.checkArgument(!request.getClientId().isEmpty(), "client id must be provided");
206+
Preconditions.checkArgument(!request.getProjectId().isEmpty(), "project id must be provided");
207+
Preconditions.checkArgument(!request.getInstanceId().isEmpty(), "instance id must be provided");
208+
Preconditions.checkArgument(!request.getDataTarget().isEmpty(), "data target must be provided");
214209

215-
if (idClientMap.get(request.getClientId()) != null) {
210+
if (idClientMap.contains(request.getClientId())) {
216211
responseObserver.onError(
217212
Status.ALREADY_EXISTS
218213
.withDescription("Client " + request.getClientId() + " already exists.")
@@ -257,12 +252,11 @@ public synchronized void createClient(
257252
@Override
258253
public void closeClient(
259254
CloseClientRequest request, StreamObserver<CloseClientResponse> responseObserver) {
260-
CbtClient client = idClientMap.get(request.getClientId());
261-
if (client == null) {
262-
responseObserver.onError(
263-
Status.NOT_FOUND
264-
.withDescription("Client " + request.getClientId() + " not found.")
265-
.asException());
255+
CbtClient client;
256+
try {
257+
client = getClient(request.getClientId());
258+
} catch (StatusException e) {
259+
responseObserver.onError(e);
266260
return;
267261
}
268262

@@ -291,12 +285,11 @@ public void removeClient(
291285
@Override
292286
public void mutateRow(
293287
MutateRowRequest request, StreamObserver<MutateRowResult> responseObserver) {
294-
CbtClient client = idClientMap.get(request.getClientId());
295-
if (client == null) {
296-
responseObserver.onError(
297-
Status.NOT_FOUND
298-
.withDescription("Client " + request.getClientId() + " not found.")
299-
.asException());
288+
CbtClient client;
289+
try {
290+
client = getClient(request.getClientId());
291+
} catch (StatusException e) {
292+
responseObserver.onError(e);
300293
return;
301294
}
302295

@@ -327,12 +320,11 @@ public void mutateRow(
327320
@Override
328321
public void bulkMutateRows(
329322
MutateRowsRequest request, StreamObserver<MutateRowsResult> responseObserver) {
330-
CbtClient client = idClientMap.get(request.getClientId());
331-
if (client == null) {
332-
responseObserver.onError(
333-
Status.NOT_FOUND
334-
.withDescription("Client " + request.getClientId() + " not found.")
335-
.asException());
323+
CbtClient client;
324+
try {
325+
client = getClient(request.getClientId());
326+
} catch (StatusException e) {
327+
responseObserver.onError(e);
336328
return;
337329
}
338330

@@ -377,12 +369,11 @@ public void bulkMutateRows(
377369

378370
@Override
379371
public void readRow(ReadRowRequest request, StreamObserver<RowResult> responseObserver) {
380-
CbtClient client = idClientMap.get(request.getClientId());
381-
if (client == null) {
382-
responseObserver.onError(
383-
Status.NOT_FOUND
384-
.withDescription("Client " + request.getClientId() + " not found.")
385-
.asException());
372+
CbtClient client;
373+
try {
374+
client = getClient(request.getClientId());
375+
} catch (StatusException e) {
376+
responseObserver.onError(e);
386377
return;
387378
}
388379

@@ -442,12 +433,11 @@ public void readRow(ReadRowRequest request, StreamObserver<RowResult> responseOb
442433

443434
@Override
444435
public void readRows(ReadRowsRequest request, StreamObserver<RowsResult> responseObserver) {
445-
CbtClient client = idClientMap.get(request.getClientId());
446-
if (client == null) {
447-
responseObserver.onError(
448-
Status.NOT_FOUND
449-
.withDescription("Client " + request.getClientId() + " not found.")
450-
.asException());
436+
CbtClient client;
437+
try {
438+
client = getClient(request.getClientId());
439+
} catch (StatusException e) {
440+
responseObserver.onError(e);
451441
return;
452442
}
453443

@@ -558,12 +548,11 @@ private static RowsResult.Builder convertRowsResult(
558548
@Override
559549
public void sampleRowKeys(
560550
SampleRowKeysRequest request, StreamObserver<SampleRowKeysResult> responseObserver) {
561-
CbtClient client = idClientMap.get(request.getClientId());
562-
if (client == null) {
563-
responseObserver.onError(
564-
Status.NOT_FOUND
565-
.withDescription("Client " + request.getClientId() + " not found.")
566-
.asException());
551+
CbtClient client;
552+
try {
553+
client = getClient(request.getClientId());
554+
} catch (StatusException e) {
555+
responseObserver.onError(e);
567556
return;
568557
}
569558

@@ -607,12 +596,11 @@ public void sampleRowKeys(
607596
@Override
608597
public void checkAndMutateRow(
609598
CheckAndMutateRowRequest request, StreamObserver<CheckAndMutateRowResult> responseObserver) {
610-
CbtClient client = idClientMap.get(request.getClientId());
611-
if (client == null) {
612-
responseObserver.onError(
613-
Status.NOT_FOUND
614-
.withDescription("Client " + request.getClientId() + " not found.")
615-
.asException());
599+
CbtClient client;
600+
try {
601+
client = getClient(request.getClientId());
602+
} catch (StatusException e) {
603+
responseObserver.onError(e);
616604
return;
617605
}
618606

@@ -643,12 +631,11 @@ public void checkAndMutateRow(
643631
@Override
644632
public void readModifyWriteRow(
645633
ReadModifyWriteRowRequest request, StreamObserver<RowResult> responseObserver) {
646-
CbtClient client = idClientMap.get(request.getClientId());
647-
if (client == null) {
648-
responseObserver.onError(
649-
Status.NOT_FOUND
650-
.withDescription("Client " + request.getClientId() + " not found.")
651-
.asException());
634+
CbtClient client;
635+
try {
636+
client = getClient(request.getClientId());
637+
} catch (StatusException e) {
638+
responseObserver.onError(e);
652639
return;
653640
}
654641

@@ -749,9 +736,9 @@ private CredentialsProvider getCredentialsProvider() throws IOException {
749736
return NoCredentialsProvider.create();
750737
}
751738

752-
final ServiceAccountJwtAccessCredentials creds =
753-
ServiceAccountJwtAccessCredentials.fromStream(
754-
new ByteArrayInputStream(credential.getBytes(UTF_8)));
739+
final GoogleCredentials creds =
740+
GoogleCredentials.fromStream(new ByteArrayInputStream(credential.getBytes(UTF_8)));
741+
755742
return FixedCredentialsProvider.create(creds);
756743
}
757744

test-proxy/src/main/java/com/google/cloud/bigtable/testproxy/CbtTestProxyMain.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ private CbtTestProxyMain() {}
2727
private static final Logger logger = Logger.getLogger(CbtTestProxyMain.class.getName());
2828

2929
public static void main(String[] args) throws InterruptedException, IOException {
30-
int port = Integer.parseInt(System.getProperty("port", "9999"));
30+
int port = Integer.getInteger("port", 9999);
3131
if (port <= 0) {
3232
throw new IllegalArgumentException(String.format("Port %d is not > 0.", port));
3333
}
3434

35-
CbtTestProxy cbtTestProxy = CbtTestProxy.createUnencrypted();
35+
CbtTestProxy cbtTestProxy;
3636

3737
// If encryption is specified
3838
boolean encrypted = Boolean.getBoolean("encrypted");
@@ -41,6 +41,8 @@ public static void main(String[] args) throws InterruptedException, IOException
4141
String sslTarget = System.getProperty("ssl.target");
4242
String credentialJsonPath = System.getProperty("credential.json.path");
4343
cbtTestProxy = CbtTestProxy.createEncrypted(rootCertsPemPath, sslTarget, credentialJsonPath);
44+
} else {
45+
cbtTestProxy = CbtTestProxy.createUnencrypted();
4446
}
4547

4648
logger.info(String.format("Test proxy starting on %d", port));

0 commit comments

Comments
 (0)