예제 #1
0
    public long _5_0_ConnectionFailed(Disquuun disquuun)
    {
        WaitUntil("_5_0_ConnectionFailed", () => (disquuun.State() == Disquuun.ConnectionState.OPENED), 5);

        Exception error     = null;
        var       disquuun2 = new Disquuun(
            DisquuunTests.TestDisqueHostStr,
            DisquuunTests.TestDisqueDummyPortNum,// fake port number.
            1,
            1,
            (conId) => { },
            (info, e) =>
        {
            error = e;
        },
            (currentSocketCount, addSocket) =>
        {
            return;
        }
            );

        WaitUntil("_5_0_ConnectionFailed", () => (error != null), 5);
        disquuun2.Disconnect();
        return(0);
    }
예제 #2
0
 public void Disconnect()
 {
     if (disquuun != null)
     {
         disquuun.Disconnect();
     }
 }
예제 #3
0
    public long _5_1_ConnectionFailedMultiple(Disquuun disquuun)
    {
        WaitUntil("_5_1_ConnectionFailedMultiple", () => (disquuun.State() == Disquuun.ConnectionState.OPENED), 5);

        List <Exception> errors = new List <Exception>();

        var disquuun2 = new Disquuun(
            DisquuunTests.TestDisqueHostStr,
            DisquuunTests.TestDisqueDummyPortNum,// fake port number.
            1,
            5,
            (conId) => { },
            (info, e) =>
        {
            lock (_5_1_ConnectionFailedMultipleLockObject)
            {
                errors.Add(e);
            }
        },
            (currentSocketCount, addSocket) =>
        {
            return;
        }
            );

        WaitUntil("_5_1_ConnectionFailedMultiple", () => (errors.Count == 5), 10);
        disquuun2.Disconnect();
        return(0);
    }
예제 #4
0
    public long _0_1_ConnectedShouldCallOnce(Disquuun disquuun)
    {
        int connectedCount = 0;
        var w = new Stopwatch();

        w.Start();

        disquuun = new Disquuun(DisquuunTests.TestDisqueHostStr, DisquuunTests.TestDisquePortNum, 1024, 100,
                                disquuunId =>
        {
            lock (_0_1_ConnectedShouldCallOnceObject)
            {
                Assert("_0_1_ConnectedShouldCallOnce", 0, connectedCount, "not match.");
                connectedCount++;
            }
        },
                                (i, e) => { },
                                (currentSocketCount, addSocket) =>
        {
            return;
        }
                                );

        WaitUntil("_0_1_ConnectedShouldCallOnce", () => (connectedCount == 1), 5);

        disquuun.Disconnect();
        w.Stop();
        return(w.ElapsedMilliseconds);
    }
예제 #5
0
    public long _0_0_1_WaitOnOpen2Connection(Disquuun disquuun)
    {
        var w = new Stopwatch();

        w.Start();

        var conId     = string.Empty;
        var disquuun2 = new Disquuun(DisquuunTests.TestDisqueHostStr, DisquuunTests.TestDisquePortNum, 1, 1,
                                     connectionId =>
        {
            conId = connectionId;
        },
                                     (info, e) =>
        {
        },
                                     (currentSocketCount, addSocket) =>
        {
            return;
        }
                                     );

        WaitUntil("_0_0_1_WaitOnOpen2Connection", () => !string.IsNullOrEmpty(conId), 5);

        disquuun2.Disconnect();
        w.Stop();
        return(w.ElapsedMilliseconds);
    }
예제 #6
0
    public void _0_0_2_ReadmeSampleSync(Disquuun disquuun)
    {
        bool overed = false;

        disquuun = new Disquuun(DisquuunTests.TestDisqueHostStr, DisquuunTests.TestDisquePortNum, 1024, 1,
                                disquuunId => {
            var queueId = Guid.NewGuid().ToString();

            // addjob. add 10bytes job to Disque.
            disquuun.AddJob(queueId, new byte[10]).DEPRICATED_Sync();

            // getjob. get job from Disque.
            var result   = disquuun.GetJob(new string[] { queueId }).DEPRICATED_Sync();
            var jobDatas = DisquuunDeserializer.GetJob(result);

            Assert("_0_0_2_ReadmeSampleSync", 1, jobDatas.Length, "not match.");

            // fastack.
            var jobId = jobDatas[0].jobId;
            disquuun.FastAck(new string[] { jobId }).DEPRICATED_Sync();

            overed = true;
        }
                                );

        WaitUntil("", () => overed, 5);

        disquuun.Disconnect();
    }
