public void createNremoveMtest(String dir, int n, int m) { String testString = "Hello World"; int num_clients = 2; clients = new ZooKeeper[num_clients]; var queueHandles = new DistributedQueue[num_clients]; for (int i = 0; i < clients.Length; i++) { clients[i] = CreateClient(); queueHandles[i] = new DistributedQueue(clients[i], dir, null); } for (int i = 0; i < n; i++) { var offerString = testString + i; queueHandles[0].Enqueue(offerString.GetBytes()); } byte[] data = null; for (int i = 0; i < m; i++) { data = queueHandles[1].Dequeue(); } Assert.AreEqual(testString + (m - 1), Encoding.UTF8.GetString(data)); }
public void testOffer1() { String dir = "/testOffer1" + Guid.NewGuid(); String testString = "Hello World"; int num_clients = 1; clients = new ZooKeeper[num_clients]; DistributedQueue[] queueHandles = new DistributedQueue[num_clients]; for (int i = 0; i < clients.Length; i++) { clients[i] = CreateClient(); queueHandles[i] = new DistributedQueue(clients[i], dir, null); } queueHandles[0].Enqueue(Encoding.UTF8.GetBytes(testString)); byte[] dequeuedBytes = queueHandles[0].Dequeue(); Assert.AreEqual(Encoding.UTF8.GetString(dequeuedBytes), testString); }
public void testTakeWait2() { String dir = "/testTakeWait2" + Guid.NewGuid(); string testString = "Hello World"; int num_clients = 1; clients = new ZooKeeper[num_clients]; DistributedQueue[] queueHandles = new DistributedQueue[num_clients]; for (int i = 0; i < clients.Length; i++) { clients[i] = CreateClient(); queueHandles[i] = new DistributedQueue(clients[i], dir, null); } int num_attempts = 2; for (int i = 0; i < num_attempts; i++) { byte[][] takeResult = new byte[1][]; string threadTestString = testString + i; var wait = new ManualResetEvent(false); int maxRetry = 10; ThreadPool.QueueUserWorkItem(st => { try { takeResult[0] = queueHandles[0].Take(); wait.Set(); } catch (KeeperException e) { } catch (ThreadInterruptedException e) { } }); Thread.Sleep(1000); ThreadPool.QueueUserWorkItem(st => { try { while (!wait.WaitOne(1000) && maxRetry-- > 0) queueHandles[0].Enqueue(threadTestString.GetBytes()); } catch (KeeperException e) { } catch (ThreadInterruptedException e) { } }); Assert.True(wait.WaitOne(3000), "Failed to take"); Assert.True(takeResult[0] != null); Assert.AreEqual(threadTestString, Encoding.UTF8.GetString(takeResult[0])); } }
public void testRemove1() { String dir = "/testRemove1" + Guid.NewGuid(); String testString = "Hello World"; int num_clients = 1; clients = new ZooKeeper[num_clients]; DistributedQueue[] queueHandles = new DistributedQueue[num_clients]; for (int i = 0; i < clients.Length; i++) { clients[i] = CreateClient(); queueHandles[i] = new DistributedQueue(clients[i], dir, null); } try { queueHandles[0].Dequeue(); } catch (NoSuchElementException e) { return; } Assert.Fail(); }