Search in sources :

Example 1 with FrontendMultipleQueryAsyncResult

use of org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult in project ovirt-engine by oVirt.

the class FrontendTest method testrunMultipleQueries_multiple_success_and_failure.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a multiple search query, with multiple requests, with *win* or *lin* as the parameter,
 *   searching for VMs</li>
 *   <li>Return success, the success status is succeeded, with a failure in the result set</li>
 *   <li>Check to make sure the appropriate query start and query complete events are fired</li>
 * </ol>
 */
@Test
public void testrunMultipleQueries_multiple_success_and_failure() {
    // Don't immediately call process until both queries are in the queue.
    fakeScheduler.setThreshold(2);
    ArrayList<QueryType> queryTypeList = new ArrayList<>();
    queryTypeList.add(QueryType.Search);
    queryTypeList.add(QueryType.Search);
    ArrayList<QueryParametersBase> queryParamsList = new ArrayList<>();
    // $NON-NLS-1$
    queryParamsList.add(new SearchParameters("*win*", SearchType.VM));
    // $NON-NLS-1$
    queryParamsList.add(new SearchParameters("*lin*", SearchType.VM));
    // $NON-NLS-1$
    frontend.runMultipleQueries(queryTypeList, queryParamsList, mockMultipleQueryCallback, ASYNC_OPERATION_TARGET);
    verify(mockService).runMultipleQueries(eq(queryTypeList), eq(queryParamsList), callbackMultipleQueries.capture());
    // Call the failure handler.
    List<QueryReturnValue> result = new ArrayList<>();
    result.add(new QueryReturnValue());
    result.get(0).setSucceeded(false);
    result.add(new QueryReturnValue());
    result.get(1).setSucceeded(true);
    ArgumentCaptor<FrontendMultipleQueryAsyncResult> multipleResultCaptor = ArgumentCaptor.forClass(FrontendMultipleQueryAsyncResult.class);
    callbackMultipleQueries.getValue().onSuccess((ArrayList<QueryReturnValue>) result);
    verify(mockMultipleQueryCallback).executed(multipleResultCaptor.capture());
    assertEquals(// $NON-NLS-1$
    "callback result much match", // $NON-NLS-1$
    result, multipleResultCaptor.getValue().getReturnValues());
    verifyAsyncQuerySucceeded();
}
Also used : SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) ArrayList(java.util.ArrayList) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) QueryType(org.ovirt.engine.core.common.queries.QueryType) FrontendMultipleQueryAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult) Test(org.junit.Test)

Example 2 with FrontendMultipleQueryAsyncResult

use of org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult in project ovirt-engine by oVirt.

the class FrontendTest method testrunMultipleQueries_multiple_success.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a multiple search query, with multiple requests, with *win* or *lin* as the parameter,
 *   searching for VMs</li>
 *   <li>Return success, the success status is succeeded</li>
 *   <li>Check to make sure the appropriate query start and query complete events are fired</li>
 * </ol>
 */
@Test
public void testrunMultipleQueries_multiple_success() {
    // Don't immediately call process until both queries are in the queue.
    fakeScheduler.setThreshold(2);
    ArrayList<QueryType> queryTypeList = new ArrayList<>();
    queryTypeList.add(QueryType.Search);
    queryTypeList.add(QueryType.Search);
    ArrayList<QueryParametersBase> queryParamsList = new ArrayList<>();
    // $NON-NLS-1$
    queryParamsList.add(new SearchParameters("*win*", SearchType.VM));
    // $NON-NLS-1$
    queryParamsList.add(new SearchParameters("*lin*", SearchType.VM));
    // $NON-NLS-1$
    frontend.runMultipleQueries(queryTypeList, queryParamsList, mockMultipleQueryCallback, ASYNC_OPERATION_TARGET);
    verify(mockService).runMultipleQueries(eq(queryTypeList), eq(queryParamsList), callbackMultipleQueries.capture());
    // Call the failure handler.
    List<QueryReturnValue> result = new ArrayList<>();
    result.add(new QueryReturnValue());
    result.get(0).setSucceeded(true);
    result.add(new QueryReturnValue());
    result.get(1).setSucceeded(true);
    ArgumentCaptor<FrontendMultipleQueryAsyncResult> multipleResultCaptor = ArgumentCaptor.forClass(FrontendMultipleQueryAsyncResult.class);
    callbackMultipleQueries.getValue().onSuccess((ArrayList<QueryReturnValue>) result);
    verify(mockMultipleQueryCallback).executed(multipleResultCaptor.capture());
    assertEquals(// $NON-NLS-1$
    "callback result much match", // $NON-NLS-1$
    result, multipleResultCaptor.getValue().getReturnValues());
    verifyAsyncQuerySucceeded();
}
Also used : SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) ArrayList(java.util.ArrayList) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) QueryType(org.ovirt.engine.core.common.queries.QueryType) FrontendMultipleQueryAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult) Test(org.junit.Test)

