⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bigatomtransferclient.java

📁 SRI international 发布的OAA框架软件
💻 JAVA
字号:
package com.sri.oaa2.test.client;

import com.sri.oaa2.test.agent.OaaTest_T;
import com.sri.oaa2.icl.IclList;
import com.sri.oaa2.icl.IclTerm;
import com.sri.oaa2.agentlib.AgentException;
import junit.framework.Assert;
import junit.framework.TestCase;

/**
 * Author: Chris Brigham (cbrigham)
 * Date: Jul 12, 2004
 * Time: 2:05:47 PM
 * Description:
 */
public class BigAtomTransferClient extends TestCase {

    OaaTest_T oaaTest;
    final int timeout = 180000;

    public BigAtomTransferClient(String test) {
        super(test);
    }

    public void setUp() {
        oaaTest = new OaaTest_T() {
            public String getAgentName() {
                return "BigAtomTransferClient";
            }

        };
    }

    public void testDirectConnect() {
        copyData(true);
    }

    public void testFacilitator() {
        copyData(false);
    }

    private synchronized void copyData(boolean dc){
        int[] data = {
            10,
            100,
            1000,
            10000,
            65536,
            261122,
            500000,
            1000000,
        };

        try {
            oaaTest.facilitatorConnect(new String[]{});

            for (int i = 0; i < data.length; i++) {
                // create a new thread to do the test work
                // this sidesteps the problem of the facilitator not ever returning if the datasize is too big.
                // instead, the test will now timeout and fail
                BigAtomTransferThread batt = new BigAtomTransferThread(Thread.currentThread(), oaaTest, data[i], dc);
                batt.start();

                // sleep until interrupted.  if not interrupted, timeout and fail this test.
                try {
                    Thread.sleep(timeout);
                    batt.stop();
                    Assert.assertTrue("oaaSolve did not return in allotted time ("+timeout+" msecs) when given atom of size " + data[i],false);
                } catch (InterruptedException e) {/* this is good */}

            }

        } catch (AgentException e) {
            e.printStackTrace();
            Assert.assertTrue(false);
        }
    }

    private class BigAtomTransferThread extends Thread{

        int datasize;
        OaaTest_T oaaTest;
        boolean dc;
        Thread parent;

        private BigAtomTransferThread(Thread parent, OaaTest_T oaaTest, int datasize, boolean dc){
            this.oaaTest = oaaTest;
            this.datasize = datasize;
            this.dc = dc;
            this.parent = parent;
        }

        public void run(){

            String random = makeString(datasize);
            IclList answers;
            try{
                if(dc){
                    System.out.print("TESTING "+datasize+" length String via direct_connect using full_goal.....");
                    answers = oaaTest.solve("copyString(DataOriginal, DataCopy)", "[direct_connect(true),full_goal(copyString("+random+", DataCopy))]");
                    System.out.println("DONE.");
                }else{
                    System.out.print("TESTING "+datasize+" length String via facilitator.....");
                    answers = oaaTest.solve("copyString(" + random + ", DataCopy)", "[]");
                    System.out.println("DONE.");
                }
                try {
                    Assert.assertEquals("Atom of size " + datasize + " failed through " + (dc ? "direct_connect" : "fac"), IclTerm.fromString(random), answers.getTerm(0).getTerm(1));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                parent.interrupt();
            } catch(Exception e){}

        }

        private String makeString(int size) {
            StringBuffer s = new StringBuffer();

            for (int indx = 0; indx < size; indx++) {
                char c = (char) ('a' + Math.round(Math.random() * ('z' - 'a')));
                s.append(c);
            }

            return s.toString();
        }
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -