test_class.declarator: proxy
test_class.modifier: private static
test_class.original_string: private static ServiceProxy proxy;
test_class.type: ServiceProxy
test_class.var_name: proxy
test_class.file: bft-smart/src/test/java/bftsmart/tom/ServiceProxyTest.java
test_class.identifier: ServiceProxyTest
test_case.body: @Test
  	public void testReplyReceived() {
  		// Just to setup some variables
  
  		Field response;
  		Field receivedReplies;
  		Field reqId;
  		Field replyQuorum;
  		Field replies;
  		Field requestType;
  
  		try {
  			response = ServiceProxy.class.getDeclaredField("response");
  			response.setAccessible(true);
  			receivedReplies = ServiceProxy.class.getDeclaredField("receivedReplies");
  			receivedReplies.setAccessible(true);
  			reqId = ServiceProxy.class.getDeclaredField("reqId");
  			reqId.setAccessible(true);
  			replyQuorum = ServiceProxy.class.getDeclaredField("replyQuorum");
  			replyQuorum.setAccessible(true);
  			replies = ServiceProxy.class.getDeclaredField("replies");
  			replies.setAccessible(true);
  			requestType = ServiceProxy.class.getDeclaredField("requestType");
  			requestType.setAccessible(true);
  
  			try {
  				// Test if a the method decides correctly when three correct
  				// replies are received in sequence. The request are ordered
  				TOMMessage[] initReplies = new TOMMessage[4];
  				receivedReplies.set(proxy, 0);
  				reqId.setInt(proxy, 1);
  				replyQuorum.setInt(proxy, 3);
  				replies.set(proxy, initReplies);
  				requestType.set(proxy, TOMMessageType.ORDERED_REQUEST);
  				response.set(proxy, null);
  
  				TOMMessage msg = new TOMMessage(0, 1, 1, "response1".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
  				proxy.replyReceived(msg);
  				msg = new TOMMessage(1, 1, 1, "response1".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
  				proxy.replyReceived(msg);
  				msg = new TOMMessage(2, 1, 1, "response1".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
  				proxy.replyReceived(msg);
  				TOMMessage reply = (TOMMessage) response.get(proxy);
  
  				Assert.assertEquals("response1", new String(reply.getContent()));
  
  				// Test if a the method decides correctly when the replies are
  				// correct, correct, wrong and correct, in that order. The requests
  				// are ordered
  				initReplies = new TOMMessage[4];
  				receivedReplies.set(proxy, 0);
  				reqId.setInt(proxy, 1);
  				replyQuorum.setInt(proxy, 3);
  				replies.set(proxy, initReplies);
  				requestType.set(proxy, TOMMessageType.ORDERED_REQUEST);
  				response.set(proxy, null);
  
  				msg = new TOMMessage(0, 1, 1, "response1".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
  				proxy.replyReceived(msg);
  				msg = new TOMMessage(1, 1, 1, "response1".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
  				proxy.replyReceived(msg);
  				msg = new TOMMessage(2, 1, 1, "response2".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
  				proxy.replyReceived(msg);
  				msg = new TOMMessage(3, 1, 1, "response1".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
  				proxy.replyReceived(msg);
  				reply = (TOMMessage) response.get(proxy);
  
  				Assert.assertEquals("response1", new String(reply.getContent()));
  
  				// Negative test, to verify if the method doesn't decide when the values
  				// doesn't match as a reply quorum. The values are 2 response1 and 2 response2
  				initReplies = new TOMMessage[4];
  				receivedReplies.set(proxy, 0);
  				reqId.setInt(proxy, 1);
  				replyQuorum.setInt(proxy, 3);
  				replies.set(proxy, initReplies);
  				requestType.set(proxy, TOMMessageType.ORDERED_REQUEST);
  				response.set(proxy, null);
  
  				msg = new TOMMessage(0, 1, 1, "response1".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
  				proxy.replyReceived(msg);
  				msg = new TOMMessage(1, 1, 1, "response1".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
  				proxy.replyReceived(msg);
  				msg = new TOMMessage(2, 1, 1, "response2".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
  				proxy.replyReceived(msg);
  				msg = new TOMMessage(3, 1, 1, "response2".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
  				proxy.replyReceived(msg);
  				reply = (TOMMessage) response.get(proxy);
  
  				Assert.assertNull(reply);
  				Assert.assertEquals(-1, reqId.get(proxy));
  
  				// Test replyReceived for correct readonly messages
  				initReplies = new TOMMessage[4];
  				receivedReplies.set(proxy, 0);
  				reqId.setInt(proxy, 1);
  				replies.set(proxy, initReplies);
  				requestType.set(proxy, TOMMessageType.UNORDERED_REQUEST);
  				response.set(proxy, null);
  
  				msg = new TOMMessage(0, 1, 1, "response1".getBytes(), 0, TOMMessageType.UNORDERED_REQUEST);
  				proxy.replyReceived(msg);
  				msg = new TOMMessage(1, 1, 1, "response1".getBytes(), 0, TOMMessageType.UNORDERED_REQUEST);
  				proxy.replyReceived(msg);
  				msg = new TOMMessage(2, 1, 1, "response1".getBytes(), 0, TOMMessageType.UNORDERED_REQUEST);
  				proxy.replyReceived(msg);
  
  				reply = (TOMMessage) response.get(proxy);
  				Assert.assertEquals("response1", new String(reply.getContent()));
  
  				// Test if the method fails for the first diverging readonly reply
  				receivedReplies.set(proxy, 0);
  				reqId.setInt(proxy, 1);
  				replies.set(proxy, initReplies);
  				requestType.set(proxy, TOMMessageType.UNORDERED_REQUEST);
  				response.set(proxy, null);
  
  				msg = new TOMMessage(0, 1, 1, "response1".getBytes(), 0, TOMMessageType.UNORDERED_REQUEST);
  				proxy.replyReceived(msg);
  				msg = new TOMMessage(1, 1, 1, "response2".getBytes(), 0, TOMMessageType.UNORDERED_REQUEST);
  				proxy.replyReceived(msg);
  
  				reply = (TOMMessage) response.get(proxy);
  				Assert.assertEquals(-1, reqId.get(proxy));
  
  			} catch (IllegalArgumentException | IllegalAccessException e) {
  
  				e.printStackTrace();
  			}
  		} catch (NoSuchFieldException e) {
  			e.printStackTrace();
  		} catch (SecurityException e) {
  			// TODO Auto-generated catch block
  			e.printStackTrace();
  		}
  	}
test_case.class_method_signature: ServiceProxyTest.testReplyReceived()
test_case.full_signature: @Test public void testReplyReceived()
test_case.identifier: testReplyReceived
test_case.invocations: getDeclaredField setAccessible getDeclaredField setAccessible getDeclaredField setAccessible getDeclaredField setAccessible getDeclaredField setAccessible getDeclaredField setAccessible set setInt setInt set set set getBytes replyReceived getBytes replyReceived getBytes replyReceived get assertEquals getContent set setInt setInt set set set getBytes replyReceived getBytes replyReceived getBytes replyReceived getBytes replyReceived get assertEquals getContent set setInt setInt set set set getBytes replyReceived getBytes replyReceived getBytes replyReceived getBytes replyReceived get assertNull assertEquals get set setInt set set set getBytes replyReceived getBytes replyReceived getBytes replyReceived get assertEquals getContent set setInt set set set getBytes replyReceived getBytes replyReceived get assertEquals get printStackTrace printStackTrace printStackTrace
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testReplyReceived()
focal_class.declarator: canReceiveLock = new ReentrantLock()
focal_class.modifier: protected
focal_class.original_string: protected ReentrantLock canReceiveLock = new ReentrantLock();
focal_class.type: ReentrantLock
focal_class.var_name: canReceiveLock
focal_class.declarator: canSendLock = new ReentrantLock()
focal_class.modifier: protected
focal_class.original_string: protected ReentrantLock canSendLock = new ReentrantLock();
focal_class.type: ReentrantLock
focal_class.var_name: canSendLock
focal_class.declarator: sm = new Semaphore(0)
focal_class.modifier: private
focal_class.original_string: private Semaphore sm = new Semaphore(0);
focal_class.type: Semaphore
focal_class.var_name: sm
focal_class.declarator: reqId = -1
focal_class.modifier: private
focal_class.original_string: private int reqId = -1;
focal_class.type: int
focal_class.var_name: reqId
focal_class.declarator: operationId = -1
focal_class.modifier: private
focal_class.original_string: private int operationId = -1;
focal_class.type: int
focal_class.var_name: operationId
focal_class.declarator: requestType
focal_class.modifier: private
focal_class.original_string: private TOMMessageType requestType;
focal_class.type: TOMMessageType
focal_class.var_name: requestType
focal_class.declarator: replyQuorum = 0
focal_class.modifier: private
focal_class.original_string: private int replyQuorum = 0;
focal_class.type: int
focal_class.var_name: replyQuorum
focal_class.declarator: replies[] = null
focal_class.modifier: private
focal_class.original_string: private TOMMessage replies[] = null;
focal_class.type: TOMMessage
focal_class.var_name: replies
focal_class.declarator: receivedReplies = 0
focal_class.modifier: private
focal_class.original_string: private int receivedReplies = 0;
focal_class.type: int
focal_class.var_name: receivedReplies
focal_class.declarator: response = null
focal_class.modifier: private
focal_class.original_string: private TOMMessage response = null;
focal_class.type: TOMMessage
focal_class.var_name: response
focal_class.declarator: invokeTimeout = 40
focal_class.modifier: private
focal_class.original_string: private int invokeTimeout = 40;
focal_class.type: int
focal_class.var_name: invokeTimeout
focal_class.declarator: comparator
focal_class.modifier: private
focal_class.original_string: private Comparator<byte[]> comparator;
focal_class.type: Comparator<byte[]>
focal_class.var_name: comparator
focal_class.declarator: extractor
focal_class.modifier: private
focal_class.original_string: private Extractor extractor;
focal_class.type: Extractor
focal_class.var_name: extractor
focal_class.declarator: rand = new Random(System.currentTimeMillis())
focal_class.modifier: private
focal_class.original_string: private Random rand = new Random(System.currentTimeMillis());
focal_class.type: Random
focal_class.var_name: rand
focal_class.declarator: replyServer
focal_class.modifier: private
focal_class.original_string: private int replyServer;
focal_class.type: int
focal_class.var_name: replyServer
focal_class.declarator: hashResponseController
focal_class.modifier: private
focal_class.original_string: private HashResponseController hashResponseController;
focal_class.type: HashResponseController
focal_class.var_name: hashResponseController
focal_class.declarator: invokeUnorderedHashedTimeout = 10
focal_class.modifier: private
focal_class.original_string: private int invokeUnorderedHashedTimeout = 10;
focal_class.type: int
focal_class.var_name: invokeUnorderedHashedTimeout
focal_class.file: bft-smart/src/main/java/bftsmart/tom/ServiceProxy.java
focal_class.identifier: ServiceProxy
focal_class.class_method_signature: ServiceProxy.ServiceProxy(int processId)
focal_class.full_signature: public  ServiceProxy(int processId)
focal_class.identifier: ServiceProxy
focal_class.modifiers: public
focal_class.parameters: (int processId)
focal_class.signature:  ServiceProxy(int processId)
focal_class.class_method_signature: ServiceProxy.ServiceProxy(int processId, String configHome)
focal_class.full_signature: public  ServiceProxy(int processId, String configHome)
focal_class.identifier: ServiceProxy
focal_class.modifiers: public
focal_class.parameters: (int processId, String configHome)
focal_class.signature:  ServiceProxy(int processId, String configHome)
focal_class.class_method_signature: ServiceProxy.ServiceProxy(int processId, String configHome, Comparator<byte[]> replyComparator,
  			Extractor replyExtractor)
focal_class.full_signature: public  ServiceProxy(int processId, String configHome, Comparator<byte[]> replyComparator,
  			Extractor replyExtractor)
focal_class.identifier: ServiceProxy
focal_class.modifiers: public
focal_class.parameters: (int processId, String configHome, Comparator<byte[]> replyComparator,
  			Extractor replyExtractor)
focal_class.signature:  ServiceProxy(int processId, String configHome, Comparator<byte[]> replyComparator,
  			Extractor replyExtractor)
focal_class.class_method_signature: ServiceProxy.getInvokeTimeout()
focal_class.full_signature: public int getInvokeTimeout()
focal_class.identifier: getInvokeTimeout
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int getInvokeTimeout()
focal_class.class_method_signature: ServiceProxy.getInvokeUnorderedHashedTimeout()
focal_class.full_signature: public int getInvokeUnorderedHashedTimeout()
focal_class.identifier: getInvokeUnorderedHashedTimeout
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int getInvokeUnorderedHashedTimeout()
focal_class.class_method_signature: ServiceProxy.setInvokeTimeout(int invokeTimeout)
focal_class.full_signature: public void setInvokeTimeout(int invokeTimeout)
focal_class.identifier: setInvokeTimeout
focal_class.modifiers: public
focal_class.parameters: (int invokeTimeout)
focal_class.return: void
focal_class.signature: void setInvokeTimeout(int invokeTimeout)
focal_class.class_method_signature: ServiceProxy.setInvokeUnorderedHashedTimeout(int timeout)
focal_class.full_signature: public void setInvokeUnorderedHashedTimeout(int timeout)
focal_class.identifier: setInvokeUnorderedHashedTimeout
focal_class.modifiers: public
focal_class.parameters: (int timeout)
focal_class.return: void
focal_class.signature: void setInvokeUnorderedHashedTimeout(int timeout)
focal_class.class_method_signature: ServiceProxy.invokeOrdered(byte[] request)
focal_class.full_signature: public byte[] invokeOrdered(byte[] request)
focal_class.identifier: invokeOrdered
focal_class.modifiers: public
focal_class.parameters: (byte[] request)
focal_class.return: byte[]
focal_class.signature: byte[] invokeOrdered(byte[] request)
focal_class.class_method_signature: ServiceProxy.invokeUnordered(byte[] request)
focal_class.full_signature: public byte[] invokeUnordered(byte[] request)
focal_class.identifier: invokeUnordered
focal_class.modifiers: public
focal_class.parameters: (byte[] request)
focal_class.return: byte[]
focal_class.signature: byte[] invokeUnordered(byte[] request)
focal_class.class_method_signature: ServiceProxy.invokeUnorderedHashed(byte[] request)
focal_class.full_signature: public byte[] invokeUnorderedHashed(byte[] request)
focal_class.identifier: invokeUnorderedHashed
focal_class.modifiers: public
focal_class.parameters: (byte[] request)
focal_class.return: byte[]
focal_class.signature: byte[] invokeUnorderedHashed(byte[] request)
focal_class.class_method_signature: ServiceProxy.invoke(byte[] request, TOMMessageType reqType)
focal_class.full_signature: public byte[] invoke(byte[] request, TOMMessageType reqType)
focal_class.identifier: invoke
focal_class.modifiers: public
focal_class.parameters: (byte[] request, TOMMessageType reqType)
focal_class.return: byte[]
focal_class.signature: byte[] invoke(byte[] request, TOMMessageType reqType)
focal_class.class_method_signature: ServiceProxy.reconfigureTo(View v)
focal_class.full_signature: protected void reconfigureTo(View v)
focal_class.identifier: reconfigureTo
focal_class.modifiers: protected
focal_class.parameters: (View v)
focal_class.return: void
focal_class.signature: void reconfigureTo(View v)
focal_class.class_method_signature: ServiceProxy.replyReceived(TOMMessage reply)
focal_class.full_signature: @Override public void replyReceived(TOMMessage reply)
focal_class.identifier: replyReceived
focal_class.modifiers: @Override public
focal_class.parameters: (TOMMessage reply)
focal_class.return: void
focal_class.signature: void replyReceived(TOMMessage reply)
focal_class.class_method_signature: ServiceProxy.getReplyQuorum()
focal_class.full_signature: protected int getReplyQuorum()
focal_class.identifier: getReplyQuorum
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int getReplyQuorum()
focal_class.class_method_signature: ServiceProxy.getRandomlyServerId()
focal_class.full_signature: private int getRandomlyServerId()
focal_class.identifier: getRandomlyServerId
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int getRandomlyServerId()
focal_class.superclass: extends TOMSender
focal_method.body: @Override
  	public void replyReceived(TOMMessage reply) {
  		Logger.println("Synchronously received reply from " + reply.getSender() + " with sequence number "
  				+ reply.getSequence());
  
  		try {
  			canReceiveLock.lock();
  			if (reqId == -1) {// no message being expected
  				Logger.println("throwing out request: sender=" + reply.getSender() + " reqId=" + reply.getSequence());
  				canReceiveLock.unlock();
  				return;
  			}
  
  			int pos = getViewManager().getCurrentViewPos(reply.getSender());
  
  			if (pos < 0) { // ignore messages that don't come from replicas
  				canReceiveLock.unlock();
  				return;
  			}
  
  			int sameContent = 1;
  			if (reply.getSequence() == reqId && reply.getReqType() == requestType) {
  
  				Logger.println("Receiving reply from " + reply.getSender() + " with reqId:" + reply.getSequence()
  						+ ". Putting on pos=" + pos);
  
  				if (requestType == TOMMessageType.UNORDERED_HASHED_REQUEST) {
  					response = hashResponseController.getResponse(pos, reply);
  					if (response != null) {
  						reqId = -1;
  						this.sm.release(); // resumes the thread that is executing the "invoke" method
  						canReceiveLock.unlock();
  						return;
  					}
  
  				} else {
  					if (replies[pos] == null) {
  						receivedReplies++;
  					}
  					replies[pos] = reply;
  
  					// Compare the reply just received, to the others
  
  					for (int i = 0; i < replies.length; i++) {
  
  						if ((i != pos || getViewManager().getCurrentViewN() == 1) && replies[i] != null
  								&& (comparator.compare(replies[i].getContent(), reply.getContent()) == 0)) {
  							sameContent++;
  							if (sameContent >= replyQuorum) {
  								response = extractor.extractResponse(replies, sameContent, pos);
  								reqId = -1;
  								this.sm.release(); // resumes the thread that is executing the "invoke" method
  								canReceiveLock.unlock();
  								return;
  							}
  						}
  					}
  				}
  
  				if (response == null) {
  					if (requestType.equals(TOMMessageType.ORDERED_REQUEST)) {
  						if (receivedReplies == getViewManager().getCurrentViewN()) {
  							reqId = -1;
  							this.sm.release(); // resumes the thread that is executing the "invoke" method
  						}
  					} else if (requestType.equals(TOMMessageType.UNORDERED_HASHED_REQUEST)) {
  						if (hashResponseController.getNumberReplies() == getViewManager().getCurrentViewN()) {
  							reqId = -1;
  							this.sm.release(); // resumes the thread that is executing the "invoke" method
  						}
  					} else { // UNORDERED
  						if (receivedReplies != sameContent) {
  							reqId = -1;
  							this.sm.release(); // resumes the thread that is executing the "invoke" method
  						}
  					}
  				}
  			} else {
  				Logger.println("Ignoring reply from " + reply.getSender() + " with reqId:" + reply.getSequence()
  						+ ". Currently wait reqId= " + reqId);
  
  			}
  
  			// Critical section ends here. The semaphore can be released
  			canReceiveLock.unlock();
  		} catch (Exception ex) {
  			System.out.println("Problem at ServiceProxy.ReplyReceived()");
  			ex.printStackTrace();
  			canReceiveLock.unlock();
  		}
  	}
focal_method.class_method_signature: ServiceProxy.replyReceived(TOMMessage reply)
focal_method.full_signature: @Override public void replyReceived(TOMMessage reply)
focal_method.identifier: replyReceived
focal_method.invocations: println getSender getSequence lock println getSender getSequence unlock getCurrentViewPos getViewManager getSender unlock getSequence getReqType println getSender getSequence getResponse release unlock getCurrentViewN getViewManager compare getContent getContent extractResponse release unlock equals getCurrentViewN getViewManager release equals getNumberReplies getCurrentViewN getViewManager release release println getSender getSequence unlock println printStackTrace unlock
focal_method.modifiers: @Override public
focal_method.parameters: (TOMMessage reply)
focal_method.return: void
focal_method.signature: void replyReceived(TOMMessage reply)