1
2
3
4
5
6
7
8
9
10 package org.mule.module.sxc;
11
12 import java.io.ByteArrayOutputStream;
13
14 import org.apache.commons.io.IOUtils;
15 import org.mule.api.MuleException;
16 import org.mule.api.MuleMessage;
17 import org.mule.module.client.MuleClient;
18 import org.mule.tck.FunctionalTestCase;
19
20 public class SxcFilterTestCase extends FunctionalTestCase {
21 int finished = 0;
22
23 public void testBasicXPath() throws Exception {
24 final MuleClient client = new MuleClient();
25
26 final ByteArrayOutputStream out = new ByteArrayOutputStream();
27 IOUtils.copy(getClass().getResourceAsStream("/purchase-order.xml"), out);
28
29 MuleMessage res = client.send("vm://in", out.toByteArray(), null);
30 assertEquals(Boolean.TRUE, res.getPayload());
31 }
32
33 public void testAndFilter() throws Exception {
34 final MuleClient client = new MuleClient();
35
36 final ByteArrayOutputStream out = new ByteArrayOutputStream();
37 IOUtils.copy(getClass().getResourceAsStream("/purchase-order.xml"), out);
38
39 MuleMessage res = client.send("vm://and-filter", out.toByteArray(), null);
40
41 assertEquals(Boolean.TRUE, res.getPayload());
42 }
43 public void testOrFilter() throws Exception {
44 final MuleClient client = new MuleClient();
45
46 final ByteArrayOutputStream out = new ByteArrayOutputStream();
47 IOUtils.copy(getClass().getResourceAsStream("/purchase-order.xml"), out);
48
49 MuleMessage res = client.send("vm://or-filter", out.toByteArray(), null);
50
51 assertEquals(Boolean.TRUE, res.getPayload());
52 }
53 public void testNotFilter() throws Exception {
54 final MuleClient client = new MuleClient();
55
56 final ByteArrayOutputStream out = new ByteArrayOutputStream();
57 IOUtils.copy(getClass().getResourceAsStream("/purchase-order.xml"), out);
58
59 MuleMessage res = client.send("vm://not-filter", out.toByteArray(), null);
60
61 assertEquals(Boolean.TRUE, res.getPayload());
62 }
63
64 public void xtestBenchmark() throws Exception {
65 final MuleClient client = new MuleClient();
66
67 final ByteArrayOutputStream out = new ByteArrayOutputStream();
68 IOUtils.copy(getClass().getResourceAsStream("/purchase-order.xml"), out);
69
70 System.out.println("Warmup");
71 fire(client, out, 1500);
72
73 System.out.println("Running....");
74
75 fire(client, out, 1000);
76
77 Thread.sleep(1000);
78 }
79
80 private void fire(final MuleClient client, final ByteArrayOutputStream out, final int count) throws InterruptedException
81 {
82 long time = System.currentTimeMillis();
83 finished = 0;
84 for (int i = 0; i < 10; i++) {
85 new Thread(new Runnable() {
86 public void run() {
87 for (int j = 0; j < count; j++) {
88 try {
89 client.send("vm://in", out.toByteArray(), null);
90 } catch (MuleException e) {
91
92 e.printStackTrace();
93 }
94 }
95 finished++;
96 }
97 }).start();
98 }
99
100 while (finished < 10) {
101 Thread.sleep(100);
102 }
103 System.out.println("elapsed " + (System.currentTimeMillis() - time));
104
105 }
106
107 @Override
108 protected String getConfigResources() {
109 return "xpath-filter-conf.xml";
110 }
111
112 }