Search in sources :

Example 81 with URL

use of java.net.URL in project flink by apache.

the class StreamExecutionEnvironmentTest method testDefaultParallelismIsDefault.

@Test
public void testDefaultParallelismIsDefault() {
    assertEquals(ExecutionConfig.PARALLELISM_DEFAULT, StreamExecutionEnvironment.createLocalEnvironment().getParallelism());
    assertEquals(ExecutionConfig.PARALLELISM_DEFAULT, StreamExecutionEnvironment.createRemoteEnvironment("dummy", 1234).getParallelism());
    StreamExecutionEnvironment contextEnv = new StreamContextEnvironment(new ContextEnvironment(mock(ClusterClient.class), Collections.<URL>emptyList(), Collections.<URL>emptyList(), this.getClass().getClassLoader(), null));
    assertEquals(ExecutionConfig.PARALLELISM_DEFAULT, contextEnv.getParallelism());
}
Also used : ContextEnvironment(org.apache.flink.client.program.ContextEnvironment) URL(java.net.URL) Test(org.junit.Test)

Example 82 with URL

use of java.net.URL in project hadoop by apache.

the class AuthenticatorTestCase method _testAuthentication.

protected void _testAuthentication(Authenticator authenticator, boolean doPost) throws Exception {
    start();
    try {
        URL url = new URL(getBaseURL());
        AuthenticatedURL.Token token = new AuthenticatedURL.Token();
        Assert.assertFalse(token.isSet());
        TestConnectionConfigurator connConf = new TestConnectionConfigurator();
        AuthenticatedURL aUrl = new AuthenticatedURL(authenticator, connConf);
        HttpURLConnection conn = aUrl.openConnection(url, token);
        Assert.assertTrue(connConf.invoked);
        String tokenStr = token.toString();
        if (doPost) {
            conn.setRequestMethod("POST");
            conn.setDoOutput(true);
        }
        conn.connect();
        if (doPost) {
            Writer writer = new OutputStreamWriter(conn.getOutputStream());
            writer.write(POST);
            writer.close();
        }
        Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
        if (doPost) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String echo = reader.readLine();
            Assert.assertEquals(POST, echo);
            Assert.assertNull(reader.readLine());
        }
        aUrl = new AuthenticatedURL();
        conn = aUrl.openConnection(url, token);
        conn.connect();
        Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
        Assert.assertEquals(tokenStr, token.toString());
    } finally {
        stop();
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) URL(java.net.URL) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Example 83 with URL

use of java.net.URL in project hadoop by apache.

the class TestKerberosAuthenticator method testNotAuthenticated.

@Test(timeout = 60000)
public void testNotAuthenticated() throws Exception {
    AuthenticatorTestCase auth = new AuthenticatorTestCase(useTomcat);
    AuthenticatorTestCase.setAuthenticationHandlerConfig(getAuthenticationHandlerConfiguration());
    auth.start();
    try {
        URL url = new URL(auth.getBaseURL());
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.connect();
        Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, conn.getResponseCode());
        Assert.assertTrue(conn.getHeaderField(KerberosAuthenticator.WWW_AUTHENTICATE) != null);
    } finally {
        auth.stop();
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) URL(java.net.URL) Test(org.junit.Test)

Example 84 with URL

use of java.net.URL in project hadoop by apache.

the class TestPseudoAuthenticator method testAnonymousAllowed.

@Test
public void testAnonymousAllowed() throws Exception {
    AuthenticatorTestCase auth = new AuthenticatorTestCase();
    AuthenticatorTestCase.setAuthenticationHandlerConfig(getAuthenticationHandlerConfiguration(true));
    auth.start();
    try {
        URL url = new URL(auth.getBaseURL());
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.connect();
        Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
    } finally {
        auth.stop();
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) URL(java.net.URL) Test(org.junit.Test)

Example 85 with URL

use of java.net.URL in project hadoop by apache.

the class WhoClient method main.

public static void main(String[] args) {
    try {
        if (args.length != 1) {
            System.err.println("Usage: <URL>");
            System.exit(-1);
        }
        AuthenticatedURL.Token token = new AuthenticatedURL.Token();
        URL url = new URL(args[0]);
        HttpURLConnection conn = new AuthenticatedURL().openConnection(url, token);
        System.out.println();
        System.out.println("Token value: " + token);
        System.out.println("Status code: " + conn.getResponseCode() + " " + conn.getResponseMessage());
        System.out.println();
        if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), Charset.forName("UTF-8")));
            String line = reader.readLine();
            while (line != null) {
                System.out.println(line);
                line = reader.readLine();
            }
            reader.close();
        }
        System.out.println();
    } catch (Exception ex) {
        System.err.println("ERROR: " + ex.getMessage());
        System.exit(-1);
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) AuthenticatedURL(org.apache.hadoop.security.authentication.client.AuthenticatedURL) URL(java.net.URL) AuthenticatedURL(org.apache.hadoop.security.authentication.client.AuthenticatedURL)

Aggregations

URL (java.net.URL)8112 IOException (java.io.IOException)2006 Test (org.junit.Test)1653 File (java.io.File)1638 MalformedURLException (java.net.MalformedURLException)1165 HttpURLConnection (java.net.HttpURLConnection)1030 InputStream (java.io.InputStream)1028 ArrayList (java.util.ArrayList)633 URLConnection (java.net.URLConnection)515 InputStreamReader (java.io.InputStreamReader)473 URLClassLoader (java.net.URLClassLoader)451 BufferedReader (java.io.BufferedReader)390 HashMap (java.util.HashMap)361 URISyntaxException (java.net.URISyntaxException)286 URI (java.net.URI)269 Map (java.util.Map)259 FileInputStream (java.io.FileInputStream)227 List (java.util.List)205 FileOutputStream (java.io.FileOutputStream)194 OutputStream (java.io.OutputStream)194