public void TestAccumuatorSuccess() { Accumulator <int> accumulator = sc.Accumulator <int>(0); using (var s = sock.GetStream()) { // write numUpdates int numUpdates = 1; SerDe.Write(s, numUpdates); // write update int key = 0; int value = 100; Tuple <int, dynamic> update = new Tuple <int, dynamic>(key, value); var ms = new MemoryStream(); var formatter = new BinaryFormatter(); formatter.Serialize(ms, update); byte[] sendBuffer = ms.ToArray(); SerDe.Write(s, sendBuffer.Length); SerDe.Write(s, sendBuffer); s.Flush(); byte[] receiveBuffer = new byte[1]; s.Read(receiveBuffer, 0, 1); Assert.AreEqual(accumulator.Value, value); } }
public void TestAccumuatorSuccess() { var sc = new SparkContext(null); Accumulator <int> accumulator = sc.Accumulator <int>(0); // get accumulator server port and connect to accumuator server int serverPort = (sc.SparkContextProxy as MockSparkContextProxy).AccumulatorServerPort; var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); sock.Connect(IPAddress.Loopback, serverPort); using (var s = new NetworkStream(sock)) { // write numUpdates int numUpdates = 1; SerDe.Write(s, numUpdates); // write update int key = 0; int value = 100; KeyValuePair <int, dynamic> update = new KeyValuePair <int, dynamic>(key, value); var ms = new MemoryStream(); var formatter = new BinaryFormatter(); formatter.Serialize(ms, update); byte[] sendBuffer = ms.ToArray(); SerDe.Write(s, sendBuffer.Length); SerDe.Write(s, sendBuffer); s.Flush(); byte[] receiveBuffer = new byte[1]; s.Read(receiveBuffer, 0, 1); Assert.AreEqual(accumulator.Value, value); // try to let service side to close gracefully sc.Stop(); try { numUpdates = 0; SerDe.Write(s, numUpdates); } catch { // do nothing here } } sock.Close(); }
public void TestAccumuatorSuccess() { var sc = new SparkContext(null); Accumulator<int> accumulator = sc.Accumulator<int>(0); // get accumulator server port and connect to accumuator server int serverPort = (sc.SparkContextProxy as MockSparkContextProxy).AccumulatorServerPort; var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); sock.Connect(IPAddress.Loopback, serverPort); using (var s = new NetworkStream(sock)) { // write numUpdates int numUpdates = 1; SerDe.Write(s, numUpdates); // write update int key = 0; int value = 100; KeyValuePair<int, dynamic> update = new KeyValuePair<int, dynamic>(key, value); var ms = new MemoryStream(); var formatter = new BinaryFormatter(); formatter.Serialize(ms, update); byte[] sendBuffer = ms.ToArray(); SerDe.Write(s, sendBuffer.Length); SerDe.Write(s, sendBuffer); s.Flush(); byte[] receiveBuffer = new byte[1]; s.Read(receiveBuffer, 0, 1); Assert.AreEqual(accumulator.Value, value); // try to let service side to close gracefully sc.Stop(); try { numUpdates = 0; SerDe.Write(s, numUpdates); } catch { // do nothing here } } sock.Close(); }