Search in sources :

Example 11 with Http

use of org.glassfish.grizzly.config.dom.Http in project Payara by payara.

the class TransactionListenerTest method transactionEvents.

@Test
public void transactionEvents() throws Exception, TransactionFailure {
    httpService = getHabitat().getService(HttpService.class);
    NetworkConfig networkConfig = getHabitat().getService(NetworkConfig.class);
    final NetworkListener netListener = networkConfig.getNetworkListeners().getNetworkListener().get(0);
    final Http http = netListener.findHttpProtocol().getHttp();
    final TransactionListener listener = new TransactionListener() {

        public void transactionCommited(List<PropertyChangeEvent> changes) {
            events = changes;
        }

        public void unprocessedTransactedEvents(List<UnprocessedChangeEvents> changes) {
        }
    };
    Transactions transactions = getHabitat().getService(Transactions.class);
    try {
        transactions.addTransactionsListener(listener);
        assertTrue(httpService != null);
        logger.fine("Max connections = " + http.getMaxConnections());
        ConfigSupport.apply(new SingleConfigCode<Http>() {

            public Object run(Http param) {
                param.setMaxConnections("500");
                return null;
            }
        }, http);
        assertTrue("500".equals(http.getMaxConnections()));
        transactions.waitForDrain();
        assertTrue(events != null);
        logger.fine("Number of events " + events.size());
        assertTrue(events.size() == 1);
        PropertyChangeEvent event = events.iterator().next();
        assertTrue("max-connections".equals(event.getPropertyName()));
        assertTrue("500".equals(event.getNewValue().toString()));
        assertTrue("250".equals(event.getOldValue().toString()));
    } catch (Exception t) {
        t.printStackTrace();
        throw t;
    } finally {
        transactions.removeTransactionsListener(listener);
    }
    // put back the right values in the domain to avoid test collisions
    ConfigSupport.apply(new SingleConfigCode<Http>() {

        public Object run(Http param) {
            param.setMaxConnections("250");
            return null;
        }
    }, http);
}
Also used : TransactionListener(org.jvnet.hk2.config.TransactionListener) Transactions(org.jvnet.hk2.config.Transactions) PropertyChangeEvent(java.beans.PropertyChangeEvent) HttpService(com.sun.enterprise.config.serverbeans.HttpService) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Http(org.glassfish.grizzly.config.dom.Http) List(java.util.List) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Aggregations

Http (org.glassfish.grizzly.config.dom.Http)11 Protocol (org.glassfish.grizzly.config.dom.Protocol)9 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)7 Protocols (org.glassfish.grizzly.config.dom.Protocols)4 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)4 Config (com.sun.enterprise.config.serverbeans.Config)3 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)3 List (java.util.List)2 FileCache (org.glassfish.grizzly.config.dom.FileCache)2 Ssl (org.glassfish.grizzly.config.dom.Ssl)2 ThreadPool (org.glassfish.grizzly.config.dom.ThreadPool)2 Transport (org.glassfish.grizzly.config.dom.Transport)2 Test (org.junit.Test)2 HttpService (com.sun.enterprise.config.serverbeans.HttpService)1 JavaConfig (com.sun.enterprise.config.serverbeans.JavaConfig)1 MonitoringService (com.sun.enterprise.config.serverbeans.MonitoringService)1 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)1 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)1 HostAndPort (com.sun.enterprise.util.HostAndPort)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1