Added logging to Voter-Registry
parent
47f68acae4
commit
7fc0af2b1f
|
@ -24,7 +24,7 @@ import java.util.List;
|
|||
import static meerkat.util.BulletinBoardUtils.signBulletinBoardMessage;
|
||||
|
||||
|
||||
// TODO : add ability to use DB of certificates and add logging
|
||||
// TODO : add ability to use DB of certificates
|
||||
|
||||
/**
|
||||
* Created by Vladimir Eliezer Tokarev on 1/8/2016.
|
||||
|
@ -39,14 +39,13 @@ public class AsyncRegistry implements VoterRegistry{
|
|||
|
||||
@Override
|
||||
public void init(DigitalSignature signer, SubscriptionAsyncBulletinBoardClient communicator) {
|
||||
logger.debug("Initialized the AsyncRegistry");
|
||||
logger.debug("Initialized AsyncRegistry: ", new java.util.Date().getTime());
|
||||
this.signer = signer;
|
||||
this.cachedBulletinBoardClient = communicator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addVoter(VoterInfo voterInfo, FutureCallback<Boolean> callback) throws SignatureException {
|
||||
logger.info("Adding voter : {0}", RegistryTags.ID_TAG);
|
||||
UnsignedBulletinBoardMessage basicMessage =
|
||||
UnsignedBulletinBoardMessage.newBuilder()
|
||||
.addTag(RegistryTags.ID_TAG + voterInfo.getId().getId())
|
||||
|
@ -55,8 +54,8 @@ public class AsyncRegistry implements VoterRegistry{
|
|||
.setTimestamp(BulletinBoardUtils.getCurrentTimestampProto())
|
||||
.build();
|
||||
|
||||
|
||||
cachedBulletinBoardClient.postMessage(signBulletinBoardMessage(basicMessage, signer), callback);
|
||||
logger.debug("Added voter : ", RegistryTags.ID_TAG, new java.util.Date().getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,6 +68,8 @@ public class AsyncRegistry implements VoterRegistry{
|
|||
.setTimestamp(BulletinBoardUtils.getCurrentTimestampProto());
|
||||
|
||||
cachedBulletinBoardClient.postMessage(signBulletinBoardMessage(basicMessage.build(), signer), callback);
|
||||
|
||||
logger.debug("Set voter groups to be : ", new java.util.Date().getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,6 +82,8 @@ public class AsyncRegistry implements VoterRegistry{
|
|||
.build();
|
||||
|
||||
cachedBulletinBoardClient.postMessage(signBulletinBoardMessage(basicMessage, signer), callback);
|
||||
|
||||
logger.debug("Next voter has voted : ", voterId.getId(), new java.util.Date().getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -90,8 +93,12 @@ public class AsyncRegistry implements VoterRegistry{
|
|||
add(RegistryTags.ID_TAG + voterID.getId());
|
||||
}};
|
||||
|
||||
cachedBulletinBoardClient.readMessages(MessageCollectionUtils.generateFiltersFromTags(GroupsActionsTags),
|
||||
cachedBulletinBoardClient.readMessages(MessageCollectionUtils.generateFiltersFromTags(GroupsActionsTags, logger),
|
||||
new GetGroupsCallback(callback));
|
||||
|
||||
logger.debug("Trying to retrieve next user groups : ",
|
||||
voterID.getId(),
|
||||
new java.util.Date().getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -101,8 +108,10 @@ public class AsyncRegistry implements VoterRegistry{
|
|||
add(RegistryTags.VOTER_ENTRY_TAG);
|
||||
}};
|
||||
|
||||
cachedBulletinBoardClient.readMessages(MessageCollectionUtils.generateFiltersFromTags(addVoterTags),
|
||||
cachedBulletinBoardClient.readMessages(MessageCollectionUtils.generateFiltersFromTags(addVoterTags, logger),
|
||||
new GetVoterCallback(callback));
|
||||
|
||||
logger.debug("Trying to retrieve next user information : ", voterID.getId(), new java.util.Date().getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -112,7 +121,9 @@ public class AsyncRegistry implements VoterRegistry{
|
|||
add(RegistryTags.VOTE_ACTION_TAG);
|
||||
}};
|
||||
|
||||
cachedBulletinBoardClient.readMessages(MessageCollectionUtils.generateFiltersFromTags(setVotedTags),
|
||||
cachedBulletinBoardClient.readMessages(MessageCollectionUtils.generateFiltersFromTags(setVotedTags, logger),
|
||||
new HasVotedCallback(callBack));
|
||||
|
||||
logger.debug("Trying to check if next has voted : ", voterId.getId(), new java.util.Date().getTime());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,16 @@ import com.google.common.util.concurrent.FutureCallback;
|
|||
import javassist.NotFoundException;
|
||||
import meerkat.protobuf.BulletinBoardAPI.BulletinBoardMessage;
|
||||
import meerkat.protobuf.VoterRegistry;
|
||||
import meerkat.registry.RegistryTags;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static meerkat.util.BulletinBoardUtils.findTagWithPrefix;
|
||||
import static meerkat.util.BulletinBoardUtils.getLatestMessage;
|
||||
|
||||
// TODO : add logging
|
||||
|
||||
/**
|
||||
* Created by Vladimir Eliezer on 3/12/2016.
|
||||
|
@ -18,6 +21,7 @@ import static meerkat.util.BulletinBoardUtils.getLatestMessage;
|
|||
*/
|
||||
public class GetGroupsCallback implements FutureCallback<List<BulletinBoardMessage>> {
|
||||
protected FutureCallback<List<VoterRegistry.GroupID>> callback;
|
||||
final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
public GetGroupsCallback(FutureCallback<List<VoterRegistry.GroupID>> callback){
|
||||
this.callback = callback;
|
||||
|
@ -31,6 +35,7 @@ public class GetGroupsCallback implements FutureCallback<List<BulletinBoardMessa
|
|||
* @throws ClassNotFoundException
|
||||
*/
|
||||
private List<VoterRegistry.GroupID> getVoterGroups(BulletinBoardMessage message) throws IOException, ClassNotFoundException {
|
||||
logger.debug("Initialized GetGroupsCallback : ", new java.util.Date().getTime());
|
||||
VoterRegistry.VoterRegistryMessage voterRegistryMessage =
|
||||
VoterRegistry.VoterRegistryMessage.parseFrom(message.getMsg().getData());
|
||||
|
||||
|
@ -47,14 +52,25 @@ public class GetGroupsCallback implements FutureCallback<List<BulletinBoardMessa
|
|||
|
||||
BulletinBoardMessage message = getLatestMessage(messages);
|
||||
try {
|
||||
|
||||
logger.debug("Wanted voter groups been retrieved: ",
|
||||
findTagWithPrefix(message, RegistryTags.ID_TAG),
|
||||
new java.util.Date().getTime());
|
||||
|
||||
callback.onSuccess(getVoterGroups(message));
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
logger.error("Error occurred while trying to get voter groups ",
|
||||
new java.util.Date().getTime(),
|
||||
e);
|
||||
callback.onFailure(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
logger.error("Error occurred while trying to get voter groups ",
|
||||
new java.util.Date().getTime(),
|
||||
t);
|
||||
this.callback.onFailure(t);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,14 @@ package meerkat.registry.AsyncRegistryCallbacks;
|
|||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import meerkat.protobuf.BulletinBoardAPI.BulletinBoardMessage;
|
||||
import meerkat.registry.RegistryTags;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// TODO : add logging
|
||||
import static meerkat.util.BulletinBoardUtils.findTagWithPrefix;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Vladimir Eliezer Tokarev on 3/12/2016.
|
||||
|
@ -13,8 +17,10 @@ import java.util.List;
|
|||
*/
|
||||
public class HasVotedCallback implements FutureCallback<List<BulletinBoardMessage>>{
|
||||
protected FutureCallback<Boolean> callback;
|
||||
final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
public HasVotedCallback(FutureCallback<Boolean> callback){
|
||||
logger.debug("Initialized HasVotedCallback : ", new java.util.Date().getTime());
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
|
@ -24,11 +30,18 @@ public class HasVotedCallback implements FutureCallback<List<BulletinBoardMessag
|
|||
callback.onSuccess(false);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug("The next voter has voted: ",
|
||||
findTagWithPrefix(messages.get(0), RegistryTags.ID_TAG),
|
||||
new java.util.Date().getTime());
|
||||
callback.onSuccess(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
logger.error("Error occurred while trying to check if voter has voted: ",
|
||||
new java.util.Date().getTime(),
|
||||
t);
|
||||
this.callback.onFailure(t);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,13 @@ import com.google.protobuf.InvalidProtocolBufferException;
|
|||
import javassist.NotFoundException;
|
||||
import meerkat.protobuf.BulletinBoardAPI.BulletinBoardMessage;
|
||||
import meerkat.protobuf.VoterRegistry;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static meerkat.util.BulletinBoardUtils.getLatestMessage;
|
||||
|
||||
// TODO : add logging
|
||||
|
||||
/**
|
||||
* Created by Vladimir Eliezer on 3/12/2016.
|
||||
|
@ -18,8 +19,10 @@ import static meerkat.util.BulletinBoardUtils.getLatestMessage;
|
|||
*/
|
||||
public class GetVoterCallback implements FutureCallback<List<BulletinBoardMessage>> {
|
||||
protected FutureCallback<VoterRegistry.VoterInfo> callback;
|
||||
final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
public GetVoterCallback(FutureCallback<VoterRegistry.VoterInfo> callback){
|
||||
logger.debug("Initialized GetVoterCallback : ", new java.util.Date().getTime());
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
|
@ -34,14 +37,24 @@ public class GetVoterCallback implements FutureCallback<List<BulletinBoardMessag
|
|||
try {
|
||||
VoterRegistry.VoterInfo info = VoterRegistry.VoterInfo.newBuilder()
|
||||
.mergeFrom(latestMessage.getMsg().getData()).build();
|
||||
callback.onSuccess(info);
|
||||
|
||||
logger.debug("Wanted voter information: ", info.getId().getId(), info.getInfo(),
|
||||
new java.util.Date().getTime());
|
||||
|
||||
callback.onSuccess(info);
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
logger.error("Error occurred while trying to get voter information: ",
|
||||
new java.util.Date().getTime(),
|
||||
e);
|
||||
callback.onFailure(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
logger.error("Error occurred while trying to get voter information:",
|
||||
new java.util.Date().getTime(),
|
||||
t);
|
||||
callback.onFailure(t);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package meerkat.registry;
|
||||
|
||||
import com.sun.deploy.util.StringUtils;
|
||||
import meerkat.protobuf.BulletinBoardAPI.FilterType;
|
||||
import meerkat.protobuf.BulletinBoardAPI.MessageFilter;
|
||||
import meerkat.protobuf.BulletinBoardAPI.MessageFilterList;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
// TODO: add logging
|
||||
|
||||
|
||||
/**
|
||||
* Created by Vladimir Eliezer Tokarev on 1/15/2016.
|
||||
* adds extra functionality to Messages collections
|
||||
|
@ -18,10 +17,11 @@ public abstract class MessageCollectionUtils {
|
|||
/**
|
||||
* Creates list of filters based on given list of strings (that are tags)
|
||||
*
|
||||
* @param logger logger object with debug method
|
||||
* @param tags the tags based on which the messages will be filtered
|
||||
* @return MessageFilterList.
|
||||
*/
|
||||
public static MessageFilterList generateFiltersFromTags(List<String> tags) {
|
||||
public static MessageFilterList generateFiltersFromTags(List<String> tags, Logger logger) {
|
||||
if (tags == null){
|
||||
return MessageFilterList.getDefaultInstance();
|
||||
}
|
||||
|
@ -32,6 +32,9 @@ public abstract class MessageCollectionUtils {
|
|||
MessageFilter filter = MessageFilter.newBuilder().setTag(tag).setType(FilterType.TAG).build();
|
||||
filters.addFilter(filter);
|
||||
}
|
||||
|
||||
logger.debug("Converted next strings to filters", StringUtils.join(tags, " "));
|
||||
|
||||
return filters.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ import com.google.common.util.concurrent.FutureCallback;
|
|||
import meerkat.AsyncRegistry;
|
||||
import meerkat.bulletinboard.BulletinBoardServer;
|
||||
import meerkat.bulletinboard.LocalBulletinBoardClient;
|
||||
import meerkat.bulletinboard.sqlserver.*;
|
||||
|
||||
import meerkat.bulletinboard.sqlserver.BulletinBoardSQLServer;
|
||||
import meerkat.bulletinboard.sqlserver.H2QueryProvider;
|
||||
import meerkat.comm.CommunicationException;
|
||||
import meerkat.crypto.DigitalSignature;
|
||||
import meerkat.crypto.concrete.ECDSASignature;
|
||||
|
@ -17,6 +17,8 @@ import meerkat.registry.MessageCollectionUtils;
|
|||
import meerkat.registry.RegistryTags;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -28,13 +30,13 @@ import java.sql.Connection;
|
|||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static meerkat.util.BulletinBoardUtils.findTagWithPrefix;
|
||||
import static meerkat.util.BulletinBoardUtils.getLatestMessage;
|
||||
import static meerkat.util.BulletinBoardUtils.*;
|
||||
|
||||
/**
|
||||
* TODO: add logs prints for the tests to be clear what they are
|
||||
|
@ -49,7 +51,7 @@ import static meerkat.util.BulletinBoardUtils.getLatestMessage;
|
|||
public class SimpleRegistryTest {
|
||||
|
||||
private DigitalSignature signer;
|
||||
private LocalBulletinBoardClient cachedBulletinBoardClient;
|
||||
private LocalBulletinBoardClient localBulletinBoardClient;
|
||||
private SecureRandom random = new SecureRandom();
|
||||
Semaphore jobSemaphore;
|
||||
|
||||
|
@ -59,6 +61,7 @@ public class SimpleRegistryTest {
|
|||
private static final String DB_NAME = "TestDB";
|
||||
private static final int SUBSCRIPTION_DELAY = 3000;
|
||||
private static final int THREAD_NUM = 3;
|
||||
final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
class DummyRegistryCallBackHandler<T> implements FutureCallback<T>{
|
||||
public int counter;
|
||||
|
@ -119,6 +122,8 @@ public class SimpleRegistryTest {
|
|||
BulletinBoardServer server = new BulletinBoardSQLServer(queryProvider);
|
||||
server.init(DB_NAME);
|
||||
|
||||
logger.debug("Created new LocalBulletinBoardClient: {}", new Date());
|
||||
|
||||
return new LocalBulletinBoardClient(server, THREAD_NUM, SUBSCRIPTION_DELAY);
|
||||
}
|
||||
|
||||
|
@ -130,7 +135,7 @@ public class SimpleRegistryTest {
|
|||
* @throws SQLException
|
||||
*/
|
||||
private void CommunicatorSetup() throws InstantiationException, IllegalAccessException, CommunicationException, SQLException {
|
||||
cachedBulletinBoardClient = CreateLocalBulletinBoardClient();
|
||||
localBulletinBoardClient = CreateLocalBulletinBoardClient();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -148,6 +153,7 @@ public class SimpleRegistryTest {
|
|||
|
||||
keyStream.close();
|
||||
this.signer = signer;
|
||||
logger.info("Have set new signer: {}", new Date());
|
||||
}
|
||||
catch (Exception e){
|
||||
assert false : "The signers creation failed ";
|
||||
|
@ -166,12 +172,14 @@ public class SimpleRegistryTest {
|
|||
SetSigner();
|
||||
CommunicatorSetup();
|
||||
jobSemaphore = new Semaphore(0);
|
||||
logger.info("Ended the setup preparations: {}", new Date());
|
||||
}
|
||||
|
||||
private AsyncRegistry GetRegistry()
|
||||
{
|
||||
AsyncRegistry registry = new AsyncRegistry();
|
||||
registry.init(signer, cachedBulletinBoardClient);
|
||||
registry.init(signer, localBulletinBoardClient);
|
||||
logger.info("Created new AsyncRegistry: {}", new Date());
|
||||
return registry;
|
||||
}
|
||||
|
||||
|
@ -190,7 +198,9 @@ public class SimpleRegistryTest {
|
|||
@Test
|
||||
public void simpleRegistryCreation() {
|
||||
try {
|
||||
logger.info("Testing registry creation: {}", new Date());
|
||||
GetRegistry();
|
||||
logger.info("Registry creation succeed: {} \n\n", new Date());
|
||||
} catch (Exception e) {
|
||||
assert false : "While creating the registry exception have been thrown " + e;
|
||||
}
|
||||
|
@ -220,11 +230,15 @@ public class SimpleRegistryTest {
|
|||
counter++;
|
||||
}
|
||||
}
|
||||
logger.info("Counted {} messages with all wanted tags from {} given messages: {}",
|
||||
counter,
|
||||
messages.size(),
|
||||
new Date());
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads messages from cachedBulletinBoardClient by given tags and return the callback handler
|
||||
* Reads messages from localBulletinBoardClient by given tags and return the callback handler
|
||||
* object
|
||||
*
|
||||
* @param tags list of strings that represents tags
|
||||
|
@ -232,9 +246,9 @@ public class SimpleRegistryTest {
|
|||
*/
|
||||
private DummyBulletinBoardCallBackHandler readMessagesByTags(List<String> tags)
|
||||
{
|
||||
MessageFilterList filters = MessageCollectionUtils.generateFiltersFromTags(tags);
|
||||
MessageFilterList filters = MessageCollectionUtils.generateFiltersFromTags(tags, logger);
|
||||
DummyBulletinBoardCallBackHandler bulletinHandler = new DummyBulletinBoardCallBackHandler();
|
||||
cachedBulletinBoardClient.readMessages(filters, bulletinHandler);
|
||||
localBulletinBoardClient.readMessages(filters, bulletinHandler);
|
||||
return bulletinHandler;
|
||||
}
|
||||
|
||||
|
@ -243,6 +257,8 @@ public class SimpleRegistryTest {
|
|||
*/
|
||||
@Test
|
||||
public void testAddVoter() throws InterruptedException, SignatureException {
|
||||
logger.info("Testing registry adding voter functionality: {}", new Date());
|
||||
|
||||
DummyRegistryCallBackHandler<Boolean> handler = new DummyRegistryCallBackHandler<>();
|
||||
|
||||
String id = generateString();
|
||||
|
@ -251,6 +267,9 @@ public class SimpleRegistryTest {
|
|||
|
||||
AsyncRegistry registry = GetRegistry();
|
||||
registry.addVoter(voterInfo, handler);
|
||||
logger.info("Tried to add next voter to registry: id: {} {}",
|
||||
voterInfo.getId().getId(),
|
||||
new Date());
|
||||
|
||||
jobSemaphore.acquire();
|
||||
assertEquals(1, handler.counter );
|
||||
|
@ -258,13 +277,19 @@ public class SimpleRegistryTest {
|
|||
List<String> tags = new ArrayList<String>(){{ add(RegistryTags.VOTER_ENTRY_TAG);}};
|
||||
DummyBulletinBoardCallBackHandler bulletinHandler = readMessagesByTags(tags);
|
||||
|
||||
|
||||
jobSemaphore.acquire();
|
||||
logger.info("Got add voter messages that have been added lately to the server: {} {}",
|
||||
GetListOfTags(bulletinHandler.messages, RegistryTags.ID_TAG),
|
||||
new Date());
|
||||
|
||||
tags.clear();
|
||||
tags.add(RegistryTags.ID_TAG + id);
|
||||
|
||||
int counter = countMessagesWithTags(bulletinHandler.messages, tags);
|
||||
assert counter == 1 : "The server don't have the new user data.";
|
||||
logger.info("The server had a message with voter data: id: {} data: {} {}", id, data, new Date());
|
||||
logger.info("Ended testing registry adding voter functionality: {}\n\n", new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -272,6 +297,7 @@ public class SimpleRegistryTest {
|
|||
*/
|
||||
@Test
|
||||
public void testSetVoted() throws InterruptedException, SignatureException {
|
||||
logger.info("Testing registry set voted functionality: {}", new Date());
|
||||
DummyRegistryCallBackHandler<Boolean> handler = new DummyRegistryCallBackHandler<>();
|
||||
|
||||
String id = generateString();
|
||||
|
@ -279,6 +305,9 @@ public class SimpleRegistryTest {
|
|||
|
||||
AsyncRegistry registry = GetRegistry();
|
||||
registry.setVoted(voterInfo, handler);
|
||||
logger.info("Tried to set that next voter voted : id: {} {}",
|
||||
voterInfo.getId(),
|
||||
new Date());
|
||||
|
||||
jobSemaphore.acquire();
|
||||
assertEquals(1, handler.counter );
|
||||
|
@ -287,12 +316,17 @@ public class SimpleRegistryTest {
|
|||
DummyBulletinBoardCallBackHandler bulletinHandler = readMessagesByTags(tags);
|
||||
|
||||
jobSemaphore.acquire();
|
||||
logger.info("Got set voted messages that have been added lately to the server: {} {} ",
|
||||
GetListOfTags(bulletinHandler.messages, RegistryTags.ID_TAG),
|
||||
new Date());
|
||||
|
||||
tags.clear();
|
||||
tags.add(RegistryTags.ID_TAG + id);
|
||||
|
||||
int counter = countMessagesWithTags(bulletinHandler.messages, tags);
|
||||
assert counter == 1 : "The server don't have the new user id.";
|
||||
logger.info("The server had a message with voter data: id: {} {}", id, new Date());
|
||||
logger.info("Ended testing registry set voted functionality: {}\n\n", new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -300,6 +334,8 @@ public class SimpleRegistryTest {
|
|||
*/
|
||||
@Test
|
||||
public void testSetVoterGroups() throws InterruptedException, SignatureException, IOException, ClassNotFoundException {
|
||||
logger.info("Testing registry set voter groups functionality: {}", new Date());
|
||||
|
||||
DummyRegistryCallBackHandler<Boolean> handler = new DummyRegistryCallBackHandler<>();
|
||||
|
||||
String voterId = generateString();
|
||||
|
@ -310,6 +346,10 @@ public class SimpleRegistryTest {
|
|||
|
||||
AsyncRegistry registry = GetRegistry();
|
||||
registry.setVoterGroups(voterInfo, handler);
|
||||
logger.info("Tried to set voter groups : id: {} groupId: {} {}",
|
||||
voterId,
|
||||
groupId1,
|
||||
new Date());
|
||||
|
||||
jobSemaphore.acquire();
|
||||
assertEquals("The callback handler hasn't been called yet", 1, handler.counter);
|
||||
|
@ -319,18 +359,27 @@ public class SimpleRegistryTest {
|
|||
DummyBulletinBoardCallBackHandler bulletinHandler = readMessagesByTags(tags);
|
||||
|
||||
jobSemaphore.acquire();
|
||||
logger.info("Got set voter groups messages that have been added lately to the server: {} {} ",
|
||||
GetListOfTags(bulletinHandler.messages, RegistryTags.ID_TAG),
|
||||
new Date());
|
||||
|
||||
BulletinBoardMessage latestMessage = getLatestMessage(bulletinHandler.messages);
|
||||
|
||||
assert findTagWithPrefix(latestMessage, RegistryTags.ID_TAG).equals(voterId) :
|
||||
"The latest message recieved is not of our voter";
|
||||
|
||||
logger.info("The server had a message of our voter, data: id: {} {}",
|
||||
findTagWithPrefix(latestMessage, RegistryTags.ID_TAG), new Date());
|
||||
|
||||
VoterRegistry.VoterRegistryMessage voterRegistryMessage =
|
||||
VoterRegistry.VoterRegistryMessage.parseFrom(latestMessage.getMsg().getData());
|
||||
|
||||
List<GroupID> groupsIds = voterRegistryMessage.getGroupIDList();
|
||||
|
||||
assert groupsIds.get(0).getId().equals(groupId1) : "The latest message doesn't have the voter group";
|
||||
logger.info("The server had a message with voter data: groupId: {} {}",
|
||||
groupsIds.get(0).getId(), new Date());
|
||||
logger.info("Ended testing registry set voter groups functionality: {}\n\n", new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -338,6 +387,7 @@ public class SimpleRegistryTest {
|
|||
*/
|
||||
@Test
|
||||
public void testGetGroups() throws InterruptedException, SignatureException, IOException {
|
||||
logger.info("Testing registry get voter groups functionality: {}", new Date());
|
||||
DummyRegistryCallBackHandler<Boolean> handler =
|
||||
new DummyRegistryCallBackHandler<>();
|
||||
|
||||
|
@ -351,6 +401,11 @@ public class SimpleRegistryTest {
|
|||
|
||||
AsyncRegistry registry = GetRegistry();
|
||||
registry.setVoterGroups(voterInfo, handler);
|
||||
logger.info("Tried to set voter groups : id: {} groupId 1: {} groupId 2: {} {}",
|
||||
voterId,
|
||||
groupId1,
|
||||
groupId2,
|
||||
new Date());
|
||||
|
||||
jobSemaphore.acquire();
|
||||
assertEquals("The callback handler hasn't been called yet", 1, handler.counter );
|
||||
|
@ -361,11 +416,18 @@ public class SimpleRegistryTest {
|
|||
jobSemaphore.acquire(1);
|
||||
List<GroupID> userGroups = groupsHandler.data;
|
||||
|
||||
logger.info("Got get voter groups messages that have been added lately to the server: {}",
|
||||
new Date());
|
||||
|
||||
assert userGroups.contains(GroupID.newBuilder().setId(groupId1).build()) :
|
||||
"The simple voter registry object does not retrieved the first user groups";
|
||||
|
||||
assert userGroups.contains(GroupID.newBuilder().setId(groupId2).build()) :
|
||||
"The simple voter registry object does not retrieved the second user groups";
|
||||
|
||||
logger.info("The server had a message with wanted data: groupId 1: {} groupId 2: {} {}",
|
||||
groupId1, groupId2, new Date());
|
||||
logger.info("Ended testing registry get voter groups functionality: {}\n\n", new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -373,6 +435,7 @@ public class SimpleRegistryTest {
|
|||
*/
|
||||
@Test
|
||||
public void testGetVoter() throws InterruptedException, SignatureException {
|
||||
logger.info("Testing registry get voter groups functionality: {}", new Date());
|
||||
DummyRegistryCallBackHandler<Boolean> handler =
|
||||
new DummyRegistryCallBackHandler<>();
|
||||
|
||||
|
@ -384,6 +447,9 @@ public class SimpleRegistryTest {
|
|||
AsyncRegistry registry = GetRegistry();
|
||||
registry.addVoter(voterInfo, handler);
|
||||
|
||||
logger.info("Tried to get voter with data: id: {} groupId 1: {} groupId 2: {} {}",
|
||||
id, data, new Date());
|
||||
|
||||
jobSemaphore.acquire();
|
||||
assertEquals("The callback handler hasn't been called yet", 1, handler.counter );
|
||||
|
||||
|
@ -391,10 +457,19 @@ public class SimpleRegistryTest {
|
|||
registry.getVoter(VoterID.newBuilder().setId(id).build(), personalHandler);
|
||||
|
||||
jobSemaphore.acquire(1);
|
||||
|
||||
logger.info("Got get voter messages that have been added lately to the server: {} {}",
|
||||
personalHandler.data.getId(),
|
||||
new Date());
|
||||
|
||||
assertEquals("The voter id doesn't match the created on ",
|
||||
id, personalHandler.data.getId().getId());
|
||||
String personalData = personalHandler.data.getInfo();
|
||||
assertTrue("The voter personal data can't be found.", data.equals(personalData));
|
||||
|
||||
logger.info("The server had a message with wanted data: if: {} personal data: {} {}",
|
||||
personalHandler.data.getId().getId(), personalData, new Date());
|
||||
logger.info("Ended testing registry get voter functionality: {}\n\n", new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -403,19 +478,31 @@ public class SimpleRegistryTest {
|
|||
*/
|
||||
@Test
|
||||
public void testHasVoted () throws InterruptedException, SignatureException {
|
||||
logger.info("Testing registry has voted functionality: {}", new Date());
|
||||
|
||||
DummyRegistryCallBackHandler<Boolean> handler = new DummyRegistryCallBackHandler<>();
|
||||
String id = generateString();
|
||||
VoterID voterInfo = VoterID.newBuilder().setId(id).build();
|
||||
|
||||
AsyncRegistry registry = GetRegistry();
|
||||
registry.setVoted(voterInfo, handler);
|
||||
|
||||
logger.info("Tried to set voted with data: id: {} groupId 1: {} {}",
|
||||
id, new Date());
|
||||
|
||||
jobSemaphore.acquire();
|
||||
assertEquals("The callback handler hasn't been called yet", 1, handler.counter);
|
||||
DummyRegistryCallBackHandler<Boolean> personalHandler = new DummyRegistryCallBackHandler<>();
|
||||
registry.hasVoted(VoterID.newBuilder().setId(id).build(), personalHandler);
|
||||
|
||||
jobSemaphore.acquire(1);
|
||||
|
||||
logger.info("Got has voted messages that have been added lately to the server: {} {}",
|
||||
personalHandler.data,
|
||||
new Date());
|
||||
assertTrue("The voter hasn't voted yet.", personalHandler.data);
|
||||
|
||||
logger.info("Ended testing registry has voted functionality: {}\n\n", new Date());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue