@Override public void run() { channel.put(event); } });
@Override public void run() { for (Event event : events) { channel.put(event); } } });
memoryChannel.put(event); tx.commit(); tx.close();
memoryChannel.put(event);
tx.begin(); Event event = EventBuilder.withBody(msg.getBytes(), headers); memoryChannel.put(event); tx.commit(); tx.close();
@Test public void testTopicAndKeyFromHeader() { Sink kafkaSink = new KafkaSink(); Context context = prepareDefaultContext(); Configurables.configure(kafkaSink, context); Channel memoryChannel = new MemoryChannel(); Configurables.configure(memoryChannel, context); kafkaSink.setChannel(memoryChannel); kafkaSink.start(); String msg = "test-topic-and-key-from-header"; Map<String, String> headers = new HashMap<String, String>(); headers.put("topic", TestConstants.CUSTOM_TOPIC); headers.put("key", TestConstants.CUSTOM_KEY); Transaction tx = memoryChannel.getTransaction(); tx.begin(); Event event = EventBuilder.withBody(msg.getBytes(), headers); memoryChannel.put(event); tx.commit(); tx.close(); try { Sink.Status status = kafkaSink.process(); if (status == Sink.Status.BACKOFF) { fail("Error Occurred"); } } catch (EventDeliveryException ex) { // ignore } checkMessageArrived(msg, TestConstants.CUSTOM_TOPIC); }
private Sink.Status prepareAndSend(Context context, String msg) throws EventDeliveryException { Sink kafkaSink = new KafkaSink(); Configurables.configure(kafkaSink, context); Channel memoryChannel = new MemoryChannel(); Configurables.configure(memoryChannel, context); kafkaSink.setChannel(memoryChannel); kafkaSink.start(); Transaction tx = memoryChannel.getTransaction(); tx.begin(); Event event = EventBuilder.withBody(msg.getBytes()); memoryChannel.put(event); tx.commit(); tx.close(); return kafkaSink.process(); }
tx.begin(); Event event = EventBuilder.withBody(msg.getBytes(), headers); memoryChannel.put(event); tx.commit(); tx.close();
@Test public void testReplaceSubStringOfTopicWithHeaders() { String topic = TestConstants.HEADER_1_VALUE + "-topic"; Sink kafkaSink = new KafkaSink(); Context context = prepareDefaultContext(); context.put(TOPIC_CONFIG, TestConstants.HEADER_TOPIC); Configurables.configure(kafkaSink, context); Channel memoryChannel = new MemoryChannel(); Configurables.configure(memoryChannel, context); kafkaSink.setChannel(memoryChannel); kafkaSink.start(); String msg = "test-replace-substring-of-topic-with-headers"; Map<String, String> headers = new HashMap<>(); headers.put(TestConstants.HEADER_1_KEY, TestConstants.HEADER_1_VALUE); Transaction tx = memoryChannel.getTransaction(); tx.begin(); Event event = EventBuilder.withBody(msg.getBytes(), headers); memoryChannel.put(event); tx.commit(); tx.close(); try { Sink.Status status = kafkaSink.process(); if (status == Sink.Status.BACKOFF) { fail("Error Occurred"); } } catch (EventDeliveryException ex) { // ignore } checkMessageArrived(msg, topic); }
tx.begin(); Event event = EventBuilder.withBody(msg.getBytes(), headers); memoryChannel.put(event); tx.commit(); tx.close();
@Test public void testDefaultTopic() { Sink kafkaSink = new KafkaSink(); Context context = prepareDefaultContext(); Configurables.configure(kafkaSink, context); Channel memoryChannel = new MemoryChannel(); Configurables.configure(memoryChannel, context); kafkaSink.setChannel(memoryChannel); kafkaSink.start(); String msg = "default-topic-test"; Transaction tx = memoryChannel.getTransaction(); tx.begin(); Event event = EventBuilder.withBody(msg.getBytes()); memoryChannel.put(event); tx.commit(); tx.close(); try { Sink.Status status = kafkaSink.process(); if (status == Sink.Status.BACKOFF) { fail("Error Occurred"); } } catch (EventDeliveryException ex) { // ignore } checkMessageArrived(msg, DEFAULT_TOPIC); }
channel.put(event); transaction.commit(); transaction.close();
channel.put(event); transaction.commit(); transaction.close();
channel.put(event); transaction.commit(); transaction.close();
channel.put(event); transaction.commit(); transaction.close();
channel.put(event); transaction.commit(); transaction.close();
@Test public void testMissingColumnsInEvent() throws EventDeliveryException, SQLException { final String fullTableName = "FLUME_JSON_TEST"; initSinkContextWithDefaults(fullTableName); sink = new PhoenixSink(); Configurables.configure(sink, sinkContext); assertEquals(LifecycleState.IDLE, sink.getLifecycleState()); final Channel channel = this.initChannel(); sink.setChannel(channel); sink.start(); final String eventBody = "{\"col1\" : \"kalyan\", \"col3\" : [\"abc\",\"pqr\",\"xyz\"], \"col4\" : [1,2,3,4]}"; final Event event = EventBuilder.withBody(Bytes.toBytes(eventBody)); // put event in channel Transaction transaction = channel.getTransaction(); transaction.begin(); channel.put(event); transaction.commit(); transaction.close(); sink.process(); int rowsInDb = countRows(fullTableName); assertEquals(0, rowsInDb); sink.stop(); assertEquals(LifecycleState.STOP, sink.getLifecycleState()); dropTable(fullTableName); }
@Test public void testMissingColumnsInEvent() throws EventDeliveryException, SQLException { final String fullTableName = "FLUME_CSV_TEST"; initSinkContextWithDefaults(fullTableName); sink = new PhoenixSink(); Configurables.configure(sink, sinkContext); assertEquals(LifecycleState.IDLE, sink.getLifecycleState()); final Channel channel = this.initChannel(); sink.setChannel(channel); sink.start(); final String eventBody = "kalyan,\"abc,pqr,xyz\",\"1,2,3,4\""; final Event event = EventBuilder.withBody(Bytes.toBytes(eventBody)); // put event in channel Transaction transaction = channel.getTransaction(); transaction.begin(); channel.put(event); transaction.commit(); transaction.close(); sink.process(); int rowsInDb = countRows(fullTableName); assertEquals(0, rowsInDb); sink.stop(); assertEquals(LifecycleState.STOP, sink.getLifecycleState()); dropTable(fullTableName); }