Skip to content

Commit 308a937

Browse files
committed
Scala FIT performer minor fix
The tests require FAILED_PRECONDITION GRPC error code to be raised in specific content validation failure situations. Change-Id: I69c61ecdee3b3600b64e08dc3c769e70430909a1 Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/233431 Tested-by: Build Bot <[email protected]> Reviewed-by: Dimitris Christodoulou <[email protected]>
1 parent 8afa542 commit 308a937

File tree

4 files changed

+49
-34
lines changed

4 files changed

+49
-34
lines changed

scala-fit-performer/src/main/scala/com/couchbase/client/performer/scala/ScalaPerformer.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ class ScalaPerformer extends CorePerformer {
311311
responseObserver.onNext(response)
312312
responseObserver.onCompleted()
313313
} catch {
314+
case err: com.couchbase.client.performer.scala.transaction.TestFailureRaiseFailedPrecondition =>
315+
logger.error("Operation failed during transactionCreate due to : " + err)
316+
err.printStackTrace()
317+
responseObserver.onError(Status.FAILED_PRECONDITION.withDescription(err.toString).asException)
314318
case err: RuntimeException =>
315319
logger.error("Operation failed during transactionCreate due to : " + err)
316320
err.printStackTrace()

scala-fit-performer/src/main/scala/com/couchbase/client/performer/scala/transaction/GetMultiHelper.scala

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,8 @@ object GetMultiHelper {
104104
)
105105

106106
if (expectedContent.getExpectSuccess != actualContent.isSuccess) {
107-
throw new TestFailure(
108-
new RuntimeException(
109-
s"ContentAs result $actualContent did not equal expected result ${expectedContent.getExpectSuccess}"
110-
)
107+
throw new TestFailureRaiseFailedPrecondition(
108+
s"ContentAs result $actualContent did not equal expected result ${expectedContent.getExpectSuccess}"
111109
)
112110
}
113111

@@ -116,10 +114,8 @@ object GetMultiHelper {
116114
if (
117115
!java.util.Arrays.equals(expectedContent.getExpectedContentBytes.toByteArray, bytes)
118116
) {
119-
throw new TestFailure(
120-
new RuntimeException(
121-
s"Content bytes ${java.util.Arrays.toString(bytes)} did not equal expected bytes ${expectedContent.getExpectedContentBytes}"
122-
)
117+
throw new TestFailureRaiseFailedPrecondition(
118+
s"Content bytes ${java.util.Arrays.toString(bytes)} did not equal expected bytes ${expectedContent.getExpectedContentBytes}"
123119
)
124120
}
125121
}
@@ -164,10 +160,8 @@ object GetMultiHelper {
164160
)
165161

166162
if (expectedContent.getExpectSuccess != actualContent.isSuccess) {
167-
throw new TestFailure(
168-
new RuntimeException(
169-
s"ContentAs result $actualContent did not equal expected result ${expectedContent.getExpectSuccess}"
170-
)
163+
throw new TestFailureRaiseFailedPrecondition(
164+
s"ContentAs result $actualContent did not equal expected result ${expectedContent.getExpectSuccess}"
171165
)
172166
}
173167

@@ -176,10 +170,8 @@ object GetMultiHelper {
176170
if (
177171
!java.util.Arrays.equals(expectedContent.getExpectedContentBytes.toByteArray, bytes)
178172
) {
179-
throw new TestFailure(
180-
new RuntimeException(
181-
s"Content bytes ${java.util.Arrays.toString(bytes)} did not equal expected bytes ${expectedContent.getExpectedContentBytes}"
182-
)
173+
throw new TestFailureRaiseFailedPrecondition(
174+
s"Content bytes ${java.util.Arrays.toString(bytes)} did not equal expected bytes ${expectedContent.getExpectedContentBytes}"
183175
)
184176
}
185177
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2025 Couchbase, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.couchbase.client.performer.scala.transaction;
17+
18+
/**
19+
* Signals that the performer should fail the RPC with gRPC FAILED_PRECONDITION.
20+
*/
21+
public class TestFailureRaiseFailedPrecondition extends TestFailure {
22+
public TestFailureRaiseFailedPrecondition(String message) {
23+
super(message);
24+
}
25+
}
26+
27+

scala-fit-performer/src/main/scala/com/couchbase/client/performer/scala/transaction/TransactionShared.scala

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -241,20 +241,16 @@ abstract class TransactionShared(
241241
)
242242

243243
if (cas.getExpectSuccess != content.isSuccess) {
244-
throw new TestFailure(
245-
new RuntimeException(
246-
s"ContentAs result $content did not equal expected result ${cas.getExpectSuccess}"
247-
)
244+
throw new TestFailureRaiseFailedPrecondition(
245+
s"ContentAs result $content did not equal expected result ${cas.getExpectSuccess}"
248246
)
249247
}
250248

251249
if (cas.hasExpectedContentBytes) {
252250
val bytes = ContentAsUtil.convert(content.get)
253251
if (!java.util.Arrays.equals(cas.getExpectedContentBytes.toByteArray, bytes)) {
254-
throw new TestFailure(
255-
new RuntimeException(
256-
s"Content bytes ${java.util.Arrays.toString(bytes)} did not equal expected bytes ${cas.getExpectedContentBytes}"
257-
)
252+
throw new TestFailureRaiseFailedPrecondition(
253+
s"Content bytes ${java.util.Arrays.toString(bytes)} did not equal expected bytes ${cas.getExpectedContentBytes}"
258254
)
259255
}
260256
}
@@ -296,21 +292,17 @@ abstract class TransactionShared(
296292
)
297293

298294
if (contentAs.getExpectSuccess != content.isSuccess)
299-
throw new TestFailure(
300-
new RuntimeException(
301-
"ContentAs result " + content + " did not equal expected result " + contentAs.getExpectSuccess
302-
)
295+
throw new com.couchbase.client.performer.scala.transaction.TestFailureRaiseFailedPrecondition(
296+
"ContentAs result " + content + " did not equal expected result " + contentAs.getExpectSuccess
303297
)
304298

305299
if (contentAs.hasExpectedContentBytes) {
306300
val bytes: Array[Byte] = ContentAsUtil.convert(content.get)
307301
if (!java.util.Arrays.equals(contentAs.getExpectedContentBytes.toByteArray, bytes))
308-
throw new TestFailure(
309-
new RuntimeException(
310-
"Content bytes " + java.util.Arrays.toString(
311-
bytes
312-
) + " did not equal expected bytes " + contentAs.getExpectedContentBytes
313-
)
302+
throw new com.couchbase.client.performer.scala.transaction.TestFailureRaiseFailedPrecondition(
303+
"Content bytes " + java.util.Arrays.toString(
304+
bytes
305+
) + " did not equal expected bytes " + contentAs.getExpectedContentBytes
314306
)
315307
}
316308
}

0 commit comments

Comments
 (0)