public void WriteRead(Tuple tuple) { Client1.Write(tuple); var result = Client1.Read(tuple); Assert.AreEqual(tuple, result); }
/** * Helper method to run with another thread, for example for ReadWrite test, we want a client to start reading before * there is any tuple in the space, and then write with another client, to test if the reading client gets the result */ private void readAndSetVar(Tuple tuple) { Tuple temp = Client1.Read(tuple); lock (lockObject){ sharedTuple = temp; Monitor.Pulse(lockObject); } }
public void ReadWrite(Tuple tuple) { // start a client to read a tuple that doesnt exist yet , and it will block until it gets something Thread readThread = new Thread(() => readAndSetVar(tuple)); readThread.Start(); Client2.Write(tuple); lock (lockObject){ Monitor.Wait(lockObject, new TimeSpan(0, 0, 2)); Assert.AreEqual(tuple, sharedTuple); } }
/** * Searches the pending list of read and take requests for any request that tried to read/take this tuple */ private Request GetAndRemoveSinglePendingRequest(Tuple tuple) { lock (PendingRequestList){ foreach (Request req in PendingRequestList) { if (req.GetType() == typeof(ReadRequest) || req.GetType() == typeof(TakeRequest) && req.Tuple.Equals(tuple)) { return(req); } } } return(null); }
private void Write(Tuple tuple) { TupleSpace.Write(tuple); Log("Wrote : " + tuple); }
public void Write(Tuple tuple) { Client1.Write(tuple); }