use of org.apache.avro.generic.GenericData.Record in project components by Talend.
the class MarketoOutputWriterTest method testRetryOperationFailDieOnError.
@Test
public void testRetryOperationFailDieOnError() throws Exception {
IndexedRecord record = new Record(MarketoConstants.getRESTOutputSchemaForSyncMultipleLeads());
record.put(0, 12345);
doReturn(false).when(client).isErrorRecoverable(any(List.class));
doReturn(getFailedSyncResult("REST", "902", "Invalid operation")).when(client).syncMultipleLeads(any(TMarketoOutputProperties.class), any(List.class));
props.outputOperation.setValue(OutputOperation.syncMultipleLeads);
props.updateSchemaRelated();
when(sink.getProperties()).thenReturn(props);
writer.open("test");
try {
writer.write(record);
writer.close();
fail("Should not be here");
} catch (Exception e) {
assertTrue(e.getMessage().contains("902"));
}
}
use of org.apache.avro.generic.GenericData.Record in project components by Talend.
the class MarketoOutputWriterTest method testRetryOperationSuccess.
@Test
public void testRetryOperationSuccess() throws Exception {
IndexedRecord record = new Record(MarketoConstants.getRESTOutputSchemaForSyncMultipleLeads());
record.put(0, 12345);
doReturn(getSuccessSyncResult("created")).when(client).syncMultipleLeads(any(TMarketoOutputProperties.class), any(List.class));
props.outputOperation.setValue(OutputOperation.syncMultipleLeads);
props.updateSchemaRelated();
when(sink.getProperties()).thenReturn(props);
writer.open("test");
writer.write(record);
MarketoResult result = (MarketoResult) writer.close();
assertEquals(1, result.apiCalls);
}
use of org.apache.avro.generic.GenericData.Record in project components by Talend.
the class MarketoOutputWriterTest method testRetryOperationFailRecoverableErrror.
@Test
public void testRetryOperationFailRecoverableErrror() throws Exception {
IndexedRecord record = new Record(MarketoConstants.getRESTOutputSchemaForSyncMultipleLeads());
record.put(0, 12345);
doReturn(getFailedSyncResult("REST", "602", "expired header")).when(client).syncMultipleLeads(any(TMarketoOutputProperties.class), any(List.class));
doReturn(true).when(client).isErrorRecoverable(any(List.class));
props.dieOnError.setValue(false);
props.outputOperation.setValue(OutputOperation.syncMultipleLeads);
props.updateSchemaRelated();
when(sink.getProperties()).thenReturn(props);
int minDelay = props.connection.maxReconnAttemps.getValue() * props.connection.attemptsIntervalTime.getValue();
long start = System.currentTimeMillis();
writer.open("test");
writer.write(record);
MarketoResult result = (MarketoResult) writer.close();
long end = System.currentTimeMillis();
assertEquals((long) props.connection.maxReconnAttemps.getValue(), result.apiCalls);
assertEquals(Collections.emptyList(), writer.getSuccessfulWrites());
assertTrue(minDelay <= (end - start));
List<IndexedRecord> rejects = writer.getRejectedWrites();
IndexedRecord reject = rejects.get(0);
assertNotNull(reject);
assertEquals("failed", reject.get(4));
assertTrue(String.valueOf(reject.get(5)).contains("602"));
}
use of org.apache.avro.generic.GenericData.Record in project components by Talend.
the class MarketoListOperationWriterTest method testWriteSOAP.
@Test
public void testWriteSOAP() throws Exception {
doReturn(getSuccessSyncResult("added")).when(client).addToList(any(ListOperationParameters.class));
IndexedRecord record = new Record(MarketoConstants.getListOperationSOAPSchema());
record.put(0, "MKTOLISTNAME");
record.put(1, "TESTS");
record.put(2, "ID");
record.put(3, "12345");
props.connection.apiMode.setValue(APIMode.SOAP);
props.dieOnError.setValue(false);
props.multipleOperation.setValue(true);
props.schemaInput.schema.setValue(MarketoConstants.getListOperationSOAPSchema());
props.updateOutputSchemas();
when(client.getApi()).thenReturn("SOAP");
when(sink.getProperties()).thenReturn(props);
writer.open("test");
writer.write(record);
assertEquals(1, writer.getSuccessfulWrites().size());
record.put(1, "TEST2");
writer.write(record);
assertNotNull(writer.close());
assertEquals(1, writer.getSuccessfulWrites().size());
//
}
use of org.apache.avro.generic.GenericData.Record in project hazelcast by hazelcast.
the class AvroUpsertTarget method conclude.
@Override
public Object conclude() {
Record record = this.record.build();
this.record = null;
return record;
}
Aggregations