Skip to content
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

fix: update the accounting of partial batch mutations #2149

Merged
merged 32 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
add tests
  • Loading branch information
ron-gal committed Mar 14, 2024
commit 7362b104590e7cf044ab0814f1892b8e08f192b6
Expand Up @@ -34,7 +34,7 @@ public class MutateRowsErrorConverterUnaryCallable extends UnaryCallable<BulkMut

private final UnaryCallable<BulkMutation, MutateRowsAttemptResult> innerCallable;

MutateRowsErrorConverterUnaryCallable(
public MutateRowsErrorConverterUnaryCallable(
UnaryCallable<BulkMutation, MutateRowsAttemptResult> callable) {
this.innerCallable = callable;
}
Expand Down
@@ -0,0 +1,89 @@
/*
* Copyright 2024 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
*
* https://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.bigtable.data.v2.stub.mutaterows;

import static com.google.common.truth.Truth.assertThat;

import com.google.api.core.SettableApiFuture;
import com.google.api.gax.grpc.GrpcStatusCode;
import com.google.api.gax.rpc.ApiExceptionFactory;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.bigtable.data.v2.internal.RequestContext;
import com.google.cloud.bigtable.data.v2.models.BulkMutation;
import com.google.cloud.bigtable.data.v2.models.MutateRowsException;
import com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation;
import com.google.cloud.bigtable.data.v2.stub.MutateRowsErrorConverterUnaryCallable;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;

@RunWith(JUnit4.class)
public class MutateRowsErrorConverterUnaryCallableTest {

private static final RequestContext REQUEST_CONTEXT =
RequestContext.create("fake-project", "fake-instance", "fake-profile");
private UnaryCallable<BulkMutation, MutateRowsAttemptResult> innerCallable;
igorbernstein2 marked this conversation as resolved.
Show resolved Hide resolved
private ArgumentCaptor<BulkMutation> innerMutation;
private SettableApiFuture<MutateRowsAttemptResult> innerResult;

@SuppressWarnings("unchecked")
@Before
public void setUp() {
innerCallable = Mockito.mock(UnaryCallable.class);
innerMutation = ArgumentCaptor.forClass(BulkMutation.class);
innerResult = SettableApiFuture.create();
Mockito.when(innerCallable.futureCall(innerMutation.capture(), Mockito.any()))
.thenReturn(innerResult);
}

@Test
public void testSuccess() {
MutateRowsErrorConverterUnaryCallable callable =
new MutateRowsErrorConverterUnaryCallable(innerCallable);

innerResult.set(new MutateRowsAttemptResult());
callable.call(BulkMutation.create("fake-table"));
igorbernstein2 marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
public void testFailure() {
MutateRowsErrorConverterUnaryCallable callable =
new MutateRowsErrorConverterUnaryCallable(innerCallable);

innerResult.set(
new MutateRowsAttemptResult(
Arrays.asList(
FailedMutation.create(
0,
ApiExceptionFactory.createException(
null, GrpcStatusCode.of(io.grpc.Status.Code.INTERNAL), false))),
true));

Throwable actualError = null;
try {
callable.call(BulkMutation.create("fake-table"));
} catch (Throwable t) {
actualError = t;
}

assertThat(actualError).isInstanceOf(MutateRowsException.class);
assertThat(((MutateRowsException) actualError).isRetryable()).isTrue();
}
}
igorbernstein2 marked this conversation as resolved.
Show resolved Hide resolved