예제 #7
0
    public long _0_0_3_ReadmeSampleAsync(Disquuun disquuun)
    {
        var w = new Stopwatch();

        w.Start();

        int fastAckedJobCount = 0;

        disquuun = new Disquuun(DisquuunTests.TestDisqueHostStr, DisquuunTests.TestDisquePortNum, 1024, 3,
                                disquuunId =>
        {
            var queueId = Guid.NewGuid().ToString();

            // addjob. add 10bytes job to Disque.
            disquuun.AddJob(queueId, data_10).Async(
                (addJobCommand, addJobData) =>
            {
                // job added to queueId @ Disque.

                // getjob. get job from Disque.
                disquuun.GetJob(new string[] { queueId }).Async(
                    (getJobCommand, getJobData) =>
                {
                    // got job from queueId @ Disque.

                    var jobDatas = DisquuunDeserializer.GetJob(getJobData);
                    Assert("_0_0_3_ReadmeSampleAsync", 1, jobDatas.Length, "not match.");

                    // get jobId from got job data.
                    var gotJobId = jobDatas[0].jobId;

                    // fastack it.
                    disquuun.FastAck(new string[] { gotJobId }).Async(
                        (fastAckCommand, fastAckData) =>
                    {
                        // fastack succeded or not.

                        fastAckedJobCount = DisquuunDeserializer.FastAck(fastAckData);
                        Assert("_0_0_3_ReadmeSampleAsync", 1, fastAckedJobCount, "not match.");
                    }
                        );
                }
                    );
            }
                );
        },
                                (i, e) => { },
                                (currentSocketCount, addSocket) =>
        {
            return;
        }
                                );

        WaitUntil("_0_0_3_ReadmeSampleAsync", () => (fastAckedJobCount == 1), 5);

        disquuun.Disconnect();
        w.Stop();
        return(w.ElapsedMilliseconds);
    }
예제 #8
0
        public void Connect(string contextQueueIdentity, string ip, int port)
        {
            disquuun = new Disquuun(
                ip,
                port,
                1024 * 100,
                30,
                conId => {
                // enable adding job to Disque by swapping publisher method.
                //context.Setup(Publish);

                // start getting job from disque then fastack all automatically.
                disquuun.GetJob(new string[] { contextQueueIdentity }, "count", 10000).Loop(
                    (command, data) => {
                    var jobs = DisquuunDeserializer.GetJob(data);

                    var jobIds   = jobs.Select(jobData => jobData.jobId).ToArray();
                    var jobDatas = jobs.Select(jobData => jobData.jobData).ToList();

                    /*
                     *  fast ack all.
                     */
                    disquuun.FastAck(jobIds).Async((command2, data2) => { });

                    InputDatasToContext(jobDatas);
                    return(true);
                }
                    );
            },
                (conId, err) => {
                Logger.Error("disque failed. state = " + disquuun.connectionState + ", message = " + err.Message);

                if (disquuun.connectionState != Disquuun.ConnectionState.OPENING &&
                    disquuun.connectionState != Disquuun.ConnectionState.ALLCLOSING)
                {
                    disquuun.Disconnect();
                    Logger.Error("disque self disconnected.");
                }

                disqueReconnector.Reconnect(this, Connect);
            }
                );
        }
예제 #9
0
    public void _0_0_4_ConnectedShouldCallOnce(Disquuun disquuun)
    {
        int connectedCount = 0;

        disquuun = new Disquuun(DisquuunTests.TestDisqueHostStr, DisquuunTests.TestDisquePortNum, 1024, 100,
                                disquuunId => {
            Assert("_0_0_4_ConnectedShouldCallOnce", 0, connectedCount, "not match.");
            connectedCount++;
        }
                                );

        WaitUntil("_0_0_4_ConnectedShouldCallOnce", () => (connectedCount == 1), 5);

        disquuun.Disconnect();
    }
예제 #10
0
    public void _0_0_1_WaitOnOpen2Connection(Disquuun disquuun)
    {
        var conId     = string.Empty;
        var disquuun2 = new Disquuun(DisquuunTests.TestDisqueHostStr, DisquuunTests.TestDisquePortNum, 1, 1,
                                     connectionId => {
            conId = connectionId;
        },
                                     (info, e) => {
        }
                                     );

        WaitUntil("_0_0_1_WaitOnOpen2Connection", () => !string.IsNullOrEmpty(conId), 5);

        disquuun2.Disconnect();
    }
예제 #11
0
    public void _0_0_3_ReadmeSampleAsync(Disquuun disquuun)
    {
        int fastAckedJobCount = 0;

        disquuun = new Disquuun(DisquuunTests.TestDisqueHostStr, DisquuunTests.TestDisquePortNum, 1024, 3,
                                disquuunId => {
            var queueId = Guid.NewGuid().ToString();

            // addjob. add 10bytes job to Disque.
            disquuun.AddJob(queueId, new byte[10]).Async(
                (addJobCommand, addJobData) => {
                // job added to queueId @ Disque.

                // getjob. get job from Disque.
                disquuun.GetJob(new string[] { queueId }).Async(
                    (getJobCommand, getJobData) => {
                    // got job from queueId @ Disque.

                    var jobDatas = DisquuunDeserializer.GetJob(getJobData);
                    Assert("_0_0_3_ReadmeSampleAsync", 1, jobDatas.Length, "not match.");

                    // get jobId from got job data.
                    var gotJobId = jobDatas[0].jobId;

                    // fastack it.
                    disquuun.FastAck(new string[] { gotJobId }).Async(
                        (fastAckCommand, fastAckData) => {
                        // fastack succeded or not.

                        fastAckedJobCount = DisquuunDeserializer.FastAck(fastAckData);
                        Assert("_0_0_3_ReadmeSampleAsync", 1, fastAckedJobCount, "not match.");
                    }
                        );
                }
                    );
            }
                );
        }
                                );

        WaitUntil("_0_0_3_ReadmeSampleAsync", () => (fastAckedJobCount == 1), 5);

        disquuun.Disconnect();
    }
