@Test public void registerWritesUrlEncodedFiltersAndNewlineToOutputStream() throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); FilterRegistry registry = new FilterRegistry(anyInputStream(), outputStream); registry.register(FILTERS); assertEquals(URL_ENCODED_FILTERS + NEW_LINE, new String(outputStream.toByteArray())); }
/** * Registers the given filters with Ryuk * * @param filters the filter to register * @return true if the filters have been registered successfuly, false otherwise * @throws IOException if communication with Ryuk fails */ protected boolean register(List<Map.Entry<String, String>> filters) throws IOException { String query = URLEncodedUtils.format( filters.stream() .map(it -> new BasicNameValuePair(it.getKey(), it.getValue())) .collect(Collectors.toList()), (String) null ); log.debug("Sending '{}' to Ryuk", query); out.write(query.getBytes()); out.write('\n'); out.flush(); return waitForAcknowledgment(in); }
int index = 0; try (Socket clientSocket = new Socket(hostIpAddress, ryukPort)) { FilterRegistry registry = new FilterRegistry(clientSocket.getInputStream(), clientSocket.getOutputStream()); synchronized (DEATH_NOTE) { while (true) { boolean isAcknowledged = registry.register(filters); if (isAcknowledged) { log.debug("Received \'ACK\' from Ryuk");
/** * Registers the given filters with Ryuk * * @param filters the filter to register * @return true if the filters have been registered successfuly, false otherwise * @throws IOException if communication with Ryuk fails */ protected boolean register(List<Map.Entry<String, String>> filters) throws IOException { String query = URLEncodedUtils.format(filters.stream().map(it -> new BasicNameValuePair(it.getKey(), it.getValue())).collect(Collectors.toList()), (String) null); log.debug("Sending \'{}\' to Ryuk", query); out.write(query.getBytes()); out.write('\n'); out.flush(); return waitForAcknowledgment(in); }
@Test public void registerReturnsTrueIfAcknowledgementIsReadFromInputStream() throws IOException { FilterRegistry registry = new FilterRegistry(inputStream(ACKNOWLEDGEMENT), anyOutputStream()); boolean successful = registry.register(FILTERS); assertTrue(successful); }
@Test public void registerReturnsFalseIfNoAcknowledgementIsReadFromInputStream() throws IOException { FilterRegistry registry = new FilterRegistry(inputStream(NO_ACKNOWLEDGEMENT), anyOutputStream()); boolean successful = registry.register(FILTERS); assertFalse(successful); }