Search in sources :

Example 36 with Connection

use of com.google.cloud.bigquery.connection.v1.Connection in project jboss-remoting by jboss-remoting.

the class RemoteChannelTest method testRefused.

@Test
public void testRefused() throws Exception {
    IoFuture<Connection> futureConnection = endpoint.connect(new URI("remote://localhost:33123"), OptionMap.EMPTY);
    try {
        futureConnection.awaitInterruptibly(2L, TimeUnit.SECONDS);
        if (futureConnection.getStatus() == IoFuture.Status.WAITING) {
            futureConnection.cancel();
        } else {
            safeClose(futureConnection.get());
        }
    } catch (IOException expected) {
        System.out.println("Exception is: " + expected);
        System.out.flush();
        if (expected.getMessage().toLowerCase(Locale.US).contains("refused")) {
            return;
        }
    }
    fail("Expected an IOException with 'refused' in the string");
}
Also used : Connection(org.jboss.remoting3.Connection) IOException(java.io.IOException) URI(java.net.URI) Test(org.junit.Test)

Example 37 with Connection

use of com.google.cloud.bigquery.connection.v1.Connection in project jboss-remoting by jboss-remoting.

the class TimeOutConnectionTestCase method doTest.

private void doTest(OptionMap connectionProviderOptions) throws Exception {
    try (final ServerSocketChannel channel = ServerSocketChannel.open()) {
        channel.configureBlocking(true);
        channel.socket().bind(new InetSocketAddress("localhost", 30123));
        Thread acceptThread = new Thread(new Accept(channel));
        acceptThread.start();
        // create endpoint, auth provider, etc, create server
        final EndpointBuilder endpointBuilder = Endpoint.builder();
        final XnioWorker.Builder workerBuilder = endpointBuilder.buildXnioWorker(Xnio.getInstance());
        workerBuilder.setCoreWorkerPoolSize(4).setMaxWorkerPoolSize(4).setWorkerIoThreads(4);
        endpointBuilder.setEndpointName("test");
        try (Endpoint ep = endpointBuilder.build()) {
            endpoint = ep;
            final SecurityDomain.Builder domainBuilder = SecurityDomain.builder();
            final SimpleMapBackedSecurityRealm mainRealm = new SimpleMapBackedSecurityRealm();
            domainBuilder.addRealm("mainRealm", mainRealm);
            domainBuilder.setDefaultRealmName("mainRealm");
            final PasswordFactory passwordFactory = PasswordFactory.getInstance("clear");
            mainRealm.setPasswordMap("bob", passwordFactory.generatePassword(new ClearPasswordSpec("pass".toCharArray())));
            // create connect and close endpoint threads
            IoFuture<Connection> futureConnection = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.empty().useName("bob").usePassword("pass")).run(new PrivilegedAction<IoFuture<Connection>>() {

                public IoFuture<Connection> run() {
                    try {
                        return ep.connect(new URI("remote://localhost:30123"), OptionMap.EMPTY);
                    } catch (URISyntaxException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
            assertEquals(Status.WAITING, futureConnection.await(500, TimeUnit.MILLISECONDS));
            ep.close();
            assertEquals(Status.CANCELLED, futureConnection.getStatus());
            acceptThread.join();
        } finally {
            endpoint = null;
        }
    }
}
Also used : SimpleMapBackedSecurityRealm(org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm) InetSocketAddress(java.net.InetSocketAddress) XnioWorker(org.xnio.XnioWorker) Connection(org.jboss.remoting3.Connection) EndpointBuilder(org.jboss.remoting3.EndpointBuilder) ClearPasswordSpec(org.wildfly.security.password.spec.ClearPasswordSpec) IoFuture(org.xnio.IoFuture) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain) PasswordFactory(org.wildfly.security.password.PasswordFactory) Endpoint(org.jboss.remoting3.Endpoint) ServerSocketChannel(java.nio.channels.ServerSocketChannel)

Example 38 with Connection

use of com.google.cloud.bigquery.connection.v1.Connection in project jboss-remoting by jboss-remoting.

the class HeartbeatTestCase method testDefaultHeartbeat.

/**
 * Test that heartbeat can be set and can be disabled by setting it to 0
 *
 * @throws Exception
 */
@Test
public void testDefaultHeartbeat() throws Exception {
    Channel clientChannel = null;
    Channel serverChannel = null;
    Closeable streamServer = null;
    Connection connection = null;
    Registration serviceRegistration = null;
    final Endpoint endpoint = Endpoint.builder().setEndpointName("test").build();
    NetworkServerProvider networkServerProvider = endpoint.getConnectionProviderInterface("remote", NetworkServerProvider.class);
    final SecurityDomain.Builder domainBuilder = SecurityDomain.builder();
    final SimpleMapBackedSecurityRealm mainRealm = new SimpleMapBackedSecurityRealm();
    domainBuilder.addRealm("mainRealm", mainRealm).build();
    domainBuilder.setDefaultRealmName("mainRealm");
    domainBuilder.setPermissionMapper((permissionMappable, roles) -> PermissionVerifier.ALL);
    final PasswordFactory passwordFactory = PasswordFactory.getInstance("clear");
    mainRealm.setPasswordMap("bob", passwordFactory.generatePassword(new ClearPasswordSpec("pass".toCharArray())));
    final SaslServerFactory saslServerFactory = new ServiceLoaderSaslServerFactory(HeartbeatTestCase.class.getClassLoader());
    final SaslAuthenticationFactory.Builder builder = SaslAuthenticationFactory.builder();
    builder.setSecurityDomain(domainBuilder.build());
    builder.setFactory(saslServerFactory);
    builder.setMechanismConfigurationSelector(mechanismInformation -> SaslMechanismInformation.Names.SCRAM_SHA_256.equals(mechanismInformation.getMechanismName()) ? MechanismConfiguration.EMPTY : null);
    final SaslAuthenticationFactory saslAuthenticationFactory = builder.build();
    streamServer = networkServerProvider.createServer(new InetSocketAddress("localhost", 30123), OptionMap.create(Options.SSL_ENABLED, Boolean.FALSE), saslAuthenticationFactory, SSLContext.getDefault());
    final FutureResult<Channel> passer = new FutureResult<Channel>();
    serviceRegistration = endpoint.registerService("org.jboss.test", new OpenListener() {

        public void channelOpened(final Channel channel) {
            passer.setResult(channel);
        }

        public void registrationTerminated() {
        }
    }, OptionMap.EMPTY);
    IoFuture<Connection> futureConnection = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.empty().useName("bob").usePassword("pass").setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("SCRAM-SHA-256"))).run(new PrivilegedAction<IoFuture<Connection>>() {

        public IoFuture<Connection> run() {
            try {
                return endpoint.connect(new URI("remote://localhost:30123"), OptionMap.EMPTY);
            } catch (URISyntaxException e) {
                throw new RuntimeException(e);
            }
        }
    });
    connection = futureConnection.get();
    IoFuture<Channel> futureChannel = connection.openChannel("org.jboss.test", OptionMap.EMPTY);
    clientChannel = futureChannel.get();
    serverChannel = passer.getIoFuture().get();
    assertNotNull(serverChannel);
    RemoteConnectionChannel remoteClientChannel = (RemoteConnectionChannel) clientChannel;
    assertEquals(RemotingOptions.DEFAULT_HEARTBEAT_INTERVAL, Utils.getInstanceValue(remoteClientChannel.getRemoteConnection(), "heartbeatInterval"));
    RemoteWriteListener clientWriteListener = (RemoteWriteListener) Utils.getInstanceValue(remoteClientChannel.getRemoteConnection(), "writeListener");
    assertNotNull(Utils.getInstanceValue(clientWriteListener, "heartKey"));
    afterTest(clientChannel, serverChannel, connection, serviceRegistration);
    destroy(endpoint, streamServer);
}
Also used : RemoteWriteListener(org.jboss.remoting3.remote.RemoteConnection.RemoteWriteListener) InetSocketAddress(java.net.InetSocketAddress) Closeable(java.io.Closeable) ClearPasswordSpec(org.wildfly.security.password.spec.ClearPasswordSpec) IoFuture(org.xnio.IoFuture) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain) Endpoint(org.jboss.remoting3.Endpoint) FutureResult(org.xnio.FutureResult) Registration(org.jboss.remoting3.Registration) NetworkServerProvider(org.jboss.remoting3.spi.NetworkServerProvider) ServiceLoaderSaslServerFactory(org.wildfly.security.sasl.util.ServiceLoaderSaslServerFactory) SimpleMapBackedSecurityRealm(org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm) SaslServerFactory(javax.security.sasl.SaslServerFactory) ServiceLoaderSaslServerFactory(org.wildfly.security.sasl.util.ServiceLoaderSaslServerFactory) OpenListener(org.jboss.remoting3.OpenListener) Channel(org.jboss.remoting3.Channel) Connection(org.jboss.remoting3.Connection) SaslAuthenticationFactory(org.wildfly.security.auth.server.sasl.SaslAuthenticationFactory) PasswordFactory(org.wildfly.security.password.PasswordFactory) Test(org.junit.Test)

