use of org.apache.synapse.commons.executors.PriorityExecutor in project wso2-synapse by wso2.
the class PriorityExecutorSerializerTest method testSerializeWithUnboundedQueues.
/**
* Test serializing a PriorityExecutor created with UnboundedQueues
*/
public void testSerializeWithUnboundedQueues() {
PriorityExecutor priorityExecutor = new PriorityExecutor();
priorityExecutor.setName("executor1");
List<InternalQueue> internalQueueList = new ArrayList<>();
internalQueueList.add(new UnboundedQueue(10));
internalQueueList.add(new UnboundedQueue(5));
MultiPriorityBlockingQueue multiPriorityBlockingQueue = new MultiPriorityBlockingQueue(internalQueueList, false, new PRRNextQueueAlgorithm());
priorityExecutor.setQueue(multiPriorityBlockingQueue);
OMElement element = PriorityExecutorSerializer.serialize(null, priorityExecutor, "http://ws.apache.org/ns/synapse");
assertEquals("Invalid serialization of PriorityExecutor", "<priorityExecutor xmlns=\"http://ws.apache.org/ns/synapse\" name=\"executor1\">" + "<queues isFixedSize=\"false\"><queue priority=\"10\" /><queue priority=\"5\" /></queues>" + "<threads max=\"100\" core=\"20\" keep-alive=\"5\" />" + "</priorityExecutor>", element.toString());
}
use of org.apache.synapse.commons.executors.PriorityExecutor in project wso2-synapse by wso2.
the class PriorityExecutorSerializerTest method testSerialize.
/**
* Test serializing a PriorityExecutor created with FixedSizeQueues
*/
public void testSerialize() {
PriorityExecutor priorityExecutor = new PriorityExecutor();
priorityExecutor.setName("executor1");
List<InternalQueue> internalQueueList = new ArrayList<>();
internalQueueList.add(new FixedSizeQueue(10, 10));
internalQueueList.add(new FixedSizeQueue(5, 25));
MultiPriorityBlockingQueue multiPriorityBlockingQueue = new MultiPriorityBlockingQueue(internalQueueList, true, new PRRNextQueueAlgorithm());
priorityExecutor.setQueue(multiPriorityBlockingQueue);
OMElement element = PriorityExecutorSerializer.serialize(null, priorityExecutor, "http://ws.apache.org/ns/synapse");
assertEquals("Invalid serialization of PriorityExecutor", "<priorityExecutor xmlns=\"http://ws.apache.org/ns/synapse\" name=\"executor1\">" + "<queues><queue size=\"10\" priority=\"10\" /><queue size=\"25\" priority=\"5\" /></queues>" + "<threads max=\"100\" core=\"20\" keep-alive=\"5\" />" + "</priorityExecutor>", element.toString());
}
use of org.apache.synapse.commons.executors.PriorityExecutor in project wso2-synapse by wso2.
the class PriorityExecutorSerializerTest method testSerializeGivenParentElement.
/**
* Test serializing a PriorityExecutor when parent element is defined
* @throws XMLStreamException
*/
public void testSerializeGivenParentElement() throws XMLStreamException {
OMElement parentElement = AXIOMUtil.stringToOM("<definitions></definitions>");
PriorityExecutor priorityExecutor = new PriorityExecutor();
priorityExecutor.setName("executor1");
List<InternalQueue> internalQueueList = new ArrayList<>();
internalQueueList.add(new FixedSizeQueue(10, 10));
internalQueueList.add(new FixedSizeQueue(5, 25));
MultiPriorityBlockingQueue multiPriorityBlockingQueue = new MultiPriorityBlockingQueue(internalQueueList, true, new PRRNextQueueAlgorithm());
priorityExecutor.setQueue(multiPriorityBlockingQueue);
PriorityExecutorSerializer.serialize(parentElement, priorityExecutor, "http://ws.apache.org/ns/synapse");
assertEquals("Invalid serialization of PriorityExecutor", "<definitions>" + "<priorityExecutor xmlns=\"http://ws.apache.org/ns/synapse\" name=\"executor1\">" + "<queues><queue size=\"10\" priority=\"10\" /><queue size=\"25\" priority=\"5\" /></queues>" + "<threads max=\"100\" core=\"20\" keep-alive=\"5\" />" + "</priorityExecutor>" + "</definitions>", parentElement.toString());
}
use of org.apache.synapse.commons.executors.PriorityExecutor in project wso2-synapse by wso2.
the class SynapseObserverTest method testSimpleObserver.
public void testSimpleObserver() {
SynapseConfiguration synapseConfig = new SynapseConfiguration();
synapseConfig.setAxisConfiguration(new AxisConfiguration());
synapseConfig.registerObserver(observer);
Endpoint epr = new AddressEndpoint();
epr.setName("endpoint1");
synapseConfig.addEndpoint(epr.getName(), epr);
assertItemAdded(epr.getName(), ENDPOINT);
synapseConfig.removeEndpoint(epr.getName());
assertItemRemoved(epr.getName(), ENDPOINT);
SequenceMediator seq = new SequenceMediator();
seq.setName("sequence1");
synapseConfig.addSequence(seq.getName(), seq);
assertItemAdded(seq.getName(), SEQUENCE);
synapseConfig.removeSequence(seq.getName());
assertItemRemoved(seq.getName(), SEQUENCE);
TemplateMediator template = new TemplateMediator();
template.setName("template1");
synapseConfig.addSequenceTemplate(template.getName(), template);
assertItemAdded(template.getName(), SEQUENCE_TEMPLATE);
synapseConfig.removeSequenceTemplate(template.getName());
assertItemRemoved(template.getName(), SEQUENCE_TEMPLATE);
Entry entry = new Entry();
entry.setKey("entry1");
synapseConfig.addEntry(entry.getKey(), entry);
assertItemAdded(entry.getKey(), ENTRY);
synapseConfig.removeEntry(entry.getKey());
assertItemRemoved(entry.getKey(), ENTRY);
ProxyService proxy = new ProxyService("proxy1");
synapseConfig.addProxyService(proxy.getName(), proxy);
assertItemAdded(proxy.getName(), PROXY);
synapseConfig.removeProxyService(proxy.getName());
assertItemRemoved(proxy.getName(), PROXY);
Startup startup = new StartUpController();
startup.setName("startup1");
synapseConfig.addStartup(startup);
assertItemAdded(startup.getName(), STARTUP);
synapseConfig.removeStartup(startup.getName());
assertItemRemoved(startup.getName(), STARTUP);
SynapseEventSource eventSrc = new SynapseEventSource("eventSrc1");
synapseConfig.addEventSource(eventSrc.getName(), eventSrc);
assertItemAdded(eventSrc.getName(), EVENT_SRC);
synapseConfig.removeEventSource(eventSrc.getName());
assertItemRemoved(eventSrc.getName(), EVENT_SRC);
PriorityExecutor exec = new PriorityExecutor();
exec.setName("exec1");
synapseConfig.addPriorityExecutor(exec.getName(), exec);
assertItemAdded(exec.getName(), EXECUTOR);
synapseConfig.removeExecutor(exec.getName());
assertItemRemoved(exec.getName(), EXECUTOR);
}
use of org.apache.synapse.commons.executors.PriorityExecutor in project wso2-synapse by wso2.
the class MultiXMLConfigurationBuilder method createExecutors.
private static void createExecutors(SynapseConfiguration synapseConfig, String rootDirPath, Properties properties) {
File executorsDir = new File(rootDirPath, EXECUTORS_DIR);
if (executorsDir.exists()) {
if (log.isDebugEnabled()) {
log.debug("Loading event sources from : " + executorsDir.getPath());
}
Iterator executors = FileUtils.iterateFiles(executorsDir, extensions, false);
while (executors.hasNext()) {
File file = (File) executors.next();
try {
OMElement document = getOMElement(file);
PriorityExecutor executor = SynapseXMLConfigurationFactory.defineExecutor(synapseConfig, document, properties);
if (executor != null) {
executor.setFileName(file.getName());
synapseConfig.getArtifactDeploymentStore().addArtifact(file.getAbsolutePath(), executor.getName());
}
} catch (Exception e) {
String msg = "Executor configuration cannot be built from : " + file.getName();
handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_EXECUTORS, msg, e);
}
}
}
}
Aggregations