Example 3 with FrontendMultipleQueryAsyncResult

use of org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult in project ovirt-engine by oVirt.

the class Frontend method runMultipleQueries.

/**
 * Run multiple queries in a single request to the back-end.
 * @param queryTypeList A list of {@code QueryType}s.
 * @param queryParamsList A list of parameters associated with each query.
 * @param callback The callback to call when the query completes.
 * @param state The state object.
 */
public void runMultipleQueries(final List<QueryType> queryTypeList, final List<QueryParametersBase> queryParamsList, final IFrontendMultipleQueryAsyncCallback callback, final Object state) {
    VdcOperationCallbackList<VdcOperation<QueryType, QueryParametersBase>, List<QueryReturnValue>> multiCallback = new VdcOperationCallbackList<VdcOperation<QueryType, QueryParametersBase>, List<QueryReturnValue>>() {

        @Override
        public void onSuccess(final List<VdcOperation<QueryType, QueryParametersBase>> operationList, final List<QueryReturnValue> resultObject) {
            // $NON-NLS-1$
            logger.finer("Succesful returned result from runMultipleQueries!");
            FrontendMultipleQueryAsyncResult f = new FrontendMultipleQueryAsyncResult(queryTypeList, queryParamsList, resultObject);
            callback.executed(f);
            fireAsyncQuerySucceededEvent(state);
        }

        @Override
        public void onFailure(final List<VdcOperation<QueryType, QueryParametersBase>> operationList, final Throwable caught) {
            try {
                if (ignoreFailure(caught)) {
                    return;
                }
                // $NON-NLS-1$
                logger.log(Level.SEVERE, "Failed to execute runMultipleQueries: " + caught, caught);
                FrontendMultipleQueryAsyncResult f = new FrontendMultipleQueryAsyncResult(queryTypeList, queryParamsList, null);
                failureEventHandler(caught);
                callback.executed(f);
            } finally {
                fireAsyncQueryFailedEvent(state);
            }
        }
    };
    List<VdcOperation<?, ?>> operationList = new ArrayList<>();
    for (int i = 0; i < queryTypeList.size(); i++) {
        QueryParametersBase parameters = queryParamsList.get(i);
        // Why do we do this?
        parameters.setRefresh(false);
        initQueryParamsFilter(parameters);
        operationList.add(new VdcOperation<>(queryTypeList.get(i), parameters, true, multiCallback, false));
    }
    fireAsyncOperationStartedEvent(state);
    getOperationManager().addOperationList(operationList);
}
Also used : VdcOperation(org.ovirt.engine.ui.frontend.communication.VdcOperation) ArrayList(java.util.ArrayList) FrontendMultipleQueryAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VdcOperationCallbackList(org.ovirt.engine.ui.frontend.communication.VdcOperationCallbackList) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) VdcOperationCallbackList(org.ovirt.engine.ui.frontend.communication.VdcOperationCallbackList) QueryType(org.ovirt.engine.core.common.queries.QueryType)

Aggregations

ArrayList (java.util.ArrayList)3 QueryParametersBase (org.ovirt.engine.core.common.queries.QueryParametersBase)3 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)3 QueryType (org.ovirt.engine.core.common.queries.QueryType)3 FrontendMultipleQueryAsyncResult (org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult)3 Test (org.junit.Test)2 SearchParameters (org.ovirt.engine.core.common.queries.SearchParameters)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 VdcOperation (org.ovirt.engine.ui.frontend.communication.VdcOperation)1 VdcOperationCallbackList (org.ovirt.engine.ui.frontend.communication.VdcOperationCallbackList)1