public void SingleDeviceSendToAndPeekAndCommitTest() { var ocassionalConnectionClient = new OccasionallyConnectionClient(PlatformApi, _deviceId, _apiKey); ocassionalConnectionClient.SendMessageTo(_deviceId, "msg1"); ocassionalConnectionClient.SendMessageTo(_deviceId, "msg2"); var result1 = ocassionalConnectionClient.PeekMessage(); Assert.IsTrue(result1.MessageId >= 0); Assert.IsTrue(result1.Payload == "msg1"); Assert.IsTrue(result1.Timestamp > new DateTime(2014, 1, 1)); Assert.AreEqual(_deviceId, result1.SenderDeviceId); var result2 = ocassionalConnectionClient.PeekMessage(); Assert.AreEqual(result1.MessageId, result2.MessageId); Assert.IsTrue(result2.Payload == "msg1"); Assert.IsTrue(result2.Timestamp > new DateTime(2014, 1, 1)); Assert.AreEqual(_deviceId, result2.SenderDeviceId); ocassionalConnectionClient.CommitMessage(); var result3 = ocassionalConnectionClient.PeekMessage(); Assert.AreEqual(result2.MessageId + 1, result3.MessageId); Assert.IsTrue(result3.Payload == "msg2"); Assert.IsTrue(result3.Timestamp > new DateTime(2014, 1, 1)); }
private static void OcassionalRecvCommit(string[] lines, int deviceOrder, int sleep) { var line = lines[deviceOrder]; var parts = line.Split(' '); var deviceId = parts[0]; var apiKey = parts[1]; Log(deviceId); var ocassionalConnectionClient = new OccasionallyConnectionClient(Config.PlatformApi, deviceId, apiKey); int cnt = 0; while (true) { PushedMessage pushedMsg = null; try { pushedMsg = ocassionalConnectionClient.PeekMessage(); cnt++; } catch (WebException) { Log("peekthrottled"); } try { if (pushedMsg != null) { ocassionalConnectionClient.CommitMessage(); } cnt++; } catch (WebException) { Log("commiythrottled"); } Thread.Sleep(sleep); Log((cnt / 2).ToString() + ((pushedMsg != null) ? "PM" : "")); } }
public void SingleDeviceCommitNothingTest() { var ocassionalConnectionClient = new OccasionallyConnectionClient(PlatformApi, _deviceId, _apiKey); ocassionalConnectionClient.CommitMessage(); }