Search in sources :

Example 6 with Result

use of com.opensymphony.xwork2.Result in project tis by qlangtech.

the class TestFullbuildWorkflowAction method testAsynJobExecute.

/**
 * 执行异步任务 创建->任务提提交->等待反馈-> 完成
 *
 * @throws Exception
 */
public void testAsynJobExecute() throws Exception {
    FullbuildWorkflowAction.MAX_CAS_RETRY_COUNT = 100;
    /**
     *=====================================================
     * 创建任务
     *     =======================================================
     */
    int taskId = -1;
    final int subTaskSize = 20;
    try {
        String dataxName = "ttt";
        request.setParameter("emethod", "createNewTask");
        request.setParameter("action", "fullbuild_workflow_action");
        request.setParameter(IFullBuildContext.KEY_TRIGGER_TYPE, String.valueOf(TriggerType.MANUAL.getValue()));
        request.setParameter(IFullBuildContext.KEY_APP_NAME, dataxName);
        ActionProxy proxy = getActionProxy();
        this.replay();
        String result = proxy.execute();
        assertEquals("FullbuildWorkflowAction_ajax", result);
        AjaxValve.ActionExecResult aResult = showBizResult();
        assertNotNull(aResult);
        assertTrue(aResult.isSuccess());
        CreateNewTaskResult bizResult = (CreateNewTaskResult) aResult.getBizResult();
        assertNotNull(bizResult);
        taskId = bizResult.getTaskid();
        assertTrue(taskId > 0);
        this.verifyAll();
        this.setUp();
        /**
         *======================================================
         * 提交异步任务
         *       ========================================================
         */
        request.setParameter("emethod", "taskComplete");
        request.setParameter("action", "fullbuild_workflow_action");
        request.setParameter(IParamContext.KEY_TASK_ID, String.valueOf(taskId));
        request.setParameter(IParamContext.KEY_EXEC_RESULT, String.valueOf(ExecResult.SUCCESS.getValue()));
        Set<String> jobs = Sets.newHashSet();
        String[] jobsName = new String[subTaskSize];
        for (int i = 0; i < subTaskSize; i++) {
            jobsName[i] = "customer_order_relation_" + i + ".json";
            jobs.add(jobsName[i]);
        }
        request.setParameter(IParamContext.KEY_ASYN_JOB_NAME, jobsName);
        proxy = getActionProxy();
        result = proxy.execute();
        assertEquals("FullbuildWorkflowAction_ajax", result);
        aResult = showBizResult();
        assertNotNull(aResult);
        assertTrue(aResult.isSuccess());
        WorkFlowBuildHistory history = this.runContext.getWorkflowDAOFacade().getWorkFlowBuildHistoryDAO().selectByPrimaryKey(taskId);
        assertNotNull("taskid:" + taskId + " relevant history", history);
        assertTrue(ExecResult.parse(history.getState()) == ExecResult.ASYN_DOING);
        JSONObject subTaskStatus = JSON.parseObject(history.getAsynSubTaskStatus());
        assertEquals(subTaskSize, subTaskStatus.keySet().size());
        subTaskStatus.forEach((key, val) -> {
            assertTrue(jobs.contains(key));
            JSONObject s = (JSONObject) val;
            assertFalse(key, s.getBoolean(IParamContext.KEY_ASYN_JOB_SUCCESS));
            assertFalse(key, s.getBoolean(IParamContext.KEY_ASYN_JOB_COMPLETE));
        });
        /**
         *======================================================
         * 等待接收反馈信息
         *       ========================================================
         */
        ExecutorService executorService = Executors.newFixedThreadPool(20);
        Throwable[] excep = new Throwable[1];
        CountDownLatch countDown = new CountDownLatch(subTaskSize);
        final int tskid = taskId;
        for (String jobName : jobsName) {
            executorService.submit(() -> {
                try {
                    TestFullbuildWorkflowAction subTest = new TestFullbuildWorkflowAction();
                    subTest.setUp();
                    subTest.feedbackAsynTaskStatus(tskid, jobName);
                    subTest.tearDown();
                } catch (Throwable e) {
                    excep[0] = e;
                } finally {
                    countDown.countDown();
                }
            });
        // this.setUp();
        // feedbackAsynTaskStatus(tskid, jobName);
        }
        countDown.await();
        if (excep[0] != null) {
            throw new RuntimeException(excep[0]);
        }
        history = this.runContext.getWorkflowDAOFacade().getWorkFlowBuildHistoryDAO().selectByPrimaryKey(taskId);
        subTaskStatus = JSON.parseObject(history.getAsynSubTaskStatus());
        assertEquals(subTaskSize, subTaskStatus.keySet().size());
        subTaskStatus.forEach((key, val) -> {
            assertTrue(jobs.contains(key));
            JSONObject s = (JSONObject) val;
            assertTrue(key, s.getBoolean(IParamContext.KEY_ASYN_JOB_SUCCESS));
            assertTrue(key, s.getBoolean(IParamContext.KEY_ASYN_JOB_COMPLETE));
        });
        assertEquals(ExecResult.SUCCESS, ExecResult.parse(history.getState()));
        assertEquals((int) subTaskSize + 1, (int) history.getLastVer());
    } finally {
        if (taskId > 0) {
            this.runContext.getWorkflowDAOFacade().getWorkFlowBuildHistoryDAO().deleteByPrimaryKey(taskId);
        }
    }
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) CountDownLatch(java.util.concurrent.CountDownLatch) JSONObject(com.alibaba.fastjson.JSONObject) CreateNewTaskResult(com.qlangtech.tis.manage.common.CreateNewTaskResult) AjaxValve(com.qlangtech.tis.manage.common.valve.AjaxValve) ExecutorService(java.util.concurrent.ExecutorService) WorkFlowBuildHistory(com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistory)

