Search in sources :

Example 1 with Callback

use of alma.ACS.Callback in project ACS by ACS-Community.

the class BACIDispatchActionTest method testException.

/**
	 * Always throws exception.
	 */
public void testException() {
    Object value = new Object();
    Completion completion = CompletionUtil.generateNoErrorCompletion();
    CBDescIn descIn = new CBDescIn(50000, 50000, 1234);
    Callback callback = new TestCallback();
    TestCallbackDispatcher dispatcher = new ExceptionCallbackDispatcher();
    BACIDispatchAction action = new BACIDispatchAction(callback, descIn, dispatcher);
    synchronized (dispatcher) {
        action.dispatchDoneRequest(completion, value);
        try {
            // wait 
            dispatcher.wait(RESPONSE_WAIT_TIME);
        } catch (InterruptedException ie) {
        }
    }
    // dummy wait (just in case there is a bug and more responses will come)
    dummyWait();
    // only 3 responses (retries) are expected
    assertEquals(3, dispatcher.getResponseQueue().size());
    // should be the same
    assertEquals(dispatcher.getResponseQueue().get(0), dispatcher.getResponseQueue().get(1));
    DispatchAction response = (DispatchAction) dispatcher.getResponseQueue().firstElement();
    // check response
    checkResponse(value, completion, descIn, callback, response);
}
Also used : BACIDispatchAction(alma.ACS.jbaci.BACIDispatchAction) Completion(alma.ACSErr.Completion) Callback(alma.ACS.Callback) BACIDispatchAction(alma.ACS.jbaci.BACIDispatchAction) CBDescIn(alma.ACS.CBDescIn)

Example 2 with Callback

use of alma.ACS.Callback in project ACS by ACS-Community.

the class BACIDispatchActionTest method testFirstFailed.

/**
	 * First failed then success test.
	 */
public void testFirstFailed() {
    Object value = new Object();
    Completion completion = CompletionUtil.generateNoErrorCompletion();
    CBDescIn descIn = new CBDescIn(50000, 50000, 1234);
    Callback callback = new TestCallback();
    TestCallbackDispatcher dispatcher = new FirstFailedCallbackDispatcher();
    BACIDispatchAction action = new BACIDispatchAction(callback, descIn, dispatcher);
    synchronized (dispatcher) {
        action.dispatchDoneRequest(completion, value);
        try {
            // wait 
            dispatcher.wait(RESPONSE_WAIT_TIME);
        } catch (InterruptedException ie) {
        }
    }
    // dummy wait (just in case there is a bug and more responses will come)
    dummyWait();
    // only 2 (failed and successful) responses are expected
    assertEquals(2, dispatcher.getResponseQueue().size());
    // should be the same
    assertEquals(dispatcher.getResponseQueue().get(0), dispatcher.getResponseQueue().get(1));
    DispatchAction response = (DispatchAction) dispatcher.getResponseQueue().firstElement();
    // check response
    checkResponse(value, completion, descIn, callback, response);
}
Also used : BACIDispatchAction(alma.ACS.jbaci.BACIDispatchAction) Completion(alma.ACSErr.Completion) Callback(alma.ACS.Callback) BACIDispatchAction(alma.ACS.jbaci.BACIDispatchAction) CBDescIn(alma.ACS.CBDescIn)

Example 3 with Callback

use of alma.ACS.Callback in project ACS by ACS-Community.

the class BACIDispatchActionTest method testNormal.

/**
	 * Normal (success) test.
	 */
public void testNormal() {
    Object value = new Object();
    Completion completion = CompletionUtil.generateNoErrorCompletion();
    CBDescIn descIn = new CBDescIn(50000, 50000, 1234);
    Callback callback = new TestCallback();
    TestCallbackDispatcher dispatcher = new PerfectCallbackDispatcher();
    BACIDispatchAction action = new BACIDispatchAction(callback, descIn, dispatcher);
    synchronized (dispatcher) {
        action.dispatchDoneRequest(completion, value);
        try {
            // wait 
            dispatcher.wait(RESPONSE_WAIT_TIME);
        } catch (InterruptedException ie) {
        }
    }
    // dummy wait (just in case there is a bug and more responses will come)
    dummyWait();
    // only 1 response is expected
    assertEquals(1, dispatcher.getResponseQueue().size());
    DispatchAction response = (DispatchAction) dispatcher.getResponseQueue().firstElement();
    // check response
    checkResponse(value, completion, descIn, callback, response);
}
Also used : BACIDispatchAction(alma.ACS.jbaci.BACIDispatchAction) Completion(alma.ACSErr.Completion) Callback(alma.ACS.Callback) BACIDispatchAction(alma.ACS.jbaci.BACIDispatchAction) CBDescIn(alma.ACS.CBDescIn)