예제 #12
0
    public long _0_0_2_ReadmeSampleSync(Disquuun disquuun)
    {
        var w = new Stopwatch();

        w.Start();

        bool overed = false;

        disquuun = new Disquuun(DisquuunTests.TestDisqueHostStr, DisquuunTests.TestDisquePortNum, 1024, 1,
                                disquuunId =>
        {
            var queueId = Guid.NewGuid().ToString();

            // addjob. add 10bytes job to Disque.
            disquuun.AddJob(queueId, data_10).DEPRICATED_Sync();

            // getjob. get job from Disque.
            var result   = disquuun.GetJob(new string[] { queueId }).DEPRICATED_Sync();
            var jobDatas = DisquuunDeserializer.GetJob(result);

            Assert("_0_0_2_ReadmeSampleSync", 1, jobDatas.Length, "not match.");

            // fastack.
            var jobId = jobDatas[0].jobId;
            disquuun.FastAck(new string[] { jobId }).DEPRICATED_Sync();

            overed = true;
        },
                                (i, e) => { },
                                (currentSocketCount, addSocket) =>
        {
            return;
        }
                                );

        WaitUntil("", () => overed, 5);

        disquuun.Disconnect();
        w.Stop();
        return(w.ElapsedMilliseconds);
    }
예제 #13
0
    public void _0_1_ConnectionFailedWithNoDisqueServer(Disquuun disquuun)
    {
        Exception          e      = null;
        Action <Exception> Failed = (Exception e2) => {
            // set error to param,
            e = e2;
            // TestLogger.Log("e:" + e);
        };

        var disquuun2 = new Disquuun(DisquuunTests.TestDisqueHostStr, 8888, 1024, 1,
                                     conId => {},
                                     (info, e2) => {
            // set error to param,
            e = e2;
            // TestLogger.Log("e:" + e);
        }
                                     );

        WaitUntil("_0_1_ConnectionFailedWithNoDisqueServer", () => (e != null), 1);

        disquuun2.Disconnect();
    }
