public void testPollingUnSubscribe() { PollingClient client = new PollingClient(SUB_PORT); try { client.subscribe(REMOTE_HOST, REMOTE_PORT, REMOTE_TABLE_NAME, 0); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.Write(ex.StackTrace); Assert.Fail(ex.Message); } PollingClient client1 = new PollingClient(SUB_PORT); try { client1.unsubscribe(REMOTE_HOST, REMOTE_PORT, REMOTE_TABLE_NAME); } catch (Exception e) { Assert.Fail(e.Message); } }
public void testPolling() { PollingClient client = new PollingClient(SUB_PORT); try { TopicPoller poller = client.subscribe(REMOTE_HOST, REMOTE_PORT, REMOTE_TABLE_NAME, 0); int count = 0; bool started = false; long start = DateTime.Now.Ticks; long last = DateTime.Now.Ticks; while (true) { List <IMessage> messages = poller.poll(TIMEOUT); if (messages == null || messages.Count == 0) { start = DateTime.Now.Ticks; continue; } int messageCount = messages.Count; if (messageCount > 0 && !started) { started = true; start = DateTime.Now.Ticks; } count += messageCount; foreach (IMessage message in messages) { string symbol = message.getEntity(0).getString(); string price = message.getEntity(1).getString(); string size = message.getEntity(2).getString(); string ex = message.getEntity(3).getString(); } if (messageCount > 0) { if (((BasicInt)messages.Last().getEntity(4)).getValue() == -1) { break; } } long now = DateTime.Now.Ticks; if (now - last >= 1000) { long batchEnd = DateTime.Now.Ticks; Console.WriteLine(count + " messages took " + ((batchEnd - start) / 1000.0) + " ms, throghput: " + count / ((batchEnd - start) / 1000000.0) + " messages/s"); last = now; } } long end = DateTime.Now.Ticks; Console.WriteLine(count + " messages took " + ((end - start) / 1000.0) + " ms, throghput: " + count / ((end - start) / 1000000.0) + " messages/s"); System.Environment.Exit(0); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.Write(ex.StackTrace); Assert.Fail(ex.Message); } }
public virtual void PollingClient() { PollingClient client = new PollingClient(subscribePORT); try { TopicPoller poller1 = client.subscribe(HOST, PORT, "Trades"); int count = 0; bool started = false; long start = DateTime.Now.Ticks; long last = DateTime.Now.Ticks; while (true) { List <IMessage> msgs = poller1.poll(1000); if (msgs == null) { count = 0; start = DateTime.Now.Ticks; continue; } if (msgs.Count > 0 && started == false) { started = true; start = DateTime.Now.Ticks; } count += msgs.Count; for (int i = 0; i < msgs.Count; ++i) { BasicTime time = (BasicTime)msgs[i].getEntity(1); Console.Write("time:" + time + " "); string symbol = msgs[i].getEntity(2).getString(); Console.Write("sym:" + symbol + " "); int qty = ((BasicInt)msgs[i].getEntity(3)).getValue(); Console.Write("qty:" + qty + " "); double?price = ((BasicDouble)msgs[i].getEntity(4)).getValue(); Console.Write("price:" + price + " \n"); } if (msgs.Count > 0) { if (((BasicInt)msgs[msgs.Count - 1].getEntity(0)).getValue() == -1) { break; } } long now = DateTime.Now.Ticks; if (now - last >= 1000) { long endtime = DateTime.Now.Ticks; Console.WriteLine(count + " messages took " + (endtime - start) + "ms, throughput: " + count / ((endtime - start) / 1000.0) + " messages/s"); last = now; } } long end = DateTime.Now.Ticks; Console.WriteLine(count + " messages took " + (end - start) + "ms, throughput: " + count / ((end - start) / 1000.0) + " messages/s"); client.unsubscribe(HOST, PORT, "Trades"); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } Environment.Exit(0); }