Search in sources :

Example 86 with Record

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"));
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) TMarketoOutputProperties(org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties) Record(org.apache.avro.generic.GenericData.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 87 with Record

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);
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) TMarketoOutputProperties(org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties) Record(org.apache.avro.generic.GenericData.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 88 with Record

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"));
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) TMarketoOutputProperties(org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties) Record(org.apache.avro.generic.GenericData.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 89 with Record

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());
// 
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) ListOperationParameters(org.talend.components.marketo.runtime.client.type.ListOperationParameters) Record(org.apache.avro.generic.GenericData.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) Test(org.junit.Test)

Example 90 with Record

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;
}
Also used : Record(org.apache.avro.generic.GenericData.Record)

Aggregations

Record (org.apache.avro.generic.GenericData.Record)96 Test (org.junit.Test)44 IndexedRecord (org.apache.avro.generic.IndexedRecord)43 Schema (org.apache.avro.Schema)33 ArrayList (java.util.ArrayList)24 GenericRecord (org.apache.avro.generic.GenericRecord)14 Field (org.apache.avro.Schema.Field)11 List (java.util.List)10 GenericData (org.apache.avro.generic.GenericData)10 TestRunner (org.apache.nifi.util.TestRunner)8 GenericRecordBuilder (org.apache.avro.generic.GenericRecordBuilder)7 JsonObject (com.google.gson.JsonObject)6 DataFileStream (org.apache.avro.file.DataFileStream)6 DataFileWriter (org.apache.avro.file.DataFileWriter)6 GenericDatumReader (org.apache.avro.generic.GenericDatumReader)6 Utf8 (org.apache.avro.util.Utf8)6 TMarketoOutputProperties (org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties)6 ActivityRecord (com.marketo.mktows.ActivityRecord)5 ArrayOfLeadRecord (com.marketo.mktows.ArrayOfLeadRecord)5 LeadChangeRecord (com.marketo.mktows.LeadChangeRecord)5