예제 #14
0
    public void RunTests()
    {
        var tests = new List <Func <Disquuun, long> >();

        for (var i = 0; i < 1; i++)
        {
            // basement.
            tests.Add(_0_0_InitWith2Connection);

            tests.Add(_0_0_1_WaitOnOpen2Connection);
            tests.Add(_0_0_2_ReadmeSampleSync);
            tests.Add(_0_0_3_ReadmeSampleAsync);
            tests.Add(_0_0_4_ReadmeSamplePipeline);
            tests.Add(_0_1_ConnectedShouldCallOnce);
            tests.Add(_0_1_ConnectionFailedWithNoDisqueServer);
            tests.Add(_0_2_SyncInfo);
            tests.Add(_0_3_SyncInfoTwice);
            tests.Add(_0_4_AsyncInfo);
            tests.Add(_0_5_LoopInfo_Once);
            tests.Add(_0_6_LoopInfo_Twice);
            tests.Add(_0_7_LoopInfo_100);
            tests.Add(_0_8_Pipeline_Single);
            tests.Add(_0_9_Pipeline);

            // sync apis. DEPRECATED.
            tests.Add(_1_0_AddJob_Sync);
            tests.Add(_1_0_1_AddJob_Sync_TimeToLive);
            tests.Add(_1_0_2_AddJob_Sync_TimeToLive_Wait_Dead);
            tests.Add(_1_0_3_AddJob_Sync_Retry);
            tests.Add(_1_0_4_AddJob_Sync_Retry_0_And_TTL_1Sec);
            tests.Add(_1_1_GetJob_Sync);
            tests.Add(_1_1_1_GetJobWithCount_Sync);
            tests.Add(_1_1_2_GetJobFromMultiQueue_Sync);
            tests.Add(_1_1_3_GetJobWithNoHang_Sync);
            tests.Add(_1_2_AckJob_Sync);
            tests.Add(_1_3_Fastack_Sync);
            tests.Add(_1_1_4_GetJobWithCounters_Sync);
            // tests.Add(_1_4_Working_Sync);
            // tests.Add(_1_5_Nack_Sync);
            tests.Add(_1_6_Info_Sync);
            tests.Add(_1_7_Hello_Sync);
            tests.Add(_1_8_Qlen_Sync);
            tests.Add(_1_9_Qstat_Sync);
            // tests.Add(_1_10_Qpeek_Sync);
            // tests.Add(_1_11_Enqueue_Sync);
            // tests.Add(_1_12_Dequeue_Sync);
            // tests.Add(_1_13_DelJob_Sync);
            // tests.Add(_1_14_Show_Sync);
            // tests.Add(_1_15_Qscan_Sync);
            // tests.Add(_1_16_Jscan_Sync);
            // tests.Add(_1_17_Pause_Sync);

            // async apis.
            tests.Add(_2_0_AddJob_Async);
            tests.Add(_2_0_1_AddJob_Async_TimeToLive);
            tests.Add(_2_0_2_AddJob_Async_TimeToLive_Wait_Dead);
            tests.Add(_2_0_3_AddJob_Async_Retry);
            tests.Add(_2_0_4_AddJob_Async_Retry_0_And_TTL_1Sec);
            tests.Add(_2_1_GetJob_Async);
            tests.Add(_2_1_1_GetJobWithCount_Async);
            tests.Add(_2_1_2_GetJobFromMultiQueue_Async);
            tests.Add(_2_1_3_GetJobWithNoHang_Async);
            tests.Add(_2_1_4_GetJobWithCounters_Async);
            tests.Add(_2_2_AckJob_Async);
            tests.Add(_2_3_Fastack_Async);
            // tests.Add(_2_4_Working_Async);
            // tests.Add(_2_5_Nack_Async);
            tests.Add(_2_6_Info_Async);
            tests.Add(_2_7_Hello_Async);
            tests.Add(_2_8_Qlen_Async);
            tests.Add(_2_9_Qstat_Async);
            // tests.Add(_2_10_Qpeek_Async);
            // tests.Add(_2_11_Enqueue_Async);
            // tests.Add(_2_12_Dequeue_Async);
            // tests.Add(_2_13_DelJob_Async);
            // tests.Add(_2_14_Show_Async);
            // tests.Add(_2_15_Qscan_Async);
            // tests.Add(_2_16_Jscan_Async);
            // tests.Add(_2_17_Pause_Async);

            // multiSocket.
            tests.Add(_3_0_Nested2AsyncSocket);
            tests.Add(_3_1_NestedMultipleAsyncSocket);

            // buffer over.
            tests.Add(_4_0_ByfferOverWithSingleSyncGetJob_Sync);
            tests.Add(_4_1_ByfferOverWithMultipleSyncGetJob_Sync);
            tests.Add(_4_2_ByfferOverWithSokcetOverSyncGetJob_Sync);
            tests.Add(_4_3_ByfferOverWithSingleSyncGetJob_Async);
            tests.Add(_4_4_ByfferOverWithMultipleSyncGetJob_Async);
            tests.Add(_4_5_ByfferOverWithSokcetOverSyncGetJob_Async);

            // error handling.
            tests.Add(_5_0_ConnectionFailed);
            tests.Add(_5_1_ConnectionFailedMultiple);

            // adding async request over busy-socket num.
            tests.Add(_6_0_ExceededSocketNo3In2);
            tests.Add(_6_1_ExceededSocketNo100In2);
            tests.Add(_6_2_ExceededSocketShouldStacked);

            // benchmarks.
            tests.Add(_7_0_AddJob1000);
            tests.Add(_7_0_0_AddJob1000by100Connection);
            tests.Add(_7_0_1_AddJob1000byPipeline);
            tests.Add(_7_0_2_AddJob1000byPipelines);
            tests.Add(_7_1_GetJob1000);
            tests.Add(_7_1_0_GetJob1000by100Connection);
            tests.Add(_7_1_1_GetJob1000byPipeline);
            tests.Add(_7_1_2_GetJob1000byPipelines);
            tests.Add(_7_2_GetJob1000byLoop);

            // scalable benchmarks.
            tests.Add(_8_0_AddJob1000);
            tests.Add(_8_0_0_AddJob1000by100Connection);
            tests.Add(_8_0_1_AddJob1000byPipeline);
            tests.Add(_8_0_2_AddJob1000byPipelines);
            tests.Add(_8_1_GetJob1000);
            tests.Add(_8_1_0_GetJob1000by100Connection);
            tests.Add(_8_1_1_GetJob1000byPipeline);
            tests.Add(_8_1_2_GetJob1000byPipelines);
            tests.Add(_8_2_GetJob1000byLoop);

            // data size bounding case.
            tests.Add(_9_0_LargeSizeSendThenSmallSizeSendMakeEmitOnSendAfterOnReceived);
            tests.Add(_9_1_LargeSizeSendThenSmallSizeSendLoopMakeEmitOnSendAfterOnReceived);

            // pipeline
            tests.Add(_0_10_0_PipelineCommands);
            tests.Add(_0_10_1_MultiplePipeline);
            tests.Add(_0_10_2_MultipleCommandPipeline);
            tests.Add(_0_10_3_SomeCommandPipeline);
            tests.Add(_0_10_4_MassiveCommandPipeline);
            tests.Add(_0_10_5_Pipelines);
        }

        try
        {
            var disquuunForResultInfo = new Disquuun(
                DisquuunTests.TestDisqueHostStr,
                DisquuunTests.TestDisquePortNum,
                10240,
                1
                );
            WaitUntil(
                "_internal",
                () => disquuunForResultInfo.State() == Disquuun.ConnectionState.OPENED,
                5
                );

            var i = 0;
            foreach (var test in tests)
            {
                var methodName = i.ToString() + "_" + test.Method.Name;

                i++;

                try
                {
                    var disquuun = new Disquuun(
                        DisquuunTests.TestDisqueHostStr,
                        DisquuunTests.TestDisquePortNum,
                        2020008,
                        20,
                        (id) => { },
                        (k, e) => { },
                        (currentSocketCount, addSocket) =>
                    {
                        return;
                    }
                        );// this buffer size is just for 100byte job x 10000 then receive 1 GetJob(count 1000).

                    // すべての接続ができるまで待つ
                    WaitUntil(
                        "_internal",
                        () => disquuun.State() == Disquuun.ConnectionState.OPENED,
                        5
                        );

                    var elapsedMilliSec = test(disquuun);

                    if (disquuun != null)
                    {
                        disquuun.Disconnect();
                        disquuun = null;
                    }

                    var info         = disquuunForResultInfo.Info().DEPRICATED_Sync();
                    var result       = DisquuunDeserializer.Info(info);
                    var restJobCount = result.jobs.registered_jobs;

                    if (restJobCount != 0)
                    {
                        TestLogger.Log("test:" + methodName + "     rest job:" + restJobCount, true);
                    }
                    else
                    {
                        TestLogger.Log("test:" + methodName + "     passed. elapsedMilliSec:" + elapsedMilliSec, true);
                    }
                }
                catch (Exception e)
                {
                    TestLogger.Log("test:" + methodName + "     FAILED by exception:" + e, true);
                }
            }

            disquuunForResultInfo.Disconnect();
            TestLogger.Log("tests end.", true);
        }
        catch (Exception e)
        {
            TestLogger.Log("tests failed:" + e, true);
        }
    }
