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: */
016: package org.apache.catalina.tribes.test.channel;
017:
018: import org.apache.catalina.tribes.group.GroupChannel;
019: import junit.framework.TestCase;
020: import org.apache.catalina.tribes.transport.ReceiverBase;
021:
022: /**
023: * @author Filip Hanik
024: * @version 1.0
025: */
026: public class ChannelStartStop extends TestCase {
027: GroupChannel channel = null;
028:
029: protected void setUp() throws Exception {
030: super .setUp();
031: channel = new GroupChannel();
032: }
033:
034: protected void tearDown() throws Exception {
035: super .tearDown();
036: try {
037: channel.stop(channel.DEFAULT);
038: } catch (Exception ignore) {
039: }
040: }
041:
042: public void testDoubleFullStart() throws Exception {
043: int count = 0;
044: try {
045: channel.start(channel.DEFAULT);
046: count++;
047: } catch (Exception x) {
048: x.printStackTrace();
049: }
050: try {
051: channel.start(channel.DEFAULT);
052: count++;
053: } catch (Exception x) {
054: x.printStackTrace();
055: }
056: assertEquals(count, 2);
057: channel.stop(channel.DEFAULT);
058: }
059:
060: public void testScrap() throws Exception {
061: System.out.println(channel.getChannelReceiver().getClass());
062: ((ReceiverBase) channel.getChannelReceiver()).setMaxThreads(1);
063: }
064:
065: public void testDoublePartialStart() throws Exception {
066: //try to double start the RX
067: int count = 0;
068: try {
069: channel.start(channel.SND_RX_SEQ);
070: channel.start(channel.MBR_RX_SEQ);
071: count++;
072: } catch (Exception x) {
073: x.printStackTrace();
074: }
075: try {
076: channel.start(channel.MBR_RX_SEQ);
077: count++;
078: } catch (Exception x) {/*expected*/
079: }
080: assertEquals(count, 1);
081: channel.stop(channel.DEFAULT);
082: //double the membership sender
083: count = 0;
084: try {
085: channel.start(channel.SND_RX_SEQ);
086: channel.start(channel.MBR_TX_SEQ);
087: count++;
088: } catch (Exception x) {
089: x.printStackTrace();
090: }
091: try {
092: channel.start(channel.MBR_TX_SEQ);
093: count++;
094: } catch (Exception x) {/*expected*/
095: }
096: assertEquals(count, 1);
097: channel.stop(channel.DEFAULT);
098:
099: count = 0;
100: try {
101: channel.start(channel.SND_RX_SEQ);
102: count++;
103: } catch (Exception x) {
104: x.printStackTrace();
105: }
106: try {
107: channel.start(channel.SND_RX_SEQ);
108: count++;
109: } catch (Exception x) {/*expected*/
110: }
111: assertEquals(count, 1);
112: channel.stop(channel.DEFAULT);
113:
114: count = 0;
115: try {
116: channel.start(channel.SND_TX_SEQ);
117: count++;
118: } catch (Exception x) {
119: x.printStackTrace();
120: }
121: try {
122: channel.start(channel.SND_TX_SEQ);
123: count++;
124: } catch (Exception x) {/*expected*/
125: }
126: assertEquals(count, 1);
127: channel.stop(channel.DEFAULT);
128: }
129:
130: public void testFalseOption() throws Exception {
131: int flag = 0xFFF0;//should get ignored by the underlying components
132: int count = 0;
133: try {
134: channel.start(flag);
135: count++;
136: } catch (Exception x) {
137: x.printStackTrace();
138: }
139: try {
140: channel.start(flag);
141: count++;
142: } catch (Exception x) {/*expected*/
143: }
144: assertEquals(count, 2);
145: channel.stop(channel.DEFAULT);
146: }
147:
148: }
|