01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.systest.ws.util;
19:
20: import junit.framework.Assert;
21:
22: public class MessageRecorder extends Assert {
23:
24: private OutMessageRecorder outRecorder;
25: private InMessageRecorder inRecorder;
26:
27: public MessageRecorder(OutMessageRecorder or, InMessageRecorder ir) {
28: inRecorder = ir;
29: outRecorder = or;
30: }
31:
32: public void awaitMessages(int nExpectedOut, int nExpectedIn,
33: int timeout) {
34: int waited = 0;
35: int nOut = 0;
36: int nIn = 0;
37: while (waited <= timeout) {
38: synchronized (outRecorder) {
39: nOut = outRecorder.getOutboundMessages().size();
40: }
41: synchronized (inRecorder) {
42: nIn = inRecorder.getInboundMessages().size();
43: }
44: if (nIn >= nExpectedIn && nOut >= nExpectedOut) {
45: return;
46: }
47: try {
48: Thread.sleep(100);
49: } catch (InterruptedException ex) {
50: // ignore
51: }
52: waited += 100;
53: }
54: assertEquals(
55: "Did not receive expected number of inbound messages",
56: nExpectedIn, nIn);
57: assertEquals(
58: "Did not send expected number of outbound messages",
59: nExpectedOut, nOut);
60: }
61: }
|