Example 4 with Callback

use of alma.ACS.Callback in project ACS by ACS-Community.

the class BACIDispatchActionTest method testOverrideBlockingFailsNoneToOverrideTest.

/**
	 * Override policy test (blocking fails, none to override).
	 */
public void testOverrideBlockingFailsNoneToOverrideTest() {
    Object value = new Object();
    Completion completion = CompletionUtil.generateNoErrorCompletion();
    CBDescIn descIn = new CBDescIn(50000, 50000, 1234);
    Callback callback = new TestCallback();
    TestCallbackDispatcher dispatcher = new OverrideTestCallbackDispatcher(true);
    BACIDispatchAction action = new BACIDispatchAction(callback, descIn, dispatcher);
    action.setOverridePolicy(true);
    synchronized (dispatcher) {
        // blocking request		
        action.dispatchDoneRequest(completion, value);
        try {
            // wait 
            dispatcher.wait(RESPONSE_WAIT_TIME);
        } catch (InterruptedException ie) {
        }
    }
    synchronized (dispatcher) {
        // notift blocking request
        dispatcher.notify();
    }
    // dummy wait (just in case there is a bug and more responses will come)
    dummyWait();
    // only 2 (failed and successful) responses are expected
    assertEquals(2, dispatcher.getResponseQueue().size());
    // should be the same
    assertEquals(dispatcher.getResponseQueue().get(0), dispatcher.getResponseQueue().get(1));
    DispatchAction response = (DispatchAction) dispatcher.getResponseQueue().firstElement();
    // check response
    checkResponse(value, completion, descIn, callback, response);
}
Also used : BACIDispatchAction(alma.ACS.jbaci.BACIDispatchAction) Completion(alma.ACSErr.Completion) Callback(alma.ACS.Callback) BACIDispatchAction(alma.ACS.jbaci.BACIDispatchAction) CBDescIn(alma.ACS.CBDescIn)

Example 5 with Callback

use of alma.ACS.Callback in project ACS by ACS-Community.

the class BACIDispatchActionTest method testAlwaysFails.

/**
	 * Always fails test.
	 */
public void testAlwaysFails() {
    Object value = new Object();
    Completion completion = CompletionUtil.generateNoErrorCompletion();
    CBDescIn descIn = new CBDescIn(50000, 50000, 1234);
    Callback callback = new TestCallback();
    TestCallbackDispatcher dispatcher = new DisasterCallbackDispatcher();
    BACIDispatchAction action = new BACIDispatchAction(callback, descIn, dispatcher);
    synchronized (dispatcher) {
        action.dispatchDoneRequest(completion, value);
        try {
            // wait 
            dispatcher.wait(RESPONSE_WAIT_TIME);
        } catch (InterruptedException ie) {
        }
    }
    // dummy wait (just in case there is a bug and more responses will come)
    dummyWait();
    // only 3 responses (retries) are expected
    assertEquals(3, dispatcher.getResponseQueue().size());
    // should be the same
    assertEquals(dispatcher.getResponseQueue().get(0), dispatcher.getResponseQueue().get(1));
    DispatchAction response = (DispatchAction) dispatcher.getResponseQueue().firstElement();
    // check response
    checkResponse(value, completion, descIn, callback, response);
}
Also used : BACIDispatchAction(alma.ACS.jbaci.BACIDispatchAction) Completion(alma.ACSErr.Completion) Callback(alma.ACS.Callback) BACIDispatchAction(alma.ACS.jbaci.BACIDispatchAction) CBDescIn(alma.ACS.CBDescIn)

Aggregations

CBDescIn (alma.ACS.CBDescIn)6 Callback (alma.ACS.Callback)6 BACIDispatchAction (alma.ACS.jbaci.BACIDispatchAction)6 Completion (alma.ACSErr.Completion)6