예제 #15
0
    public long _8_0_2_AddJob1000byPipelines(Disquuun disquuun)
    {
        WaitUntil("_8_0_2_AddJob1000byPipelines", () => (disquuun.State() == Disquuun.ConnectionState.OPENED), 5);

        var count = 1000 * ratio;

        var connectedCount = 0;

        disquuun = new Disquuun(DisquuunTests.TestDisqueHostStr, DisquuunTests.TestDisquePortNum, 1024, 10,
                                disquuunId =>
        {
            connectedCount++;
        },
                                (info, e) =>
        {
            TestLogger.Log("error, info:" + info + " e:" + e.Message);
        },
                                (currentSocketCount, addSocket) =>
        {
            if (100 < currentSocketCount)
            {
                return;
            }
            addSocket(true, 1);
        }
                                );

        WaitUntil("_8_0_2_AddJob1000byPipelines 0", () => (connectedCount == 1), 5);

        var addedCount = 0;

        var queueId = Guid.NewGuid().ToString();

        var w = new Stopwatch();

        w.Start();
        for (var i = 0; i < count; i++)
        {
            if (i == count / 2)
            {
                disquuun.RevolvePipeline();
            }
            disquuun.Pipeline(disquuun.AddJob(queueId, data_10));
        }
        disquuun.Pipeline().Execute(
            (command, data) =>
        {
            lock (_8_0_2_AddJob1000byPipelinesObject) addedCount++;
        }
            );

        w.Stop();

        WaitUntil("_8_0_2_AddJob1000byPipelines 1", () => (addedCount == count), 100);

        var gotCount = 0;

        disquuun.GetJob(new string[] { queueId }, "count", count).Async(
            (command, data) =>
        {
            var jobDatas = DisquuunDeserializer.GetJob(data);
            var jobIds   = jobDatas.Select(j => j.jobId).ToArray();
            disquuun.FastAck(jobIds).Async(
                (c2, d2) =>
            {
                var fastackCount = DisquuunDeserializer.FastAck(d2);
                lock (_8_0_2_AddJob1000byPipelinesObject)
                {
                    gotCount += fastackCount;
                }
            }
                );
        }
            );

        WaitUntil("_8_0_2_AddJob1000byPipelines 2", () => (gotCount == count), 10);
        disquuun.Disconnect();

        return(w.ElapsedMilliseconds);
    }
예제 #16
0
    public void _7_0_0_AddJob1000by100Connectoion(Disquuun disquuun)
    {
        WaitUntil("_7_0_0_AddJob1000by100Connectoion", () => (disquuun.State() == Disquuun.ConnectionState.OPENED), 5);

        var count = 1000 * loadLevel;

        var connectedCount = 0;

        disquuun = new Disquuun(DisquuunTests.TestDisqueHostStr, DisquuunTests.TestDisquePortNum, 1024, 100,
                                disquuunId => {
            connectedCount++;
        },
                                (info, e) => {
            TestLogger.Log("error, info:" + info + " e:" + e.Message);
        }
                                );



        WaitUntil("_7_0_0_AddJob1000by100Connectoion 0", () => (connectedCount == 1), 5);

        var addedCount = 0;

        var queueId = Guid.NewGuid().ToString();

        var w = new Stopwatch();

        w.Start();
        for (var i = 0; i < count; i++)
        {
            disquuun.AddJob(queueId, new byte[10]).Async(
                (command, data) => {
                lock (_7_0_0_AddJob1000by100ConnectoionLockObject) addedCount++;
            }
                );
        }
        w.Stop();
        TestLogger.Log("_7_0_0_AddJob1000by100Connectoion w:" + w.ElapsedMilliseconds + " tick:" + w.ElapsedTicks);

        WaitUntil("_7_0_0_AddJob1000by100Connectoion 1", () => (addedCount == count), 100);

        var gotCount = 0;

        disquuun.GetJob(new string[] { queueId }, "count", count).Async(
            (command, data) => {
            var jobDatas = DisquuunDeserializer.GetJob(data);
            var jobIds   = jobDatas.Select(j => j.jobId).ToArray();
            disquuun.FastAck(jobIds).Async(
                (c2, d2) => {
                var fastackCount = DisquuunDeserializer.FastAck(d2);
                lock (_7_0_0_AddJob1000by100ConnectoionLockObject) {
                    gotCount += fastackCount;
                }
            }
                );
        }
            );

        WaitUntil("_7_0_0_AddJob1000by100Connectoion 2", () => (gotCount == count), 10);
        disquuun.Disconnect();
    }
