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());
}
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;
}
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);
}
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);
}
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);
}
}
Aggregations