Java Code Examples for org.apache.nifi.remote.client.SiteToSiteClient#createTransaction()
The following examples show how to use
org.apache.nifi.remote.client.SiteToSiteClient#createTransaction() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSiteToSiteClient.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test @Ignore("For local testing only; not really a unit test but a manual test") public void testReceive() throws IOException { System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.remote", "DEBUG"); final SiteToSiteClient client = new SiteToSiteClient.Builder() .url("http://localhost:8080/nifi") .portName("cba") .requestBatchCount(10) .build(); try { for (int i = 0; i < 1000; i++) { final Transaction transaction = client.createTransaction(TransferDirection.RECEIVE); Assert.assertNotNull(transaction); DataPacket packet; while (true) { packet = transaction.receive(); if (packet == null) { break; } final InputStream in = packet.getData(); final long size = packet.getSize(); final byte[] buff = new byte[(int) size]; StreamUtils.fillBuffer(in, buff); } transaction.confirm(); transaction.complete(); } } finally { client.close(); } }
Example 2
Source File: TestSiteToSiteClient.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test @Ignore("For local testing only; not really a unit test but a manual test") public void testSend() throws IOException { System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.remote", "DEBUG"); final SiteToSiteClient client = new SiteToSiteClient.Builder() .url("http://localhost:8080/nifi") .portName("input") .build(); try { final Transaction transaction = client.createTransaction(TransferDirection.SEND); Assert.assertNotNull(transaction); final Map<String, String> attrs = new HashMap<>(); attrs.put("site-to-site", "yes, please!"); final byte[] bytes = "Hello".getBytes(); final ByteArrayInputStream bais = new ByteArrayInputStream(bytes); final DataPacket packet = new StandardDataPacket(attrs, bais, bytes.length); transaction.send(packet); transaction.confirm(); transaction.complete(); } finally { client.close(); } }
Example 3
Source File: TestHttpClient.java From localization_nifi with Apache License 2.0 | 5 votes |
private static void testSendIgnoreProxyError(final SiteToSiteClient client, final SendData function) throws IOException { final boolean isProxyEnabled = client.getConfig().getHttpProxy() != null; try { final Transaction transaction = client.createTransaction(TransferDirection.SEND); if (isProxyEnabled && transaction == null) { // Transaction is not created sometimes at AppVeyor. logger.warn("Transaction was not created. Most likely an environment dependent issue."); return; } assertNotNull(transaction); function.apply(transaction); transaction.confirm(); transaction.complete(); } catch (final IOException e) { if (isProxyEnabled && e.getMessage().contains("504")) { // Gateway Timeout happens sometimes at Travis CI. logger.warn("Request timeout. Most likely an environment dependent issue.", e); } else { throw e; } } }
Example 4
Source File: TestHttpClient.java From localization_nifi with Apache License 2.0 | 5 votes |
private void testReceive(SiteToSiteClient client) throws IOException { final Transaction transaction = client.createTransaction(TransferDirection.RECEIVE); assertNotNull(transaction); DataPacket packet; while ((packet = transaction.receive()) != null) { consumeDataPacket(packet); } transaction.confirm(); transaction.complete(); }
Example 5
Source File: TestSiteToSiteClient.java From nifi with Apache License 2.0 | 5 votes |
@Test @Ignore("For local testing only; not really a unit test but a manual test") public void testReceive() throws IOException { System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.remote", "DEBUG"); final SiteToSiteClient client = new SiteToSiteClient.Builder() .url("http://localhost:8080/nifi") .portName("cba") .requestBatchCount(10) .build(); try { for (int i = 0; i < 1000; i++) { final Transaction transaction = client.createTransaction(TransferDirection.RECEIVE); Assert.assertNotNull(transaction); DataPacket packet; while (true) { packet = transaction.receive(); if (packet == null) { break; } final InputStream in = packet.getData(); final long size = packet.getSize(); final byte[] buff = new byte[(int) size]; StreamUtils.fillBuffer(in, buff); } transaction.confirm(); transaction.complete(); } } finally { client.close(); } }
Example 6
Source File: TestSiteToSiteClient.java From nifi with Apache License 2.0 | 5 votes |
@Test @Ignore("For local testing only; not really a unit test but a manual test") public void testSend() throws IOException { System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.remote", "DEBUG"); final SiteToSiteClient client = new SiteToSiteClient.Builder() .url("http://localhost:8080/nifi") .portName("input") .build(); try { final Transaction transaction = client.createTransaction(TransferDirection.SEND); Assert.assertNotNull(transaction); final Map<String, String> attrs = new HashMap<>(); attrs.put("site-to-site", "yes, please!"); final byte[] bytes = "Hello".getBytes(); final ByteArrayInputStream bais = new ByteArrayInputStream(bytes); final DataPacket packet = new StandardDataPacket(attrs, bais, bytes.length); transaction.send(packet); transaction.confirm(); transaction.complete(); } finally { client.close(); } }
Example 7
Source File: TestHttpClient.java From nifi with Apache License 2.0 | 5 votes |
private static void testSendIgnoreProxyError(final SiteToSiteClient client, final SendData function) throws IOException { final boolean isProxyEnabled = client.getConfig().getHttpProxy() != null; try { final Transaction transaction = client.createTransaction(TransferDirection.SEND); if (isProxyEnabled && transaction == null) { // Transaction is not created sometimes at AppVeyor. logger.warn("Transaction was not created. Most likely an environment dependent issue."); return; } assertNotNull(transaction); function.apply(transaction); transaction.confirm(); transaction.complete(); } catch (final IOException e) { if (isProxyEnabled && e.getMessage().contains("504")) { // Gateway Timeout happens sometimes at Travis CI. logger.warn("Request timeout. Most likely an environment dependent issue.", e); } else { throw e; } } }
Example 8
Source File: TestHttpClient.java From nifi with Apache License 2.0 | 5 votes |
private void testReceive(SiteToSiteClient client) throws IOException { final Transaction transaction = client.createTransaction(TransferDirection.RECEIVE); assertNotNull(transaction); DataPacket packet; while ((packet = transaction.receive()) != null) { consumeDataPacket(packet); } transaction.confirm(); transaction.complete(); }