예제 #17
0
    public void _7_1_0_GetJob1000by100Connection(Disquuun disquuun)
    {
        WaitUntil("_7_1_0_GetJob1000by100Connection", () => (disquuun.State() == Disquuun.ConnectionState.OPENED), 5);

        var addingJobCount = 1000 * loadLevel;

        var connected = false;

        disquuun = new Disquuun(DisquuunTests.TestDisqueHostStr, DisquuunTests.TestDisquePortNum, 1024, 100,
                                disquuunId => {
            connected = true;
        },
                                (info, e) => {
            TestLogger.Log("error, info:" + info + " e:" + e.Message);
        }
                                );

        WaitUntil("_7_1_0_GetJob1000by100Connection", () => connected, 5);

        var addedCount = 0;

        var queueId = Guid.NewGuid().ToString();

        for (var i = 0; i < addingJobCount; i++)
        {
            disquuun.AddJob(queueId, new byte[10]).Async(
                (command, data) => {
                lock (_7_1_0_GetJob1000by100ConnectionLockObject) addedCount++;
            }
                );
        }


        WaitUntil("_7_1_0_GetJob1000by100Connection", () => (addedCount == addingJobCount), 10);

        var gotJobDataIds = new List <string>();


        var w = new Stopwatch();

        w.Start();
        for (var i = 0; i < addingJobCount; i++)
        {
            disquuun.GetJob(new string[] { queueId }).Async(
                (command, data) => {
                lock (_7_1_0_GetJob1000by100ConnectionLockObject) {
                    var jobDatas = DisquuunDeserializer.GetJob(data);
                    var jobIds   = jobDatas.Select(j => j.jobId).ToList();
                    gotJobDataIds.AddRange(jobIds);
                }
            }
                );
        }

        WaitUntil("_7_1_0_GetJob1000by100Connection", () => (gotJobDataIds.Count == addingJobCount), 10);


        w.Stop();
        TestLogger.Log("_7_1_0_GetJob1000by100Connection w:" + w.ElapsedMilliseconds + " tick:" + w.ElapsedTicks);

        var result = DisquuunDeserializer.FastAck(disquuun.FastAck(gotJobDataIds.ToArray()).DEPRICATED_Sync());

        Assert("_7_1_0_GetJob1000by100Connection", addingJobCount, result, "result not match.");
        disquuun.Disconnect();
    }
예제 #18
0
    public long _8_1_2_GetJob1000byPipelines(Disquuun disquuun)
    {
        WaitUntil("_8_1_2_GetJob1000byPipelines", () => (disquuun.State() == Disquuun.ConnectionState.OPENED), 5);

        var addingJobCount = 1000 * ratio;

        var connected = false;

        disquuun = new Disquuun(DisquuunTests.TestDisqueHostStr, DisquuunTests.TestDisquePortNum, 1024, 10,
                                disquuunId =>
        {
            connected = true;
        },
                                (info, e) =>
        {
            TestLogger.Log("error, info:" + info + " e:" + e.Message);
        },
                                (currentSocketCount, addSocket) =>
        {
            if (100 < currentSocketCount)
            {
                return;
            }
            addSocket(true, 1);
        }
                                );

        WaitUntil("_8_1_2_GetJob1000byPipelines", () => connected, 5);

        var addedCount = 0;

        var queueId = Guid.NewGuid().ToString();

        for (var i = 0; i < addingJobCount; i++)
        {
            disquuun.Pipeline(disquuun.AddJob(queueId, data_10));
        }

        disquuun.Pipeline().Execute(
            (command, data) =>
        {
            lock (_8_1_2_GetJob1000byPipelinesObject) addedCount++;
        }
            );


        WaitUntil("_8_1_2_GetJob1000byPipelines", () => (addedCount == addingJobCount), 10);

        var gotJobDataIds = new List <string>();


        var w = new Stopwatch();

        w.Start();
        for (var i = 0; i < addingJobCount; i++)
        {
            if (i == addingJobCount / 2)
            {
                disquuun.RevolvePipeline();
            }
            disquuun.Pipeline(disquuun.GetJob(new string[] { queueId }));
        }
        disquuun.Pipeline().Execute(
            (command, data) =>
        {
            lock (_8_1_2_GetJob1000byPipelinesObject)
            {
                var jobDatas = DisquuunDeserializer.GetJob(data);
                var jobIds   = jobDatas.Select(j => j.jobId).ToList();
                gotJobDataIds.AddRange(jobIds);
            }
        }
            );

        WaitUntil("_8_1_2_GetJob1000byPipelines", () => (gotJobDataIds.Count == addingJobCount), 10);

        w.Stop();

        var result = DisquuunDeserializer.FastAck(disquuun.FastAck(gotJobDataIds.ToArray()).DEPRICATED_Sync());

        Assert("_8_1_2_GetJob1000byPipelines", addingJobCount, result, "result not match.");
        disquuun.Disconnect();

        return(w.ElapsedMilliseconds);
    }
예제 #19
0
    public void RunTests()
    {
        var tests = new List <Action <Disquuun> >();

        for (var i = 0; i < 1; i++)
        {
            // basement.
            tests.Add(_0_0_InitWith2Connection);
            tests.Add(_0_0_1_WaitOnOpen2Connection);
            tests.Add(_0_0_2_ReadmeSampleSync);
            tests.Add(_0_0_3_ReadmeSampleAsync);
            tests.Add(_0_0_4_ConnectedShouldCallOnce);
            tests.Add(_0_1_ConnectionFailedWithNoDisqueServer);
            tests.Add(_0_2_SyncInfo);
            tests.Add(_0_3_SyncInfoTwice);
            tests.Add(_0_4_AsyncInfo);
            tests.Add(_0_5_LoopInfo_Once);
            tests.Add(_0_6_LoopInfo_Twice);
            tests.Add(_0_7_LoopInfo_100);

            // sync apis. DEPRECATED.
            tests.Add(_1_0_AddJob_Sync);
            tests.Add(_1_1_GetJob_Sync);
            tests.Add(_1_1_1_GetJobWithCount_Sync);
            tests.Add(_1_1_2_GetJobFromMultiQueue_Sync);
            tests.Add(_1_1_3_GetJobWithNoHang_Sync);
            tests.Add(_1_2_AckJob_Sync);
            tests.Add(_1_3_Fastack_Sync);
            tests.Add(_1_1_4_GetJobWithCounters_Sync);
            // tests.Add(_1_4_Working_Sync);
            // tests.Add(_1_5_Nack_Sync);
            tests.Add(_1_6_Info_Sync);
            tests.Add(_1_7_Hello_Sync);
            tests.Add(_1_8_Qlen_Sync);
            tests.Add(_1_9_Qstat_Sync);
            // tests.Add(_1_10_Qpeek_Sync);
            // tests.Add(_1_11_Enqueue_Sync);
            // tests.Add(_1_12_Dequeue_Sync);
            // tests.Add(_1_13_DelJob_Sync);
            // tests.Add(_1_14_Show_Sync);
            // tests.Add(_1_15_Qscan_Sync);
            // tests.Add(_1_16_Jscan_Sync);
            // tests.Add(_1_17_Pause_Sync);

            // async apis.
            tests.Add(_2_0_AddJob_Async);
            tests.Add(_2_1_GetJob_Async);
            tests.Add(_2_1_1_GetJobWithCount_Async);
            tests.Add(_2_1_2_GetJobFromMultiQueue_Async);
            tests.Add(_2_1_3_GetJobWithNoHang_Async);
            tests.Add(_2_1_4_GetJobWithCounters_Async);
            tests.Add(_2_2_AckJob_Async);
            tests.Add(_2_3_Fastack_Async);
            // tests.Add(_2_4_Working_Async);
            // tests.Add(_2_5_Nack_Async);
            tests.Add(_2_6_Info_Async);
            tests.Add(_2_7_Hello_Async);
            tests.Add(_2_8_Qlen_Async);
            tests.Add(_2_9_Qstat_Async);
            // tests.Add(_2_10_Qpeek_Async);
            // tests.Add(_2_11_Enqueue_Async);
            // tests.Add(_2_12_Dequeue_Async);
            // tests.Add(_2_13_DelJob_Async);
            // tests.Add(_2_14_Show_Async);
            // tests.Add(_2_15_Qscan_Async);
            // tests.Add(_2_16_Jscan_Async);
            // tests.Add(_2_17_Pause_Async);

            // multiSocket.
            tests.Add(_3_0_Nested2AsyncSocket);
            tests.Add(_3_1_NestedMultipleAsyncSocket);

            // buffer over.
            tests.Add(_4_0_ByfferOverWithSingleSyncGetJob_Sync);
            tests.Add(_4_1_ByfferOverWithMultipleSyncGetJob_Sync);
            tests.Add(_4_2_ByfferOverWithSokcetOverSyncGetJob_Sync);
            tests.Add(_4_3_ByfferOverWithSingleSyncGetJob_Async);
            tests.Add(_4_4_ByfferOverWithMultipleSyncGetJob_Async);
            tests.Add(_4_5_ByfferOverWithSokcetOverSyncGetJob_Async);

            // error handling.
            tests.Add(_5_0_ConnectionFailed);
            tests.Add(_5_1_ConnectionFailedMultiple);

            // adding async request over busy-socket num.
            tests.Add(_6_0_ExceededSocketNo3In2);
            tests.Add(_6_1_ExceededSocketNo100In2);
            tests.Add(_6_2_ExceededSocketShouldStacked);

            // benchmarks.
            tests.Add(_7_0_AddJob1000);
            tests.Add(_7_0_0_AddJob1000by100Connectoion);
            tests.Add(_7_1_GetJob1000);
            tests.Add(_7_1_0_GetJob1000by100Connection);
            tests.Add(_7_2_GetJob1000byLoop);

            // data size bounding case.
            tests.Add(_8_0_LargeSizeSendThenSmallSizeSendMakeEmitOnSendAfterOnReceived);
            tests.Add(_8_1_LargeSizeSendThenSmallSizeSendLoopMakeEmitOnSendAfterOnReceived);
        }

        try {
            TestLogger.Log("tests started.", true);

            var disquuunForResultInfo = new Disquuun(DisquuunTests.TestDisqueHostStr, DisquuunTests.TestDisquePortNum, 10240, 1);
            WaitUntil("testRunner:", () => (disquuunForResultInfo.State() == Disquuun.ConnectionState.OPENED), 5);
            var i = 0;
            foreach (var test in tests)
            {
                var methodName = i.ToString() + test.GetType();
                i++;

                try {
                    var disquuun = new Disquuun(DisquuunTests.TestDisqueHostStr, DisquuunTests.TestDisquePortNum, 2020008, 2);                    // this buffer size is just for 100byte job x 10000 then receive 1 GetJob(count 1000).
                    test(disquuun);
                    if (disquuun != null)
                    {
                        disquuun.Disconnect();
                        disquuun = null;
                    }

                    var info         = disquuunForResultInfo.Info().DEPRICATED_Sync();
                    var result       = DisquuunDeserializer.Info(info);
                    var restJobCount = result.jobs.registered_jobs;

                    if (restJobCount != 0)
                    {
                        TestLogger.Log("test:" + methodName + " rest job:" + restJobCount, true);
                    }
                    else
                    {
                        TestLogger.Log("test:" + methodName + " passed. no job exists.", true);
                    }
                } catch (Exception e) {
                    TestLogger.Log("before error...", true);
                    TestLogger.Log("test:" + methodName + " FAILED by exception:" + e, true);
                }
            }

            disquuunForResultInfo.Disconnect();
            TestLogger.Log("tests end.", true);
        } catch (Exception e) {
            TestLogger.Log("tests failed:" + e.Message, true);
        }
    }
