SstCloseTest() {
        plugins.load( "tcpsst" );

        uint32 randport = 3000 + (uint32)(Sirikata::Task::LocalTime::now().raw() % 20000);
        mPort = boost::lexical_cast<std::string>(randport);

        mBytes=65536;
        mChunks=3;
        mOffset=1;
        mSendService = new IOServicePool(4);
        mSendStrand = mSendService->service()->createStrand();
        mRecvService = new IOServicePool(4);
        mRecvStrand = mRecvService->service()->createStrand();
        mListener = StreamListenerFactory::getSingleton().getDefaultConstructor()(mRecvStrand,StreamListenerFactory::getSingleton().getDefaultOptionParser()(String()));
        using std::tr1::placeholders::_1;
        using std::tr1::placeholders::_2;
        mListener->listen(Address("127.0.0.1",mPort),std::tr1::bind(&SstCloseTest::listenerNewStreamCallback,this,_1,_2));

        mRecvService->run();
#ifdef _WIN32
        Sleep(1000);
#else
        sleep(1);
#endif

    }
Example #2
0
    SstTest():mCount(0),mDisconCount(0),mEndCount(0),ENDSTRING("T end"),mAbortTest(false) {
        Sirikata::PluginManager plugins;
        plugins.load( Sirikata::DynamicLibrary::filename("tcpsst") );
        mPort="9142";

        mServicePool = new IOServicePool(1);

        mListener = StreamListenerFactory::getSingleton().getDefaultConstructor()(mServicePool->service(),StreamListenerFactory::getSingleton().getDefaultOptionParser()(String()));
        using std::tr1::placeholders::_1;
        using std::tr1::placeholders::_2;
        mListener->listen(Address("127.0.0.1",mPort),std::tr1::bind(&SstTest::listenerNewStreamCallback,this,0,_1,_2));

        mServicePool->run();

        bool doUnorderedTest=true;
        bool doShortTest=false;

        if (doUnorderedTest){
            mMessagesToSend.push_back("U:0");
            mMessagesToSend.push_back("U:1");
            mMessagesToSend.push_back("U:2");
        }
        mMessagesToSend.push_back("T0th");
        mMessagesToSend.push_back("T1st");
        mMessagesToSend.push_back("T2nd");
        mMessagesToSend.push_back("T3rd");
        mMessagesToSend.push_back("T4th");
        mMessagesToSend.push_back("T5th");
        if (doUnorderedTest){
            mMessagesToSend.push_back("U:3");
            mMessagesToSend.push_back("U:4");
            mMessagesToSend.push_back("U:5");
        }
        mMessagesToSend.push_back("T6th");
        mMessagesToSend.push_back("T7th");
        mMessagesToSend.push_back("T8th");
        mMessagesToSend.push_back("T9th");
        if (!doShortTest) {
        std::string test("T");
        for (unsigned int i=0;i<16385;++i) {
            test+=(char)((i+5)%128);
        }
        mMessagesToSend.push_back(test);
        if (doUnorderedTest){
        test[0]='U';
        mMessagesToSend.push_back(test);
}
        for (unsigned int i=0;i<256*1024;++i) {
            test+=(char)((rand())%256);
        }
        if (doUnorderedTest){
        mMessagesToSend.push_back(test);
}
        test[0]='T';
        mMessagesToSend.push_back(test);
        int pattern[40]={127,257,511,65537,129,16383,254,255,16384,256,16385,32767,1440,32768,32769,65535,65536,1401,1399,1280,
                         228,25215,5141,627,151,1,4,124240,3,296,114385,25,17,47,42,24222,655,1441,1439,1024};
        for (size_t i=0;i<sizeof(pattern)/sizeof(pattern[0]);++i) {
            std::string pat="T";
            for (int j=0;j<pattern[i];++j) {
                pat+='~'-(i%((pattern[i]%90)+3));
            }
            mMessagesToSend.push_back(pat);
            pat[0]='U';
            mMessagesToSend.push_back(pat);
        }
        mMessagesToSend.push_back("T_0th");
        mMessagesToSend.push_back("T_1st");
        mMessagesToSend.push_back("T_2nd");
        mMessagesToSend.push_back("T_3rd");
        mMessagesToSend.push_back("T_4th");
        mMessagesToSend.push_back("T_5th");
        if (doUnorderedTest){
            mMessagesToSend.push_back("U:6");
            mMessagesToSend.push_back("U:7");
            mMessagesToSend.push_back("U:8");
            mMessagesToSend.push_back("U:9");
            mMessagesToSend.push_back("U:A");
        }
        mMessagesToSend.push_back("T_6th");
        mMessagesToSend.push_back("T_7th");
        if (doUnorderedTest){
            mMessagesToSend.push_back("U:B");
        }
        mMessagesToSend.push_back("T_8th");
        if (doUnorderedTest){
            mMessagesToSend.push_back("U:C");
        }
        mMessagesToSend.push_back("T_9th");
        if (doUnorderedTest){
            mMessagesToSend.push_back("U:D");
        }
        mMessagesToSend.push_back("The green grasshopper fetched.");
        if (doUnorderedTest){
            mMessagesToSend.push_back("U:E");
            mMessagesToSend.push_back("U:F");
            mMessagesToSend.push_back("U:G");
        }
        mMessagesToSend.push_back("T A blade of grass.");
        mMessagesToSend.push_back("T From the playground .");
        mMessagesToSend.push_back("T Grounds test test test this is a test test test this is a test test test this is a test test test test and the test is proceeding until it reaches signific length with a string that long however. this is not quite long enough to trigger the high water mark--well now it is I believe to the best of my abilities");
        mMessagesToSend.push_back("T Grounds test test test this is a test test test this is a test test test this is a test test test test and the test is proceeding until it reaches signific length with a string that long however. this is not quite");
        if (doUnorderedTest){
            mMessagesToSend.push_back("U:H");
            mMessagesToSend.push_back("U:I");
            mMessagesToSend.push_back("U:J");
            mMessagesToSend.push_back("U:K");
            mMessagesToSend.push_back("U:L");
            mMessagesToSend.push_back("U:M");
            mMessagesToSend.push_back("U:N");
            mMessagesToSend.push_back("U:O");
            mMessagesToSend.push_back("U:P");
            mMessagesToSend.push_back("U:Q");
        }
        }
        mMessagesToSend.push_back(ENDSTRING);

    }
    void closeStreamRun(bool fork, bool doSleep=false) {
        using std::tr1::placeholders::_1;
        using std::tr1::placeholders::_2;

        for(int i=0;i<NUM_TEST_STREAMS;++i) {
            mReceivers[i]=mSenders[i]=NULL;
            mSendReceiveMap[i]=-1;
            mReceiversData[i]=0;
        }

        for(int i=0;i<NUM_TEST_STREAMS;++i) {
            if (i==0||!fork) {
                mSenders[i]=StreamFactory::getSingleton().getDefaultConstructor()(mSendStrand,StreamFactory::getSingleton().getDefaultOptionParser()(String("--parallel-sockets=1")));
                mSenders[i]->connect(Address("127.0.0.1",mPort),
                                     &Stream::ignoreSubstreamCallback,
                                     std::tr1::bind(&SstCloseTest::connectionCallback,this,i,_1,_2),
                                     &Stream::ignoreReceivedCallback,
                                     &Stream::ignoreReadySendCallback);
            }else {
                mSenders[i]=mSenders[0]->clone(  std::tr1::bind(&SstCloseTest::connectionCallback,this,i,_1,_2),
                                     &Stream::ignoreReceivedCallback,
                                     &Stream::ignoreReadySendCallback);

            }

        }
        mSendService->reset();
        mSendService->run();
#ifdef _WIN32
        //Sleep(1000);
#else
        sleep(1);
#endif

        int sentSoFar=0;
        for (int c=0;c<mChunks;++c) {
            int willHaveSent=(c+1)*mBytes/mChunks;

            Chunk cur(willHaveSent-sentSoFar);
            for (size_t j=0;j<cur.size();++j) {
                cur[j]=j+sentSoFar;
            }
            for (int i=0;i<NUM_TEST_STREAMS;++i) {
                if (cur.size()) {
                    cur[0]=i%256;
                    if (cur.size()>1) {
                        cur[1]=i/256%256;
                    }
                    if (cur.size()>2) {
                        cur[2]=i/256/256%256;
                    }
                    if (cur.size()>3) {
                        cur[3]=i/256/256/256%256;
                    }
                }
                bool retval=mSenders[i]->send(MemoryReference(cur),ReliableUnordered);
                TS_ASSERT(retval);

            }
            if (doSleep) {
#ifdef _WIN32
                Sleep(1000);
#else
//                sleep(1);
#endif
            }
            sentSoFar=willHaveSent;
        }
        if (!doSleep) {
#ifdef _WIN32
            Sleep(1000);
#else
//            sleep(1);
#endif
        }
        //SILOG(tcpsst,error,"CLOSING");
        for (int i=mOffset;i<NUM_TEST_STREAMS;++i) {
            mSenders[i]->close();
        }
        //SILOG(tcpsst,error,"CLOSED");
        bool done=true;
        int counter=0;
        do {
            done=true;
            for (int i=mOffset;i<NUM_TEST_STREAMS;++i) {
                if (mReceiversData[i].read()!=mBytes*2+1) {
                    done=false;
                    if (counter>4998) {
                        SILOG(ssttest,error,"Data "<<i<<" only "<<mReceiversData[i].read()<<" != "<<mBytes*2+1);
                    }
                }
            }
            if (counter>4997&&!done) {
#ifdef _WIN32
                Sleep(1000);
#else
                sleep (1);
#endif
            }
            ++counter;
        }while (counter<5000&&!done);
        TS_ASSERT(done);
        for (int i=0;i<NUM_TEST_STREAMS;++i) {
            delete mSenders[i];
            mSenders[i]=NULL;
        }
        for (int i=0;i<NUM_TEST_STREAMS;++i) {
            delete mReceivers[i];
            mReceivers[i]=NULL;
        }
    }