Example 39 with Connection

use of com.google.cloud.bigquery.connection.v1.Connection in project osate2 by osate.

the class Aadl2InstanceUtil method getIncomingConnection.

/**
 * find incoming connection that goes through the feature of the specified component instance
 * @param ci Component instance
 * @param fi Feature instance
 * @return list of connection instances going through the feature
 */
public static EList<ConnectionInstance> getIncomingConnection(ComponentInstance ci, FeatureInstance fi) {
    Feature f = fi.getFeature();
    EList<ConnectionInstance> result = new BasicEList<ConnectionInstance>();
    // allEnclosingConnectionInstances();
    Iterable<ConnectionInstance> it = ci.getSystemInstance().getAllConnectionInstances();
    for (ConnectionInstance connectionInstance : it) {
        ConnectionInstanceEnd dest = connectionInstance.getDestination();
        ComponentInstance destci = dest.getContainingComponentInstance();
        if (containedIn(destci, ci)) {
            EList<ConnectionReference> connreflist = connectionInstance.getConnectionReferences();
            for (ConnectionReference connectionReference : connreflist) {
                ComponentInstance pci = connectionReference.getContext();
                Connection conn = connectionReference.getConnection();
                ConnectionEnd ce = conn.getAllSource();
                if (pci == ci.getContainingComponentInstance() && ce == f) {
                    result.add(connectionInstance);
                }
            }
        }
    }
    return result;
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) BasicEList(org.eclipse.emf.common.util.BasicEList) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) Connection(org.osate.aadl2.Connection) ConnectionEnd(org.osate.aadl2.ConnectionEnd) Feature(org.osate.aadl2.Feature)

Example 40 with Connection

use of com.google.cloud.bigquery.connection.v1.Connection in project osate2 by osate.

the class Aadl2InstanceUtil method getOutgoingConnection.

/**
 * find outgoing connection that goes through the feature of the specified component instance
 * @param ci Component instance
 * @param fi Feature instance
 * @return list of connection instances going through the feature
 */
public static EList<ConnectionInstance> getOutgoingConnection(ComponentInstance ci, FeatureInstance fi) {
    Feature f = fi.getFeature();
    EList<ConnectionInstance> result = new BasicEList<ConnectionInstance>();
    // allEnclosingConnectionInstances();
    Iterable<ConnectionInstance> it = ci.getSystemInstance().getAllConnectionInstances();
    for (ConnectionInstance connectionInstance : it) {
        ConnectionInstanceEnd src = connectionInstance.getSource();
        ComponentInstance srcci = src.getContainingComponentInstance();
        if (containedIn(srcci, ci)) {
            EList<ConnectionReference> connreflist = connectionInstance.getConnectionReferences();
            for (ConnectionReference connectionReference : connreflist) {
                ComponentInstance pci = connectionReference.getContext();
                Connection conn = connectionReference.getConnection();
                ConnectionEnd ce = conn.getAllSource();
                if (pci == ci.getContainingComponentInstance() && ce == f) {
                    // add connection if it goes through feature instance
                    result.add(connectionInstance);
                }
            }
        }
    }
    return result;
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) BasicEList(org.eclipse.emf.common.util.BasicEList) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) Connection(org.osate.aadl2.Connection) ConnectionEnd(org.osate.aadl2.ConnectionEnd) Feature(org.osate.aadl2.Feature)

Aggregations

IOException (java.io.IOException)87 Connection (com.trilead.ssh2.Connection)70 Connection (org.ovirt.engine.sdk4.Connection)64 Connection (org.osate.aadl2.Connection)58 Connection (ch.ethz.ssh2.Connection)47 Test (org.junit.Test)35 Session (com.trilead.ssh2.Session)33 Connection (okhttp3.Connection)33 Connection (org.jboss.remoting3.Connection)33 Connection (com.google.cloud.bigquery.connection.v1.Connection)31 InputStream (java.io.InputStream)31 VmsService (org.ovirt.engine.sdk4.services.VmsService)30 Vm (org.ovirt.engine.sdk4.types.Vm)30 Request (okhttp3.Request)23 Response (okhttp3.Response)20 Subcomponent (org.osate.aadl2.Subcomponent)20 ArrayList (java.util.ArrayList)19 FeatureGroupConnection (org.osate.aadl2.FeatureGroupConnection)19 VmService (org.ovirt.engine.sdk4.services.VmService)18 ResponseBody (okhttp3.ResponseBody)17