예제 #20
0
    public long _7_1_GetJob1000(Disquuun disquuun)
    {
        WaitUntil("_7_1_GetJob1000", () => (disquuun.State() == Disquuun.ConnectionState.OPENED), 5);

        var addingJobCount = 1000 * ratio;

        var connected = false;

        disquuun = new Disquuun(DisquuunTests.TestDisqueHostStr, DisquuunTests.TestDisquePortNum, 1024, 10,
                                disquuunId =>
        {
            connected = true;
        },
                                (info, e) =>
        {
            TestLogger.Log("error, info:" + info + " e:" + e.Message, true);
            throw e;
        },
                                (currentSocketCount, addSocket) =>
        {
            return;
        }
                                );

        var r0 = WaitUntil("r0 _7_1_GetJob1000", () => connected, 5);

        if (!r0)
        {
            return(0);
        }

        var addedCount = 0;

        var queueId = Guid.NewGuid().ToString();

        for (var i = 0; i < addingJobCount; i++)
        {
            disquuun.AddJob(queueId, data_10).Async(
                (command, data) =>
            {
                lock (_7_1_GetJob1000Lock) addedCount++;
            }
                );
        }

        var r1 = WaitUntil("r1 _7_1_GetJob1000", () => (addedCount == addingJobCount), 10);

        if (!r1)
        {
            return(0);
        }

        var gotJobDataIds = new List <string>();


        var w = new Stopwatch();

        w.Start();
        for (var i = 0; i < addingJobCount; i++)
        {
            disquuun.GetJob(new string[] { queueId }).Async(
                (command, data) =>
            {
                lock (_7_1_GetJob1000Lock)
                {
                    var jobDatas = DisquuunDeserializer.GetJob(data);
                    var jobIds   = jobDatas.Select(j => j.jobId).ToList();
                    gotJobDataIds.AddRange(jobIds);
                }
            }
                );
        }

        var r2 = WaitUntil("r2 _7_1_GetJob1000", () => (gotJobDataIds.Count == addingJobCount), 10);

        if (!r2)
        {
            TestLogger.Log("gotJobDataIds:" + gotJobDataIds.Count, true);
            return(0);
        }

        w.Stop();

        var result = DisquuunDeserializer.FastAck(disquuun.FastAck(gotJobDataIds.ToArray()).DEPRICATED_Sync());

        Assert("_7_1_GetJob1000", addingJobCount, result, "result not match.");
        disquuun.Disconnect();

        return(w.ElapsedMilliseconds);
    }