예제 #1
0
        public void WriteRead(Tuple tuple)
        {
            Client1.Write(tuple);
            var result = Client1.Read(tuple);

            Assert.AreEqual(tuple, result);
        }
예제 #2
0
        /**
         * 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);
            }
        }
예제 #3
0
        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);
        }
예제 #5
0
 private void Write(Tuple tuple)
 {
     TupleSpace.Write(tuple);
     Log("Wrote : " + tuple);
 }
예제 #6
0
 public void Write(Tuple tuple)
 {
     Client1.Write(tuple);
 }