Example 7 with Result

use of com.opensymphony.xwork2.Result in project tis by qlangtech.

the class TestFullbuildWorkflowAction method feedbackAsynTaskStatus.

// public void testFeedbackAsynTaskStatus() throws Exception {
// feedbackAsynTaskStatus(887, "customer_order_relation_7.json");
// while (true) {
// WorkFlowBuildHistory buildHistory = this.runContext.getWorkflowDAOFacade().getWorkFlowBuildHistoryDAO().selectByPrimaryKey(887);
// System.out.println("last_ver:" + buildHistory.getLastVer());
// Thread.sleep(1000);
// }
// }
private void feedbackAsynTaskStatus(int taskId, String jobName) throws Exception {
    WorkFlowBuildHistory buildHistory = this.runContext.getWorkflowDAOFacade().getWorkFlowBuildHistoryDAO().selectByPrimaryKey(taskId);
    assertNotNull("buildHistory can not be null", buildHistory);
    request.setParameter(IParamContext.KEY_REQUEST_DISABLE_TRANSACTION, String.valueOf(true));
    request.setParameter("emethod", "feedbackAsynTaskStatus");
    request.setParameter("action", "fullbuild_workflow_action");
    request.setParameter(IParamContext.KEY_TASK_ID, String.valueOf(taskId));
    request.setParameter(IParamContext.KEY_ASYN_JOB_NAME, jobName);
    request.setParameter(IParamContext.KEY_ASYN_JOB_SUCCESS, String.valueOf(true));
    ActionProxy proxy = getActionProxy();
    String result = proxy.execute();
    assertEquals("FullbuildWorkflowAction_ajax", result);
    AjaxValve.ActionExecResult aResult = showBizResult();
    assertNotNull(aResult);
    assertTrue(aResult.isSuccess());
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) AjaxValve(com.qlangtech.tis.manage.common.valve.AjaxValve) WorkFlowBuildHistory(com.qlangtech.tis.workflow.pojo.WorkFlowBuildHistory)

Example 8 with Result

use of com.opensymphony.xwork2.Result in project tis by qlangtech.

the class TestFullbuildWorkflowAction method testDoCreateNewTaskWithSingleTableCollectionFullBuild.

public void testDoCreateNewTaskWithSingleTableCollectionFullBuild() throws Exception {
    // createMockCollection(COLLECTION_NAME);
    String collectionName = "search4employee4local";
    request.setParameter("emethod", "createNewTask");
    request.setParameter("action", "fullbuild_workflow_action");
    request.setParameter(IFullBuildContext.KEY_TRIGGER_TYPE, String.valueOf(TriggerType.MANUAL.getValue()));
    request.setParameter(IFullBuildContext.KEY_APP_NAME, collectionName);
    // JSONObject content = new JSONObject();
    // content.put(CollectionAction.KEY_INDEX_NAME, TEST_TABLE_EMPLOYEES_NAME);
    // request.setContent(content.toJSONString().getBytes(TisUTF8.get()));
    ActionProxy proxy = getActionProxy();
    this.replay();
    String result = proxy.execute();
    assertEquals("FullbuildWorkflowAction_ajax", result);
    AjaxValve.ActionExecResult aResult = showBizResult();
    assertNotNull(aResult);
    assertTrue(aResult.isSuccess());
    this.verifyAll();
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) AjaxValve(com.qlangtech.tis.manage.common.valve.AjaxValve)

