package com.renren.Wario.plugin;

import org.apache.zookeeper.KeeperException;

public class ReadWriteTestPlugin extends IPlugin {

	private String[] numbers;
	private String[] addresses;

	private static String path = "/test";
	private static String INITIAL = "I'm the initial data.";
	private static String UPDATED = "I'm the updated data.";

	@Override
	public void run() {
		String message = "";
		if(!client.isAvailable()) {
			try {
				Thread.sleep(5000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

		if (!client.isAvailable()) {
			message += "Client can not establish connection with " +
						client.getConnectionString() + ". \n";
		} else {
			boolean canBeUsed = true;
			try {
				if (client.testExists(path) == null) {
					client.testCreate(path, INITIAL.getBytes());
				}
				canBeUsed = INITIAL.equals(new String(client.testGetData(path)));
				client.testSetData(path, UPDATED.getBytes());
				canBeUsed = UPDATED.equals(new String(client.testGetData(path)));
				client.testDdelete(path);
			} catch (KeeperException e) {
				canBeUsed = false;
			} catch (InterruptedException e) {
				canBeUsed = false;
			}
			if (!canBeUsed) {
				message += "ZooKeeper " + client.getConnectionString()
						+ " can not be used.";
			}
		}		
		
		if (!"".equals(message)) {
			numbers = args[0].split(",");
			addresses = args[1].split(",");

			for (String address : addresses) {
				mailSender.sendMail(address, message);
			}
			for (String number : numbers) {
				msgSender.sendMessage(number, message);
			}
		}
	}
}

@@ -817,28 +817,21 @@
 %09%09%7D%0A%09%09%09%09
-canBeUsed = 
+if (!
 INITIAL.
@@ -866,33 +866,65 @@
 tGetData(path)))
-;
+) %7B%0A%09%09%09%09%09canBeUsed = false;%0A%09%09%09%09%7D
 %0A%09%09%09%09client.test
@@ -962,28 +962,21 @@
 ));%0A%09%09%09%09
-canBeUsed = 
+if (!
 UPDATED.
@@ -1019,17 +1019,49 @@
 (path)))
-;
+) %7B%0A%09%09%09%09%09canBeUsed = false;%0A%09%09%09%09%7D
 %0A%09%09%09%09cli

Fix bug of ReadWriteTestPlugin