use of org.apache.avro.generic.GenericData.Record in project components by Talend.
the class MarketoListOperationWriterTest method testRetryOperationFailRecoverableErrror.
@Test
public void testRetryOperationFailRecoverableErrror() throws Exception {
IndexedRecord record = new Record(MarketoConstants.getListOperationRESTSchema());
record.put(0, 12345);
record.put(1, 54321);
doReturn(getFailedSyncResult("REST", "602", "expired header")).when(client).addToList(any(ListOperationParameters.class));
doReturn(true).when(client).isErrorRecoverable(any(List.class));
props.dieOnError.setValue(false);
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(2));
assertTrue(String.valueOf(reject.get(3)).contains("602"));
}
use of org.apache.avro.generic.GenericData.Record in project components by Talend.
the class MarketoListOperationWriterTest method testRetryOperationFailDieOnError.
@Test
public void testRetryOperationFailDieOnError() throws Exception {
IndexedRecord record = new Record(MarketoConstants.getListOperationRESTSchema());
record.put(0, 12345);
record.put(1, 54321);
doReturn(false).when(client).isErrorRecoverable(any(List.class));
doReturn(getFailedSyncResult("REST", "902", "Invalid operation")).when(client).addToList(any(ListOperationParameters.class));
writer.open("test");
writer.write(record);
try {
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 MarketoListOperationWriterTest method testWriteREST.
@Test
public void testWriteREST() throws Exception {
doReturn(getFailedSyncResult(true)).when(client).addToList(any(ListOperationParameters.class));
doReturn(getSuccessSyncResult("added")).when(client).removeFromList(any(ListOperationParameters.class));
doReturn(getFailedSyncResult(true)).when(client).isMemberOfList(any(ListOperationParameters.class));
IndexedRecord record = new Record(MarketoConstants.getListOperationRESTSchema());
record.put(0, 12345);
record.put(1, 54321);
try {
writer.write(record);
fail("Should not be here");
} catch (Exception e) {
}
props.dieOnError.setValue(false);
props.multipleOperation.setValue(true);
when(sink.getProperties()).thenReturn(props);
writer.open("test");
writer.write(record);
writer.write(record);
writer.write(record);
writer.write(record);
writer.write(record);
record.put(0, 66666);
writer.write(record);
assertNotNull(writer.close());
//
doReturn(getSuccessSyncResult("added")).when(client).addToList(any(ListOperationParameters.class));
writer.open("test");
writer.write(record);
assertNotNull(writer.close());
//
props.listOperation.setValue(ListOperation.isMemberOf);
when(sink.getProperties()).thenReturn(props);
writer.open("test");
writer.write(record);
assertNotNull(writer.close());
//
props.listOperation.setValue(ListOperation.removeFrom);
when(sink.getProperties()).thenReturn(props);
writer.open("test");
writer.write(record);
assertNotNull(writer.close());
}
use of org.apache.avro.generic.GenericData.Record in project components by Talend.
the class MarketoListOperationWriterTest method testRetryOperationSuccess.
@Test
public void testRetryOperationSuccess() throws Exception {
IndexedRecord record = new Record(MarketoConstants.getListOperationRESTSchema());
record.put(0, 12345);
record.put(1, 54321);
doReturn(getSuccessSyncResult("added")).when(client).addToList(any(ListOperationParameters.class));
doReturn(false).when(client).isErrorRecoverable(any(List.class));
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 MarketoListOperationWriterTest method testRetryOperationFailNonRecoverableErrror.
@Test
public void testRetryOperationFailNonRecoverableErrror() throws Exception {
IndexedRecord record = new Record(MarketoConstants.getListOperationRESTSchema());
record.put(0, 12345);
record.put(1, 54321);
doReturn(false).when(client).isErrorRecoverable(any(List.class));
doReturn(getFailedSyncResult("REST", "902", "Invalid operation")).when(client).addToList(any(ListOperationParameters.class));
props.dieOnError.setValue(false);
when(sink.getProperties()).thenReturn(props);
writer.open("test");
writer.write(record);
MarketoResult result = (MarketoResult) writer.close();
assertEquals(1, result.apiCalls);
assertEquals(Collections.emptyList(), writer.getSuccessfulWrites());
List<IndexedRecord> rejects = writer.getRejectedWrites();
IndexedRecord reject = rejects.get(0);
assertNotNull(reject);
assertEquals("failed", reject.get(2));
assertTrue(String.valueOf(reject.get(3)).contains("902"));
}
Aggregations