private void Pull(int SIZE, QueueServerClient client, Dictionary <ulong, int> dictionary) { Console.WriteLine(); Console.WriteLine("pull and commit " + SIZE); var stopwatch = Stopwatch.StartNew(); for (int i = 0; i < SIZE; i++) { var data = client.Pull(); var remoteValue = Adf.BaseDataConverter.ToInt32(data.Data); var localValue = 0; dictionary.TryGetValue(data.MessageId, out localValue); //diff value if (localValue != remoteValue) { Console.WriteLine("receive result error, local: {0} - remote : {1}, dup:{2}", localValue, remoteValue, data.Duplications); } //diff index if (i != remoteValue) { Console.WriteLine("receive result error, index: {0} - remote : {1}, dup:{2}", i, remoteValue, data.Duplications); } client.Commit(data.MessageId); } stopwatch.Stop(); Console.WriteLine((SIZE / (double)(stopwatch.ElapsedMilliseconds / 1000)).ToString("0.000") + "/s"); }
//private void ParallelPushAndPullAsync(int SIZE, QueueServerClient client, Dictionary<ulong, int> dictionary) //{ // Console.WriteLine(); // Console.WriteLine("parallel async push - async pull - commit " + SIZE); // System.Threading.ManualResetEvent waitHandle1 = new System.Threading.ManualResetEvent(false); // var stopwatch = Stopwatch.StartNew(); // QueueServerPushAck pushAck = (ulong transferId, ulong messageId, QueueServerErrorCode errorCode, string errorMessage) => // { // lock (dictionary) // dictionary.Add(messageId, (int)transferId); // if ((int)transferId == SIZE - 1) // { // waitHandle1.Set(); // stopwatch.Stop(); // } // }; // client.PushAck += pushAck; // System.Threading.ThreadPool.QueueUserWorkItem(q => // { // stopwatch.Reset(); // stopwatch.Start(); // for (uint i = 0; i < SIZE; i++) // { // var data = Adf.BaseDataConverter.ToBytes(i); // client.PushAsync(data, i); // } // }); // this.PullAsync(SIZE, client, dictionary); // waitHandle1.WaitOne(); // client.PushAck -= pushAck; // Console.WriteLine("push async:" + (SIZE / (double)(stopwatch.ElapsedMilliseconds / 1000)) + "/s"); //} private void ParallelPushAndPullCommit(int SIZE, QueueServerClient client, Dictionary <ulong, int> dictionary) { Console.WriteLine(); Console.WriteLine("parallel push / pull-commit " + SIZE); System.Threading.ManualResetEvent waitHandle1 = new System.Threading.ManualResetEvent(false); System.Threading.ThreadPool.QueueUserWorkItem(s => { var stopwatch1 = Stopwatch.StartNew(); stopwatch1.Start(); for (int i = 0; i < SIZE; i++) { var data = Adf.BaseDataConverter.ToBytes(i); var msgid = client.RPush(data); lock (dictionary) dictionary.Add(msgid, i); } stopwatch1.Stop(); Console.WriteLine("push:" + (SIZE / (double)(stopwatch1.ElapsedMilliseconds / 1000)).ToString("0.000") + "/s"); waitHandle1.Set(); }); System.Threading.ManualResetEvent waitHandle2 = new System.Threading.ManualResetEvent(false); System.Threading.ThreadPool.QueueUserWorkItem(s => { var stopwatch1 = Stopwatch.StartNew(); stopwatch1.Start(); for (int i = 0; i < SIZE; i++) { var data = client.Pull(); var remoteValue = Adf.BaseDataConverter.ToInt32(data.Data); var localValue = 0; lock (dictionary) dictionary.TryGetValue(data.MessageId, out localValue); //diff value if (localValue != remoteValue) { Console.WriteLine("receive result error, local: {0} - remote : {1}, dup: {2}", localValue, remoteValue, data.Duplications); } client.Commit(data.MessageId); } stopwatch1.Stop(); Console.WriteLine("pull:" + (SIZE / (double)(stopwatch1.ElapsedMilliseconds / 1000)).ToString("0.000") + "/s"); waitHandle2.Set(); }); waitHandle1.WaitOne(); waitHandle2.WaitOne(); }
private void CheckAutoRollback(QueueServerClient client) { client.Select(client.Topic, 5); Console.WriteLine("push one message and pull no commit,wait timeout 10s, check auto rollback"); //client.RPush(""); var msg = client.Pull(); System.Threading.Thread.Sleep(10000); try { client.Rollback(msg.MessageId); //成功则表示未自动 rollback, Console.WriteLine("commit timeout error"); } catch { } Console.WriteLine("completed"); }