KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > engine > TaskProcessorRetryStrategyTest


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.engine;
23
24 import junit.framework.Test;
25 import junit.framework.TestSuite;
26
27 import org.easymock.MockControl;
28 import org.jacorb.notification.engine.AbstractRetryStrategy;
29 import org.jacorb.notification.engine.TaskProcessor;
30 import org.jacorb.notification.engine.TaskProcessorRetryStrategy;
31 import org.omg.CORBA.TRANSIENT JavaDoc;
32
33 /**
34  * @author Alphonse Bendt
35  * @version $Id: TaskProcessorRetryStrategyTest.java,v 1.4 2005/04/27 10:50:49 alphonse.bendt Exp $
36  */

37 public class TaskProcessorRetryStrategyTest extends AbstractRetryStrategyTest
38 {
39     private MockControl controlTaskProcessor_;
40     private TaskProcessor mockTaskProcessor_;
41
42     protected void setUpTest()
43     {
44         controlTaskProcessor_ = MockControl.createControl(TaskProcessor.class);
45         mockTaskProcessor_ = (TaskProcessor) controlTaskProcessor_.getMock();
46     }
47
48     protected AbstractRetryStrategy newRetryStrategy()
49     {
50         return new TaskProcessorRetryStrategy(mockConsumer_, mockPushOperation_, mockTaskProcessor_, 10);
51     }
52     
53     /**
54      * Constructor for TaskProcessorRetryStrategyTest.
55      *
56      * @param name
57      */

58     public TaskProcessorRetryStrategyTest(String JavaDoc name)
59     {
60         super(name);
61     }
62     
63     public void testSuccessfulRetryDisposes() throws Exception JavaDoc
64     {
65         controlConsumer_.replay();
66         
67         mockPushOperation_.invokePush();
68         mockPushOperation_.dispose();
69         
70         controlPushOperation_.replay();
71         
72         controlTaskProcessor_.replay();
73         
74         ((TaskProcessorRetryStrategy)objectUnderTest_).doPush();
75         
76         controlConsumer_.verify();
77         controlPushOperation_.verify();
78         controlTaskProcessor_.verify();
79     }
80     
81     public void testNotSuccessfulRetryDisposes() throws Exception JavaDoc
82     {
83         mockConsumer_.incErrorCounter();
84         controlConsumer_.setDefaultReturnValue(0);
85         
86         mockConsumer_.isRetryAllowed();
87         controlConsumer_.setDefaultReturnValue(false);
88         
89         mockConsumer_.destroy();
90         controlConsumer_.replay();
91         
92         mockPushOperation_.invokePush();
93         controlPushOperation_.setDefaultThrowable(new TRANSIENT JavaDoc());
94         mockPushOperation_.dispose();
95         
96         controlPushOperation_.replay();
97                 
98         controlTaskProcessor_.replay();
99         
100         ((TaskProcessorRetryStrategy)objectUnderTest_).doPush();
101         
102         controlConsumer_.verify();
103         controlPushOperation_.verify();
104         controlTaskProcessor_.verify();
105     }
106
107     
108     public void testFailedRetryRequeues() throws Exception JavaDoc
109     {
110         mockConsumer_.incErrorCounter();
111         controlConsumer_.setDefaultReturnValue(0);
112         
113         mockConsumer_.isRetryAllowed();
114         controlConsumer_.setReturnValue(true, 2);
115         controlConsumer_.replay();
116         
117         mockPushOperation_.invokePush();
118         controlPushOperation_.setThrowable(new TRANSIENT JavaDoc());
119            
120         controlPushOperation_.replay();
121                 
122         mockTaskProcessor_.executeTaskAfterDelay(0, null);
123         controlTaskProcessor_.setMatcher(MockControl.ALWAYS_MATCHER);
124         controlTaskProcessor_.setReturnValue(new Object JavaDoc());
125         
126         controlTaskProcessor_.replay();
127         
128         ((TaskProcessorRetryStrategy)objectUnderTest_).doPush();
129         
130         controlConsumer_.verify();
131         controlPushOperation_.verify();
132         controlTaskProcessor_.verify();
133     }
134    
135     public static Test suite()
136     {
137         return new TestSuite(TaskProcessorRetryStrategyTest.class);
138     }
139 }
140
Popular Tags