001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.bpmscript.jbi.component;
018:
019: import java.util.Date;
020: import java.util.Properties;
021: import java.util.concurrent.ExecutorService;
022: import java.util.concurrent.Executors;
023: import java.util.concurrent.TimeUnit;
024:
025: import javax.jbi.messaging.ExchangeStatus;
026: import javax.jbi.messaging.InOut;
027: import javax.xml.namespace.QName;
028:
029: import org.apache.log4j.PropertyConfigurator;
030: import org.apache.servicemix.client.DefaultServiceMixClient;
031: import org.apache.servicemix.jbi.jaxp.SourceTransformer;
032: import org.apache.servicemix.jbi.jaxp.StringSource;
033: import org.apache.servicemix.tck.SpringTestSupport;
034: import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
035: import org.springframework.context.support.AbstractXmlApplicationContext;
036:
037: import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
038:
039: public class NineteenPerformanceTest extends SpringTestSupport {
040:
041: public NineteenPerformanceTest() {
042: Properties properties = new Properties();
043: properties.put("log4j.rootCategory", "INFO, stdout");
044: properties.put("log4j.appender.stdout",
045: "org.apache.log4j.ConsoleAppender");
046: properties.put("log4j.appender.stdout.layout",
047: "org.apache.log4j.PatternLayout");
048: properties.put(
049: "log4j.appender.stdout.layout.ConversionPattern",
050: "%p [%t] %c{1}.%M(%L) | %m%n");
051: properties.put("log4j.logger.org.apache", "WARN");
052: PropertyConfigurator.configure(properties);
053: }
054:
055: public void testNineteen() throws Exception {
056: final DefaultServiceMixClient client = new DefaultServiceMixClient(
057: jbi);
058: InOut me = client.createInOutExchange();
059: me
060: .setService(new QName("http://bpmscript.org/jbi",
061: "nineteen"));
062: me.getInMessage().setContent(
063: new StringSource("<hello>world</hello>"));
064: assertTrue(client.sendSync(me, 1000000));
065: if (me.getStatus() == ExchangeStatus.ERROR) {
066: if (me.getFault() != null) {
067: fail("Received fault: "
068: + new SourceTransformer().toString(me
069: .getFault().getContent()));
070: } else if (me.getError() != null) {
071: throw me.getError();
072: } else {
073: fail("Received ERROR status");
074: }
075: } else {
076: System.out.println(new SourceTransformer().toString(me
077: .getOutMessage().getContent()));
078: }
079: int total = 1;
080: long startTime = System.currentTimeMillis();
081: ExecutorService executorService = Executors
082: .newFixedThreadPool(10);
083: final AtomicInteger count = new AtomicInteger(0);
084: for (int i = 0; i < total; i++) {
085: executorService.execute(new Runnable() {
086: public void run() {
087: try {
088: InOut me = client.createInOutExchange();
089: me
090: .setService(new QName(
091: "http://bpmscript.org/jbi",
092: "nineteen"));
093: me
094: .getInMessage()
095: .setContent(
096: new StringSource(
097: "<hello>world</hello>"));
098: assertTrue(client.sendSync(me, 1000000));
099: if (me.getStatus() == ExchangeStatus.ERROR) {
100: if (me.getFault() != null) {
101: fail("Received fault: "
102: + new SourceTransformer()
103: .toString(me.getFault()
104: .getContent()));
105: } else if (me.getError() != null) {
106: throw me.getError();
107: } else {
108: fail("Received ERROR status");
109: }
110: }
111: count.incrementAndGet();
112: } catch (Throwable t) {
113: fail(t.getMessage());
114: }
115: }
116:
117: });
118: }
119: executorService.shutdown();
120: while (!executorService.awaitTermination(2, TimeUnit.SECONDS)) {
121: log
122: .info(new Date() + ": " + count.get()
123: + " have finished");
124: }
125: long duration = System.currentTimeMillis() - startTime;
126: log.info("Average time " + ((double) duration / (double) total)
127: + "ms");
128: log.info("Average throughput "
129: + (((double) total / (double) duration) * 60000.0)
130: + "tpm");
131: }
132:
133: protected AbstractXmlApplicationContext createBeanFactory() {
134: return new ClassPathXmlApplicationContext(
135: "/nineteen/spring.xml");
136: }
137:
138: }
|