KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > filter > GarbageCollectTest


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21
22 package org.jacorb.test.notification.filter;
23
24 import junit.framework.Test;
25
26 import org.apache.avalon.framework.configuration.Configuration;
27 import org.easymock.MockControl;
28 import org.jacorb.notification.IContainer;
29 import org.jacorb.notification.conf.Attributes;
30 import org.jacorb.notification.conf.Default;
31 import org.jacorb.notification.filter.DefaultFilterFactoryDelegate;
32 import org.jacorb.notification.filter.FilterFactoryImpl;
33 import org.jacorb.notification.util.WeakCacheWildcardMap;
34 import org.jacorb.test.notification.NotificationTestCase;
35 import org.jacorb.test.notification.NotificationTestCaseSetup;
36 import org.omg.CORBA.Any JavaDoc;
37 import org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc;
38 import org.omg.CosNotifyFilter.Filter;
39 import org.omg.CosNotifyFilter.FilterFactory;
40 import org.omg.CosNotifyFilter.FilterFactoryHelper;
41 import org.picocontainer.MutablePicoContainer;
42
43 /**
44  * @author Alphonse Bendt
45  * @version $Id: GarbageCollectTest.java,v 1.2 2005/05/01 21:16:32 alphonse.bendt Exp $
46  */

47 public class GarbageCollectTest extends NotificationTestCase
48 {
49     private MockControl controlConfiguration_;
50
51     private Configuration mockConfiguration_;
52
53     private IContainer iContainerForTest_;
54
55     /**
56      * Constructor for FilterGarbageCollectTest.
57      *
58      * @param name
59      */

60     public GarbageCollectTest(String JavaDoc name, NotificationTestCaseSetup setup)
61     {
62         super(name, setup);
63     }
64
65     protected void setUpTest() throws Exception JavaDoc
66     {
67         super.setUpTest();
68
69         controlConfiguration_ = MockControl.createControl(Configuration.class);
70
71
72         iContainerForTest_ = new IContainer()
73         {
74             public MutablePicoContainer getContainer()
75             {
76                 return getPicoContainer();
77             }
78
79             public void destroy()
80             {
81                 // no operation
82
}
83         };
84
85         mockConfiguration_ = (Configuration) controlConfiguration_.getMock();
86
87         // configuration options that setup code depends on.
88
mockConfiguration_.getAttributeNames();
89         controlConfiguration_.setReturnValue(new String JavaDoc[0]);
90
91         mockConfiguration_.getAttribute(Attributes.WILDCARDMAP_CLASS, WeakCacheWildcardMap.class
92                 .getName());
93         controlConfiguration_.setReturnValue(WeakCacheWildcardMap.class.getName());
94     }
95
96     public void testGCFilter() throws Exception JavaDoc
97     {
98         // enable gc
99
mockConfiguration_.getAttributeAsBoolean(Attributes.USE_GC, Default.DEFAULT_USE_GC);
100         controlConfiguration_.setReturnValue(true);
101
102         // set timeout
103
mockConfiguration_.getAttributeAsLong(Attributes.DEAD_FILTER_INTERVAL,
104                 Default.DEFAULT_DEAD_FILTER_INTERVAL);
105         controlConfiguration_.setReturnValue(100);
106
107         // another picocontainer is necessary so that registered
108
// Configuration can be overridden locally to configure
109
// garbage collection.
110
getPicoContainer().registerComponentInstance(Configuration.class, mockConfiguration_);
111
112         controlConfiguration_.replay();
113
114         // will use local configuration.
115
FilterFactoryImpl factoryServant_ = new FilterFactoryImpl(getORB(), getPOA(),
116                 mockConfiguration_, new DefaultFilterFactoryDelegate(iContainerForTest_, mockConfiguration_));
117
118         String JavaDoc _factoryRef = getORB().object_to_string(factoryServant_.activate());
119         
120         FilterFactory _factory = FilterFactoryHelper.narrow(getClientORB().string_to_object(_factoryRef));
121
122         Filter _filter = _factory.create_filter("EXTENDED_TCL");
123
124         assertFalse(_filter._non_existent());
125
126         // wait some time. give gc thread chance to clean up filter.
127
Thread.sleep(10000);
128
129         try
130         {
131             Any JavaDoc any = toAny(5);
132             _filter.match(any);
133         } catch (OBJECT_NOT_EXIST JavaDoc e)
134         {
135             // expected
136
}
137     }
138
139
140     public static Test suite() throws Exception JavaDoc
141     {
142         return NotificationTestCase.suite(GarbageCollectTest.class);
143     }
144 }
145
Popular Tags