internal SubscriptionState(string destinationObject) { this.destinationObject = destinationObject; this.lastSentMessage = null; }
public void testBigMessages() { // Note: // The messages are sent with different priorities, which means // that they might complete in the order that is different from the // order of posting them to the outgoing queue. // The messages are posted with increasing priorities (first message // is sent with lowest priority, last message with highest), // so it is *very likely* that they will be received by server // in the reversed order, but this cannot be guaranteed as there is // no relation between the speed of posting and the speed // of transmission. int numOfMessages = 10; bool[] gotMessages = new bool[numOfMessages]; int sizeOfBigString = 1000000; StringBuilder bigStringBld = new StringBuilder(sizeOfBigString); for (int i = 0; i != sizeOfBigString; ++i) { bigStringBld.Append('x'); } string bigString = bigStringBld.ToString(); serverAgent.RegisterObject(objectName, delegate(object sender, IncomingMessageArgs args) { Parameters receivedContent = args.Message.Parameters; int id = receivedContent.GetInteger("id"); // uncomment it to see how the messages get reordered // verify the big value //Console.WriteLine("received message {0}", id); gotMessages[id] = true; Assert.AreEqual(bigString, receivedContent.GetString("big")); args.Message.Reply(null); }); Parameters content = new Parameters(); content.SetString("big", bigString); OutgoingMessage[] messages = new OutgoingMessage[numOfMessages]; // send all messages with different ids and priorities for (int i = 0; i != numOfMessages; ++i) { int id = i; int priority = i; // increasing priority content.SetInteger("id", id); messages[i] = clientAgent.Send( serverAddress, objectName, messageName, content, priority); } // wait for all messages to complete for (int i = 0; i != numOfMessages; ++i) { messages[i].WaitForCompletion(); messages[i].Close(); } for (int i = 0; i != numOfMessages; ++i) { Assert.IsTrue(gotMessages[i]); } }