@VisibleForTesting protected static Map<String, String> executeGetRequest(HttpGet getRequest) throws IOException { // Make the call, get response @Cleanup CloseableHttpClient httpClient = getHttpClient(); HttpResponse response = httpClient.execute(getRequest); return AzkabanClient.handleResponse(response); }
@VisibleForTesting protected static Map<String, String> executePostRequest(HttpPost postRequest) throws IOException { // Make the call, get response @Cleanup CloseableHttpClient httpClient = getHttpClient(); HttpResponse response = httpClient.execute(postRequest); return AzkabanClient.handleResponse(response); }
@edu.umd.cs.findbugs.annotations.SuppressWarnings( value = "OBL_UNSATISFIED_OBLIGATION", justification = "Lombok construct of @Cleanup is handing this, but not detected by FindBugs") private static void addFilesToZip(File zipFile, List<File> filesToAdd) throws IOException { try { @Cleanup OutputStream archiveStream = new FileOutputStream(zipFile); @Cleanup ArchiveOutputStream archive = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream); for (File fileToAdd : filesToAdd) { ZipArchiveEntry entry = new ZipArchiveEntry(fileToAdd.getName()); archive.putArchiveEntry(entry); @Cleanup BufferedInputStream input = new BufferedInputStream(new FileInputStream(fileToAdd)); IOUtils.copy(input, archive); archive.closeArchiveEntry(); } archive.finish(); } catch (ArchiveException e) { throw new IOException("Issue with creating archive", e); } }
private static String uploadZipFileToAzkaban(String sessionId, String azkabanServerUrl, String azkabanProjectName, String jobZipFile) throws IOException { // Create post request HttpPost postRequest = new HttpPost(azkabanServerUrl + "/manager"); HttpEntity entity = MultipartEntityBuilder .create() .addTextBody("session.id", sessionId) .addTextBody("ajax", "upload") .addBinaryBody("file", new File(jobZipFile), ContentType.create("application/zip"), azkabanProjectName + ".zip") .addTextBody("project", azkabanProjectName) .build(); postRequest.setEntity(entity); // Make the call, get response @Cleanup CloseableHttpClient httpClient = getHttpClient(); HttpResponse response = httpClient.execute(postRequest); // Obtaining projectId is hard. Uploading zip file is one avenue to get it from Azkaban return AzkabanClient.handleResponse(response).get("projectId"); }
@BeforeClass public static void setupContent() throws FileNotFoundException { contentFolder.mkdir(); contentFolder.setReadable(true, false); contentFolder.setWritable(true, false); contentFolder.setExecutable(true, false); File indexFile = new File(contentFolder, "index.html"); indexFile.setReadable(true, false); indexFile.setWritable(true, false); indexFile.setExecutable(true, false); @Cleanup PrintStream printStream = new PrintStream(new FileOutputStream(indexFile)); printStream.println("<html><body>This worked</body></html>"); }
@SuppressWarnings({"Duplicates", "ResultOfMethodCallIgnored"}) @BeforeClass public static void setupContent() throws FileNotFoundException { contentFolder.mkdir(); contentFolder.setReadable(true, false); contentFolder.setWritable(true, false); contentFolder.setExecutable(true, false); File indexFile = new File(contentFolder, "index.html"); indexFile.setReadable(true, false); indexFile.setWritable(true, false); indexFile.setExecutable(true, false); @Cleanup PrintStream printStream = new PrintStream(new FileOutputStream(indexFile)); printStream.println("<html><body>This worked</body></html>"); }
private TarArchiveInputStream intoTarArchive(Consumer<TarArchiveOutputStream> consumer) throws IOException { @Cleanup final ByteArrayOutputStream baos = new ByteArrayOutputStream(); @Cleanup final TarArchiveOutputStream taos = new TarArchiveOutputStream(baos); consumer.accept(taos); taos.close(); return new TarArchiveInputStream(new ByteArrayInputStream(baos.toByteArray())); }
@Test public void testSimple() throws Exception { info("Base URL is " + nginx.getBaseUrl("http", 80)); URLConnection urlConnection = nginx.getBaseUrl("http", 80).openConnection(); @Cleanup BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String line = reader.readLine(); System.out.println(line); assertTrue("Using URLConnection, an HTTP GET from the nginx server returns the index.html from the custom content directory", line.contains("This worked")); } }
private static String responseFromMockserver(MockServerContainer mockServer, String expectedBody, String path) throws IOException { new MockServerClient(mockServer.getContainerIpAddress(), mockServer.getServerPort()) .when(request(path)) .respond(response(expectedBody)); URLConnection urlConnection = new URL(mockServer.getEndpoint() + path).openConnection(); @Cleanup BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); return reader.readLine(); } }
@Test public void noTrailingSlashesInTarEntryNames() throws Exception { final MountableFile mountableFile = MountableFile.forClasspathResource("mappable-resource/test-resource.txt"); @Cleanup final TarArchiveInputStream tais = intoTarArchive((taos) -> { mountableFile.transferTo(taos, "/some/path.txt"); mountableFile.transferTo(taos, "/path.txt"); mountableFile.transferTo(taos, "path.txt"); }); ArchiveEntry entry; while ((entry = tais.getNextEntry()) != null) { assertFalse("no entries should have a trailing slash", entry.getName().endsWith("/")); } }
/** * Tests the RandomRevisionDataOutput class with an fixed-length RandomAccessOutputStream. */ @Test public void testRandomOutputFixed() throws Exception { final int bufferSize = 1024 * 1024; @Cleanup val s = new FixedByteArrayOutputStream(new byte[bufferSize], 0, bufferSize); @Cleanup val impl = RevisionDataOutputStream.wrap(s); testImpl(impl, s::getData); }
@Test(timeout = 10000) public void generateStreamCutSuccess() { when(synchronizer.getState()).thenReturn(state); when(state.isCheckpointComplete(any(String.class))).thenReturn(false).thenReturn(true); when(state.getStreamCutsForCompletedCheckpoint(anyString())).thenReturn(Optional.of(ImmutableMap.of(createStream("s1"), createStreamCut("s1", 2)))); @Cleanup("shutdown") InlineExecutor executor = new InlineExecutor(); CompletableFuture<Map<Stream, StreamCut>> result = readerGroup.generateStreamCuts(executor); assertEquals(createStreamCut("s1", 2), result.join().get(createStream("s1"))); }
void writeEvents(EventStreamClientFactory clientFactory, String streamName, int totalEvents, int initialPoint) { @Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(streamName, new JavaSerializer<>(), EventWriterConfig.builder().build()); for (int i = initialPoint; i < totalEvents + initialPoint; i++) { writer.writeEvent(String.valueOf(i)).join(); log.debug("Writing event: {} to stream {}.", streamName + String.valueOf(i), streamName); } }
private void writeTestEvent(String scope, String streamName, int eventId) { @Cleanup EventStreamClientFactory clientFactory = EventStreamClientFactory.withScope(scope, ClientConfig.builder().controllerURI(controllerURI).build()); @Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(streamName, new JavaSerializer<>(), EventWriterConfig.builder().build()); writer.writeEvent( "0", Integer.toString(eventId)).join(); }
@Test(timeout = 5000) public void testAvailable() throws Exception { @Cleanup ByteStreamWriter writer = clientFactory.createByteStreamWriter(STREAM); @Cleanup ByteStreamReader reader = clientFactory.createByteStreamReader(STREAM); assertEquals(0, reader.available()); byte[] value = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; writer.write(value); writer.flush(); assertEquals(10, reader.available()); }
@Test(timeout = 5000) public void testSingleByteWrite() throws Exception { @Cleanup ByteStreamWriter writer = clientFactory.createByteStreamWriter(STREAM); int numBytes = BufferedByteStreamWriterImpl.BUFFER_SIZE * 2 + 1; for (int i = 0; i < numBytes; i++) { writer.write(i); } writer.flush(); assertEquals(numBytes, writer.fetchTailOffset()); }
@Override public void createReaderGroup(String groupName, ReaderGroupConfig config) { NameUtils.validateReaderGroupName(groupName); createStreamHelper(NameUtils.getStreamForReaderGroup(groupName), StreamConfiguration.builder() .scalingPolicy(ScalingPolicy.fixed(1)).build()); @Cleanup StateSynchronizer<ReaderGroupState> synchronizer = clientFactory.createStateSynchronizer(NameUtils.getStreamForReaderGroup(groupName), new ReaderGroupStateUpdatesSerializer(), new ReaderGroupStateInitSerializer(), SynchronizerConfig.builder().build()); Map<Segment, Long> segments = ReaderGroupImpl.getSegmentsForStreams(controller, config); synchronizer.initialize(new ReaderGroupState.ReaderGroupStateInit(config, segments, getEndSegmentsForStreams(config))); }