Search in sources :

Example 6 with Transactions

use of org.jvnet.hk2.config.Transactions in project Payara by payara.

the class ConfigAttributeSetTest method simpleAttributeSetTest.

@Test
public void simpleAttributeSetTest() {
    CommandRunnerImpl runner = habitat.getService(CommandRunnerImpl.class);
    assertNotNull(runner);
    // let's find our target
    NetworkListener listener = null;
    NetworkListeners service = habitat.getService(NetworkListeners.class);
    for (NetworkListener l : service.getNetworkListener()) {
        if ("http-listener-1".equals(l.getName())) {
            listener = l;
            break;
        }
    }
    assertNotNull(listener);
    // Let's register a listener
    ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(listener);
    bean.addListener(this);
    // parameters to the command
    ParameterMap parameters = new ParameterMap();
    parameters.set("value", "8090");
    parameters.set("DEFAULT", "configs.config.server-config.http-service.http-listener.http-listener-1.port");
    // execute the set command.
    runner.getCommandInvocation("set", new HTMLActionReporter(), adminSubject()).parameters(parameters).execute();
    // check the result.
    String port = listener.getPort();
    assertEquals(port, "8090");
    // ensure events are delivered.
    habitat.<Transactions>getService(Transactions.class).waitForDrain();
    // finally
    bean.removeListener(this);
    // check we recevied the event
    assertNotNull(event);
    assertEquals("8080", event.getOldValue());
    assertEquals("8090", event.getNewValue());
    assertEquals("port", event.getPropertyName());
}
Also used : Transactions(org.jvnet.hk2.config.Transactions) HTMLActionReporter(com.sun.enterprise.v3.common.HTMLActionReporter) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) ObservableBean(org.jvnet.hk2.config.ObservableBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 7 with Transactions

use of org.jvnet.hk2.config.Transactions in project Payara by payara.

the class ConfigApiTest method getHabitat.

/**
 * Returns a configured Habitat with the configuration.
 *
 * @return a configured Habitat
 */
public ServiceLocator getHabitat() {
    ServiceLocator habitat = Utils.instance.getHabitat(this);
    assertNotNull("Transactions service from Configuration subsystem is null", habitat.getService(Transactions.class));
    return habitat;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Transactions(org.jvnet.hk2.config.Transactions)

Example 8 with Transactions

use of org.jvnet.hk2.config.Transactions in project Payara by payara.

the class PropertyChangeListenerTest method propertyChangeEventReceptionTest.

@Test
public void propertyChangeEventReceptionTest() throws TransactionFailure {
    HttpService httpService = habitat.getService(HttpService.class);
    assertNotNull(httpService);
    // let's find a acceptable target.
    VirtualServer target = null;
    for (VirtualServer vs : httpService.getVirtualServer()) {
        if (!vs.getProperty().isEmpty()) {
            target = vs;
            break;
        }
    }
    assertNotNull(target);
    ((ObservableBean) ConfigSupport.getImpl(target)).addListener(this);
    final Property prop = target.getProperty().get(0);
    ConfigSupport.apply(new SingleConfigCode<Property>() {

        public Object run(Property param) throws PropertyVetoException, TransactionFailure {
            // first one is fine...
            param.setValue(prop.getValue().toUpperCase());
            return null;
        }
    }, prop);
    getHabitat().<Transactions>getService(Transactions.class).waitForDrain();
    assertTrue(result);
    ((ObservableBean) ConfigSupport.getImpl(target)).removeListener(this);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) Property(org.jvnet.hk2.config.types.Property) Test(org.junit.Test)

Example 9 with Transactions

use of org.jvnet.hk2.config.Transactions 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)

Example 10 with Transactions

use of org.jvnet.hk2.config.Transactions in project Payara by payara.

the class TranslatedViewCreationTest method createVirtualServerTest.

@Test
public void createVirtualServerTest() throws TransactionFailure {
    httpService = getHabitat().getService(HttpService.class);
    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);
        ConfigSupport.apply(new SingleConfigCode<HttpService>() {

            public Object run(HttpService param) throws PropertyVetoException, TransactionFailure {
                VirtualServer newVirtualServer = param.createChild(VirtualServer.class);
                newVirtualServer.setDocroot("${" + propName + "}");
                newVirtualServer.setId("translated-view-creation");
                param.getVirtualServer().add(newVirtualServer);
                return null;
            }
        }, httpService);
        // first let check that our new virtual server has the right translated value
        VirtualServer vs = httpService.getVirtualServerByName("translated-view-creation");
        assertTrue(vs != null);
        String docRoot = vs.getDocroot();
        assertTrue("/foo/bar/docroot".equals(docRoot));
        transactions.waitForDrain();
        assertTrue(events != null);
        logger.fine("Number of events " + events.size());
        assertTrue(events.size() == 3);
        for (PropertyChangeEvent event : events) {
            if ("virtual-server".equals(event.getPropertyName())) {
                VirtualServer newVS = (VirtualServer) event.getNewValue();
                assertTrue(event.getOldValue() == null);
                docRoot = newVS.getDocroot();
                assertTrue("/foo/bar/docroot".equals(docRoot));
                VirtualServer rawView = GlassFishConfigBean.getRawView(newVS);
                assertTrue(rawView != null);
                assertTrue(rawView.getDocroot().equalsIgnoreCase("${" + propName + "}"));
                return;
            }
        }
        assertTrue(false);
    } finally {
        transactions.removeTransactionsListener(listener);
    }
}
Also used : TransactionListener(org.jvnet.hk2.config.TransactionListener) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Transactions(org.jvnet.hk2.config.Transactions) PropertyChangeEvent(java.beans.PropertyChangeEvent) HttpService(com.sun.enterprise.config.serverbeans.HttpService) List(java.util.List) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 Transactions (org.jvnet.hk2.config.Transactions)10 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)6 ObservableBean (org.jvnet.hk2.config.ObservableBean)5 PropertyChangeEvent (java.beans.PropertyChangeEvent)4 List (java.util.List)4 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)4 TransactionListener (org.jvnet.hk2.config.TransactionListener)4 Property (org.jvnet.hk2.config.types.Property)4 PropertyVetoException (java.beans.PropertyVetoException)3 HttpService (com.sun.enterprise.config.serverbeans.HttpService)2 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)2 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)2 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)2 ConnectorRuntime (com.sun.appserv.connectors.internal.api.ConnectorRuntime)1 Config (com.sun.enterprise.config.serverbeans.Config)1 Domain (com.sun.enterprise.config.serverbeans.Domain)1 ModuleMonitoringLevels (com.sun.enterprise.config.serverbeans.ModuleMonitoringLevels)1 Resource (com.sun.enterprise.config.serverbeans.Resource)1 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)1