Example usage for java.net InetSocketAddress createUnresolved

List of usage examples for java.net InetSocketAddress createUnresolved

Introduction

In this page you can find the example usage for java.net InetSocketAddress createUnresolved.

Prototype

public static InetSocketAddress createUnresolved(String host, int port) 

Source Link

Document

Creates an unresolved socket address from a hostname and a port number.

Usage

From source file:io.tourniquet.junit.http.rules.HttpExchangeTest.java

@Test
public void testGetSourceAddress() throws Exception {
    //prepare/*  w  ww .  j  a  va  2 s.  c om*/
    exchange.setSourceAddress(InetSocketAddress.createUnresolved("somehost", 12345));

    //act
    InetSocketAddress source = subject.getSourceAddress();

    //assert
    assertNotNull(source);
    assertEquals("somehost", source.getHostName());
    assertEquals(12345, source.getPort());
}

From source file:io.tourniquet.junit.http.rules.HttpExchangeTest.java

@Test
public void testGetDestinationAddress() throws Exception {
    //prepare/*from  www.ja v a  2 s .c o  m*/
    exchange.setDestinationAddress(InetSocketAddress.createUnresolved("somehost", 12345));

    //act
    InetSocketAddress dest = subject.getDestinationAddress();

    //assert
    assertNotNull(dest);
    assertEquals("somehost", dest.getHostName());
    assertEquals(12345, dest.getPort());
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.security.TestDelegationTokenRenewer.java

@Before
public void setUp() throws Exception {
    counter = new AtomicInteger(0);
    YarnAPIStorageFactory.setConfiguration(conf);
    RMStorageFactory.setConfiguration(conf);
    DBUtility.InitializeDB();/*from w  w w.  j a  va  2  s.c o  m*/
    conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
    UserGroupInformation.setConfiguration(conf);
    eventQueue = new LinkedBlockingQueue<Event>();
    dispatcher = new AsyncDispatcher(eventQueue);
    Renewer.reset();
    delegationTokenRenewer = createNewDelegationTokenRenewer(conf, counter);
    RMContext mockContext = mock(RMContext.class);
    ClientRMService mockClientRMService = mock(ClientRMService.class);
    when(mockContext.getSystemCredentialsForApps())
            .thenReturn(new ConcurrentHashMap<ApplicationId, ByteBuffer>());
    when(mockContext.getDelegationTokenRenewer()).thenReturn(delegationTokenRenewer);
    when(mockContext.getDispatcher()).thenReturn(dispatcher);
    when(mockContext.getClientRMService()).thenReturn(mockClientRMService);
    InetSocketAddress sockAddr = InetSocketAddress.createUnresolved("localhost", 1234);
    when(mockClientRMService.getBindAddress()).thenReturn(sockAddr);
    delegationTokenRenewer.setRMContext(mockContext);
    delegationTokenRenewer.init(conf);
    delegationTokenRenewer.start();
}

From source file:org.apache.htrace.impl.Conf.java

/**
 * Parse a hostname:port or ip:port pair.
 *
 * @param str       The string to parse.
 * @return          The socket address.//  www  . j a v a2  s.c o  m
 */
InetSocketAddress parseHostPortPair(String str) throws IOException {
    str = str.trim();
    if (str.isEmpty()) {
        throw new IOException("No hostname:port pair given.");
    }
    int bracketBegin = str.indexOf('[');
    if (bracketBegin == 0) {
        // Parse an ipv6-style address enclosed in square brackets.
        int bracketEnd = str.indexOf(']');
        if (bracketEnd < 0) {
            throw new IOException("Found left bracket, but no corresponding " + "right bracket, in " + str);
        }
        String host = str.substring(bracketBegin + 1, bracketEnd);
        int port = parseColonPort(str.substring(bracketEnd + 1));
        return InetSocketAddress.createUnresolved(host, port);
    } else if (bracketBegin > 0) {
        throw new IOException(
                "Found a left bracket that wasn't at the " + "start of the host:port pair in " + str);
    } else {
        int colon = str.indexOf(':');
        if (colon <= 0) {
            throw new IOException("No port component found in " + str);
        }
        String host = str.substring(0, colon);
        int port = parseColonPort(str.substring(colon));
        return InetSocketAddress.createUnresolved(host, port);
    }
}

From source file:org.apache.flink.yarn.CliFrontendYarnAddressConfigurationTest.java

@Test
public void testManualOptionsOverridesYarn() throws Exception {

    File emptyFolder = temporaryFolder.newFolder();
    File testConfFile = new File(emptyFolder.getAbsolutePath(), "flink-conf.yaml");
    Files.createFile(testConfFile.toPath());

    TestCLI frontend = new TestCLI(emptyFolder.getAbsolutePath());

    RunOptions options = CliFrontendParser.parseRunCommand(new String[] { "-m", "10.221.130.22:7788" });

    frontend.retrieveClient(options);//from  w w  w . java2s .  c  o  m

    Configuration config = frontend.getConfiguration();

    InetSocketAddress expectedAddress = InetSocketAddress.createUnresolved("10.221.130.22", 7788);

    checkJobManagerAddress(config, expectedAddress.getHostName(), expectedAddress.getPort());

}

From source file:org.apache.maven.wagon.providers.http.LightweightHttpWagon.java

public SocketAddress getSocketAddress(ProxyInfo proxyInfo) {
    return InetSocketAddress.createUnresolved(proxyInfo.getHost(), proxyInfo.getPort());
}

From source file:com.googlecode.gmail4j.javamail.ImapGmailConnection.java

public void setProxy(final String host, final int port) {
    setProxy(new Proxy(Type.HTTP, InetSocketAddress.createUnresolved(host, port)));
}

From source file:org.apache.qpid.server.management.plugin.servlet.rest.AbstractServlet.java

protected SocketAddress getSocketAddress(HttpServletRequest request) {
    return InetSocketAddress.createUnresolved(request.getServerName(), request.getServerPort());
}

From source file:com.datatorrent.stram.StramRecoveryTest.java

@Test
public void testWriteAheadLog() throws Exception {
    final MutableInt flushCount = new MutableInt();
    final MutableBoolean isClosed = new MutableBoolean(false);
    dag.setAttribute(OperatorContext.STORAGE_AGENT, new FSStorageAgent(testMeta.getPath(), null));

    TestGeneratorInputOperator o1 = dag.addOperator("o1", TestGeneratorInputOperator.class);
    StreamingContainerManager scm = new StreamingContainerManager(dag);
    PhysicalPlan plan = scm.getPhysicalPlan();
    Journal j = scm.getJournal();/*from ww  w .  j  av a2 s .c om*/
    ByteArrayOutputStream bos = new ByteArrayOutputStream() {
        @Override
        public void flush() throws IOException {
            super.flush();
            flushCount.increment();
        }

        @Override
        public void close() throws IOException {
            super.close();
            isClosed.setValue(true);
        }
    };
    j.setOutputStream(new DataOutputStream(bos));

    PTOperator o1p1 = plan.getOperators(dag.getMeta(o1)).get(0);
    assertEquals(PTOperator.State.PENDING_DEPLOY, o1p1.getState());
    String externalId = new MockContainer(scm, o1p1.getContainer()).container.getExternalId();
    assertEquals("flush count", 1, flushCount.intValue());

    o1p1.setState(PTOperator.State.ACTIVE);
    assertEquals(PTOperator.State.ACTIVE, o1p1.getState());
    assertEquals("flush count", 2, flushCount.intValue());
    assertEquals("is closed", false, isClosed.booleanValue());

    // this will close the stream. There are 2 calls to flush() during the close() - one in Kryo Output and one
    // in FilterOutputStream
    j.setOutputStream(null);
    assertEquals("flush count", 4, flushCount.intValue());
    assertEquals("is closed", true, isClosed.booleanValue());

    // output stream is closed, so state will be changed without recording it in the journal
    o1p1.setState(PTOperator.State.INACTIVE);
    assertEquals(PTOperator.State.INACTIVE, o1p1.getState());
    assertEquals("flush count", 4, flushCount.intValue());

    ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
    j.replay(new DataInputStream(bis));
    assertEquals(PTOperator.State.ACTIVE, o1p1.getState());

    InetSocketAddress addr1 = InetSocketAddress.createUnresolved("host1", 1);
    PTContainer c1 = plan.getContainers().get(0);
    c1.setState(PTContainer.State.ALLOCATED);
    c1.host = "host1";
    c1.bufferServerAddress = addr1;
    c1.setAllocatedMemoryMB(2);
    c1.setRequiredMemoryMB(1);
    c1.setAllocatedVCores(3);
    c1.setRequiredVCores(4);

    j.setOutputStream(new DataOutputStream(bos));
    j.write(c1.getSetContainerState());

    c1.setExternalId(null);
    c1.setState(PTContainer.State.NEW);
    c1.setExternalId(null);
    c1.host = null;
    c1.bufferServerAddress = null;

    bis = new ByteArrayInputStream(bos.toByteArray());
    j.replay(new DataInputStream(bis));

    assertEquals(externalId, c1.getExternalId());
    assertEquals(PTContainer.State.ALLOCATED, c1.getState());
    assertEquals("host1", c1.host);
    assertEquals(addr1, c1.bufferServerAddress);
    assertEquals(1, c1.getRequiredMemoryMB());
    assertEquals(2, c1.getAllocatedMemoryMB());
    assertEquals(3, c1.getAllocatedVCores());
    assertEquals(4, c1.getRequiredVCores());

    j.write(scm.getSetOperatorProperty("o1", "maxTuples", "100"));
    o1.setMaxTuples(10);
    j.setOutputStream(null);
    bis = new ByteArrayInputStream(bos.toByteArray());
    j.replay(new DataInputStream(bis));
    assertEquals(100, o1.getMaxTuples());

    j.setOutputStream(new DataOutputStream(bos));
    scm.setOperatorProperty("o1", "maxTuples", "10");
    assertEquals(10, o1.getMaxTuples());
    o1.setMaxTuples(100);
    assertEquals(100, o1.getMaxTuples());
    j.setOutputStream(null);

    bis = new ByteArrayInputStream(bos.toByteArray());
    j.replay(new DataInputStream(bis));
    assertEquals(10, o1.getMaxTuples());

    j.setOutputStream(new DataOutputStream(bos));
    scm.setPhysicalOperatorProperty(o1p1.getId(), "maxTuples", "50");
}

From source file:org.apache.qpid.server.store.berkeleydb.BDBHAMessageStore.java

private ReplicationGroupAdmin createReplicationGroupAdmin() {
    final Set<InetSocketAddress> helpers = new HashSet<InetSocketAddress>();
    helpers.addAll(getReplicatedEnvironment().getRepConfig().getHelperSockets());

    final ReplicationConfig repConfig = getReplicatedEnvironment().getRepConfig();
    helpers.add(InetSocketAddress.createUnresolved(repConfig.getNodeHostname(), repConfig.getNodePort()));

    return new ReplicationGroupAdmin(_groupName, helpers);
}