@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("/")); } }
private SegmentInfo segmentToInfo(Segment s) { @Cleanup SegmentMetadataClient client = segmentMetadataClientFactory.createSegmentMetadataClient(s, latestDelegationToken.get()); return client.getSegmentInfo(); } }
protected void createScope(final String scopeName) { @Cleanup Controller controller = Exceptions.handleInterruptedCall(controllerWrapper::getController); controller.createScope(scopeName).join(); }
@Test(expected = InvalidMessageException.class) public void testAppendWithoutSetup() throws Exception { int size = 10; @Cleanup("release") ByteBuf fakeNetwork = ByteBufAllocator.DEFAULT.buffer(); append(streamName, writerId, 0, 1, size, fakeNetwork); }
@Test(expected = IllegalArgumentException.class) public void testReadWithInvalidEndOffset() { AsyncSegmentInputStream mockAsyncInputStream = mock(AsyncSegmentInputStream.class); //Set the end offset which is less than startOffset @Cleanup EventSegmentReaderImpl stream = SegmentInputStreamFactoryImpl.getEventSegmentReader(mockAsyncInputStream, 10, 9, SegmentInputStreamImpl.DEFAULT_BUFFER_SIZE); }