Example 9 with Result

use of com.opensymphony.xwork2.Result in project tis by qlangtech.

the class TestCoreAction method triggerFullbuildTask.

private void triggerFullbuildTask(TableMeta totalpayMeta, Consumer<AjaxValve.ActionExecResult> consumer) throws Exception {
    request.setParameter("emethod", "trigger_fullbuild_task");
    request.setParameter("action", "core_action");
    setCollection(TestSchemaAction.collection);
    createMockErRules(totalpayMeta);
    DocCollection docCollection = this.createMockCollection(TestSchemaAction.collection, false);
    Collection<Slice> slice = Lists.newArrayList();
    slice.add(null);
    EasyMock.expect(docCollection.getSlices()).andReturn(slice);
    this.replay();
    ActionProxy proxy = getActionProxy();
    String result = proxy.execute();
    assertEquals("CoreAction_ajax", result);
    AjaxValve.ActionExecResult aResult = showBizResult();
    assertNotNull(aResult);
    consumer.accept(aResult);
    this.verifyAll();
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) Slice(org.apache.solr.common.cloud.Slice) AjaxValve(com.qlangtech.tis.manage.common.valve.AjaxValve) DocCollection(org.apache.solr.common.cloud.DocCollection)

Example 10 with Result

use of com.opensymphony.xwork2.Result in project tis by qlangtech.

the class TestAddAppAction method testDoCreateCollection.

/**
 * 测试创建
 *
 * @throws Exception
 */
public void testDoCreateCollection() throws Exception {
    request.setParameter("emethod", "create_collection");
    request.setParameter("action", "add_app_action");
    try (InputStream content = this.getClass().getResourceAsStream("create_confirm_index_http_body.json")) {
        assertNotNull(content);
        request.setContent(IOUtils.toByteArray(content));
    }
    ITISCoordinator zkCoordinator = MockZKUtils.createZkMock();
    MockZooKeeperGetter.mockCoordinator = zkCoordinator;
    setCollection(TestSchemaAction.collection);
    ActionProxy proxy = getActionProxy();
    replay();
    String result = proxy.execute();
    assertEquals("AddAppAction_ajax", result);
    AjaxValve.ActionExecResult aResult = showBizResult();
    assertNotNull(aResult);
    assertTrue(aResult.isSuccess());
    verifyAll();
    IAppSource appSource = IAppSource.load(null, TestSchemaAction.collection);
    assertTrue(appSource instanceof SingleTableAppSource);
}
Also used : ITISCoordinator(com.qlangtech.tis.cloud.ITISCoordinator) ActionProxy(com.opensymphony.xwork2.ActionProxy) InputStream(java.io.InputStream) IAppSource(com.qlangtech.tis.manage.IAppSource) SingleTableAppSource(com.qlangtech.tis.manage.impl.SingleTableAppSource) AjaxValve(com.qlangtech.tis.manage.common.valve.AjaxValve)

Aggregations

ActionSupport (com.opensymphony.xwork2.ActionSupport)63 Test (org.junit.Test)52 ActionProxy (com.opensymphony.xwork2.ActionProxy)51 List (java.util.List)49 ValueStack (com.opensymphony.xwork2.util.ValueStack)38 Result (edu.stanford.CVC4.Result)35 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)34 ActionContext (com.opensymphony.xwork2.ActionContext)33 Expr (edu.stanford.CVC4.Expr)32 SExpr (edu.stanford.CVC4.SExpr)32 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)31 ArrayList (java.util.ArrayList)31 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)30 HashMap (java.util.HashMap)29 Rational (edu.stanford.CVC4.Rational)25 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)22 Map (java.util.Map)21 ServletActionContext (org.apache.struts2.ServletActionContext)21 Result (com.opensymphony.xwork2.Result)18 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)18