1 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 ; 32 33 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 58 public TaskProcessorRetryStrategyTest(String name) 59 { 60 super(name); 61 } 62 63 public void testSuccessfulRetryDisposes() throws Exception 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 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 ()); 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 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 ()); 119 120 controlPushOperation_.replay(); 121 122 mockTaskProcessor_.executeTaskAfterDelay(0, null); 123 controlTaskProcessor_.setMatcher(MockControl.ALWAYS_MATCHER); 124 controlTaskProcessor_.setReturnValue(new Object ()); 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 |