use of com.google.api.ads.admanager.jaxws.v202108.Value in project beam by apache.
the class FirestoreV1FnBatchWriteWithDeadLetterQueueTest method enqueueingWritesValidateBytesSize.
@Override
@Test
public void enqueueingWritesValidateBytesSize() throws Exception {
int maxBytes = 50;
RpcQosOptions options = rpcQosOptions.toBuilder().withBatchMaxBytes(maxBytes).build();
when(ff.getFirestoreStub(any())).thenReturn(stub);
when(ff.getRpcQos(any())).thenReturn(FirestoreStatefulComponentFactory.INSTANCE.getRpcQos(options));
byte[] bytes = new byte[maxBytes + 1];
SecureRandom.getInstanceStrong().nextBytes(bytes);
byte[] base64Bytes = Base64.getEncoder().encode(bytes);
String base64String = Base64.getEncoder().encodeToString(bytes);
Value largeValue = Value.newBuilder().setStringValueBytes(ByteString.copyFrom(base64Bytes)).build();
// apply a doc transform that is too large
Write write1 = Write.newBuilder().setTransform(DocumentTransform.newBuilder().setDocument(String.format("doc-%03d", 2)).addFieldTransforms(FieldTransform.newBuilder().setAppendMissingElements(ArrayValue.newBuilder().addValues(largeValue)))).build();
// delete a doc that is too large
Write write2 = Write.newBuilder().setDelete(String.format("doc-%03d_%s", 3, base64String)).build();
// update a doc that is too large
Write write3 = Write.newBuilder().setUpdate(Document.newBuilder().setName(String.format("doc-%03d", 4)).putAllFields(ImmutableMap.of("foo", largeValue))).build();
BatchWriteFnWithDeadLetterQueue fn = getFn(clock, ff, options, metricsFixture.counterFactory, metricsFixture.distributionFactory);
fn.populateDisplayData(displayDataBuilder);
fn.setup();
fn.startBundle(startBundleContext);
ArgumentCaptor<WriteFailure> write1FailureCapture = ArgumentCaptor.forClass(WriteFailure.class);
doNothing().when(processContext).outputWithTimestamp(write1FailureCapture.capture(), any());
when(processContext.element()).thenReturn(write1);
fn.processElement(processContext, window);
WriteFailure failure = write1FailureCapture.getValue();
assertNotNull(failure);
String message = failure.getStatus().getMessage();
assertTrue(message.contains("TRANSFORM"));
assertTrue(message.contains("larger than configured max allowed bytes per batch"));
ArgumentCaptor<WriteFailure> write2FailureCapture = ArgumentCaptor.forClass(WriteFailure.class);
doNothing().when(processContext).outputWithTimestamp(write2FailureCapture.capture(), any());
when(processContext.element()).thenReturn(write2);
fn.processElement(processContext, window);
WriteFailure failure2 = write2FailureCapture.getValue();
assertNotNull(failure2);
String message2 = failure2.getStatus().getMessage();
assertTrue(message2.contains("DELETE"));
assertTrue(message2.contains("larger than configured max allowed bytes per batch"));
ArgumentCaptor<WriteFailure> write3FailureCapture = ArgumentCaptor.forClass(WriteFailure.class);
doNothing().when(processContext).outputWithTimestamp(write3FailureCapture.capture(), any());
when(processContext.element()).thenReturn(write3);
fn.processElement(processContext, window);
WriteFailure failure3 = write3FailureCapture.getValue();
assertNotNull(failure3);
String message3 = failure3.getStatus().getMessage();
assertTrue(message3.contains("UPDATE"));
assertTrue(message3.contains("larger than configured max allowed bytes per batch"));
assertEquals(0, fn.writes.size());
}
use of com.google.api.ads.admanager.jaxws.v202108.Value in project beam by apache.
the class FirestoreV1FnBatchWriteWithSummaryTest method enqueueingWritesValidateBytesSize.
@Override
@Test
public void enqueueingWritesValidateBytesSize() throws Exception {
int maxBytes = 50;
RpcQosOptions options = rpcQosOptions.toBuilder().withBatchMaxBytes(maxBytes).build();
when(ff.getFirestoreStub(any())).thenReturn(stub);
when(ff.getRpcQos(any())).thenReturn(FirestoreStatefulComponentFactory.INSTANCE.getRpcQos(options));
byte[] bytes = new byte[maxBytes + 1];
SecureRandom.getInstanceStrong().nextBytes(bytes);
byte[] base64Bytes = Base64.getEncoder().encode(bytes);
String base64String = Base64.getEncoder().encodeToString(bytes);
Value largeValue = Value.newBuilder().setStringValueBytes(ByteString.copyFrom(base64Bytes)).build();
// apply a doc transform that is too large
Write write1 = Write.newBuilder().setTransform(DocumentTransform.newBuilder().setDocument(String.format("doc-%03d", 2)).addFieldTransforms(FieldTransform.newBuilder().setAppendMissingElements(ArrayValue.newBuilder().addValues(largeValue)))).build();
// delete a doc that is too large
Write write2 = Write.newBuilder().setDelete(String.format("doc-%03d_%s", 3, base64String)).build();
// update a doc that is too large
Write write3 = Write.newBuilder().setUpdate(Document.newBuilder().setName(String.format("doc-%03d", 4)).putAllFields(ImmutableMap.of("foo", largeValue))).build();
BatchWriteFnWithSummary fn = getFn(clock, ff, options, metricsFixture.counterFactory, metricsFixture.distributionFactory);
fn.populateDisplayData(displayDataBuilder);
fn.setup();
fn.startBundle(startBundleContext);
try {
when(processContext.element()).thenReturn(write1);
fn.processElement(processContext, window);
fail("expected validation error");
} catch (FailedWritesException e) {
WriteFailure failure = e.getWriteFailures().get(0);
assertNotNull(failure);
String message = failure.getStatus().getMessage();
assertTrue(message.contains("TRANSFORM"));
assertTrue(message.contains("larger than configured max allowed bytes per batch"));
}
try {
when(processContext.element()).thenReturn(write2);
fn.processElement(processContext, window);
fail("expected validation error");
} catch (FailedWritesException e) {
WriteFailure failure = e.getWriteFailures().get(0);
assertNotNull(failure);
String message = failure.getStatus().getMessage();
assertTrue(message.contains("DELETE"));
assertTrue(message.contains("larger than configured max allowed bytes per batch"));
}
try {
when(processContext.element()).thenReturn(write3);
fn.processElement(processContext, window);
fail("expected validation error");
} catch (FailedWritesException e) {
WriteFailure failure = e.getWriteFailures().get(0);
assertNotNull(failure);
String message = failure.getStatus().getMessage();
assertTrue(message.contains("UPDATE"));
assertTrue(message.contains("larger than configured max allowed bytes per batch"));
}
assertEquals(0, fn.writes.size());
}
use of com.google.api.ads.admanager.jaxws.v202108.Value in project spring-cloud-gcp by spring-cloud.
the class FirestoreDefaultClassMapper method entityToDocument.
public <T> Document entityToDocument(T entity, String documentResourceName) {
DocumentSnapshot documentSnapshot = INTERNAL.snapshotFromObject(NOT_USED_PATH, entity);
Map<String, Value> valuesMap = INTERNAL.protoFromSnapshot(documentSnapshot);
return Document.newBuilder().putAllFields(valuesMap).setName(documentResourceName).build();
}
use of com.google.api.ads.admanager.jaxws.v202108.Value in project googleads-java-lib by googleads.
the class PqlTest method testCreateValue_dateSet.
@Test
public void testCreateValue_dateSet() {
Set<Date> numberSet = new LinkedHashSet<Date>();
numberSet.add(date1);
Value value1 = ((SetValue) Pql.createValue(numberSet)).getValues(0);
assertEquals("2012-12-02", DateTimes.toString(((DateValue) value1).getValue()));
}
use of com.google.api.ads.admanager.jaxws.v202108.Value in project googleads-java-lib by googleads.
the class PqlTest method testCreateValue_textSet.
@Test
public void testCreateValue_textSet() {
Set<String> textSet = new LinkedHashSet<String>();
textSet.add("value1");
Value value1 = ((SetValue) Pql.createValue(textSet)).getValues(0);
assertEquals("value1", ((TextValue) value1).getValue());
}
Aggregations