Changed the code according to Arbel Peled CR.
parent
2d72822405
commit
4b31e87d07
|
@ -18,7 +18,6 @@ public class BulletinBoardUtils {
|
||||||
* @return the tag without the prefix, if found, or null if not found
|
* @return the tag without the prefix, if found, or null if not found
|
||||||
*/
|
*/
|
||||||
public static String findTagWithPrefix(BulletinBoardMessage message, String prefix) {
|
public static String findTagWithPrefix(BulletinBoardMessage message, String prefix) {
|
||||||
|
|
||||||
for (String tag : message.getMsg().getTagList()){
|
for (String tag : message.getMsg().getTagList()){
|
||||||
if (tag.startsWith(prefix)) {
|
if (tag.startsWith(prefix)) {
|
||||||
return tag.substring(prefix.length());
|
return tag.substring(prefix.length());
|
||||||
|
|
|
@ -80,9 +80,9 @@ public class Registry implements VoterRegistry{
|
||||||
.addTag(RegistryTags.ADD_TO_GROUP_TAG)
|
.addTag(RegistryTags.ADD_TO_GROUP_TAG)
|
||||||
.setTimestamp(Timestamp.newBuilder().setNanos((int) System.nanoTime()).build());
|
.setTimestamp(Timestamp.newBuilder().setNanos((int) System.nanoTime()).build());
|
||||||
|
|
||||||
for ( int i = 0 ; i < voterGroup.getGroupIDCount() ; i++)
|
for (GroupID groupId : voterGroup.getGroupIDList())
|
||||||
{
|
{
|
||||||
basicMessage.addTag(RegistryTags.GROUP_ID_TAG + voterGroup.getGroupID(i).getId());
|
basicMessage.addTag(RegistryTags.GROUP_ID_TAG + groupId.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new MessagesCallBack(callback));
|
bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new MessagesCallBack(callback));
|
||||||
|
|
|
@ -56,8 +56,7 @@ public class LatestMessagesCallBack implements FutureCallback<List<BulletinBoard
|
||||||
*/
|
*/
|
||||||
private boolean isAddToGroupsList(List<BulletinBoardMessage> msg) {
|
private boolean isAddToGroupsList(List<BulletinBoardMessage> msg) {
|
||||||
List<String> tags = msg.get(0).getMsg().getTagList();
|
List<String> tags = msg.get(0).getMsg().getTagList();
|
||||||
for (int i = 0 ;i < tags.size(); i++) {
|
for (String tag : tags) {
|
||||||
String tag = tags.get(i);
|
|
||||||
if(tag.contains(RegistryTags.GROUP_ID_TAG))
|
if(tag.contains(RegistryTags.GROUP_ID_TAG))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@ -123,9 +122,8 @@ public class LatestMessagesCallBack implements FutureCallback<List<BulletinBoard
|
||||||
@Override
|
@Override
|
||||||
public List<BulletinBoardMessage> validate(List<BulletinBoardMessage> object) throws ValidationError {
|
public List<BulletinBoardMessage> validate(List<BulletinBoardMessage> object) throws ValidationError {
|
||||||
List<BulletinBoardMessage> verifiedMessages = new ArrayList<>(object.size());
|
List<BulletinBoardMessage> verifiedMessages = new ArrayList<>(object.size());
|
||||||
for (int i = 0 ; i < object.size() ; i++)
|
for (BulletinBoardMessage message : object)
|
||||||
{
|
{
|
||||||
BulletinBoardMessage message = object.get(i);
|
|
||||||
if(VerifyMessage(message.getMsg()))
|
if(VerifyMessage(message.getMsg()))
|
||||||
{
|
{
|
||||||
verifiedMessages.add(message);
|
verifiedMessages.add(message);
|
||||||
|
|
|
@ -28,9 +28,8 @@ public abstract class MessageCollectionUtils {
|
||||||
return filters.build();
|
return filters.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0 ;i < tags.size() ; i++) {
|
for (String tag : tags) {
|
||||||
String tag = tags.get(i);
|
MessageFilter filter = MessageFilter.newBuilder().setTag(tag).setType(FilterType.TAG).build();
|
||||||
MessageFilter.Builder filter = MessageFilter.newBuilder().setTag(tag).setType(FilterType.TAG);
|
|
||||||
filters.addFilter(filter);
|
filters.addFilter(filter);
|
||||||
}
|
}
|
||||||
return filters.build();
|
return filters.build();
|
||||||
|
|
|
@ -5,13 +5,13 @@ package meerkat.registry;
|
||||||
* Created by Vladimir Eliezer Tokarev on 1/9/2016.
|
* Created by Vladimir Eliezer Tokarev on 1/9/2016.
|
||||||
* Have the tags for the registry messages
|
* Have the tags for the registry messages
|
||||||
*/
|
*/
|
||||||
public abstract class RegistryTags {
|
public interface RegistryTags {
|
||||||
public final static String ID_TAG = "ID: ";
|
String ID_TAG = "ID: ";
|
||||||
public final static String VOTER_ENTRY_TAG = "VoterEntry: ";
|
String VOTER_ENTRY_TAG = "VoterEntry: ";
|
||||||
public final static String VOTER_DATA_TAG = "Data: ";
|
String VOTER_DATA_TAG = "Data: ";
|
||||||
public final static String GROUP_ID_TAG = "GroupID: ";
|
String GROUP_ID_TAG = "GroupID: ";
|
||||||
public final static String ADD_TO_GROUP_TAG = "AddToGroups: ";
|
String ADD_TO_GROUP_TAG = "AddToGroups: ";
|
||||||
public final static String VOTE_ACTION_TAG = "VoteAction: ";
|
String VOTE_ACTION_TAG = "VoteAction: ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,6 @@ import com.google.common.util.concurrent.FutureCallback;
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import meerkat.Registry;
|
import meerkat.Registry;
|
||||||
import meerkat.registry.MessageCollectionUtils;
|
|
||||||
import meerkat.registry.RegistryTags;
|
|
||||||
import meerkat.bulletinboard.AsyncBulletinBoardClient;
|
import meerkat.bulletinboard.AsyncBulletinBoardClient;
|
||||||
import meerkat.bulletinboard.ThreadedBulletinBoardClient;
|
import meerkat.bulletinboard.ThreadedBulletinBoardClient;
|
||||||
import meerkat.crypto.concrete.ECDSASignature;
|
import meerkat.crypto.concrete.ECDSASignature;
|
||||||
|
@ -14,6 +12,8 @@ import meerkat.protobuf.VoterRegistry.GroupID;
|
||||||
import meerkat.protobuf.VoterRegistry.VoterID;
|
import meerkat.protobuf.VoterRegistry.VoterID;
|
||||||
import meerkat.protobuf.VoterRegistry.VoterInfo;
|
import meerkat.protobuf.VoterRegistry.VoterInfo;
|
||||||
import meerkat.protobuf.Voting;
|
import meerkat.protobuf.Voting;
|
||||||
|
import meerkat.registry.MessageCollectionUtils;
|
||||||
|
import meerkat.registry.RegistryTags;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
@ -23,6 +23,8 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
|
|
||||||
|
import static meerkat.util.BulletinBoardUtils.findTagWithPrefix;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: add logs prints for the tests to be clear what they are
|
* TODO: add logs prints for the tests to be clear what they are
|
||||||
*/
|
*/
|
||||||
|
@ -144,13 +146,11 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
{
|
{
|
||||||
int counter = 0 ;
|
int counter = 0 ;
|
||||||
|
|
||||||
for (int i = 0 ; i < messages.size() ; i++) {
|
for (BulletinBoardMessage message : messages) {
|
||||||
BulletinBoardMessage message = messages.get(i);
|
|
||||||
int wantedTagsCounter = 0;
|
int wantedTagsCounter = 0;
|
||||||
|
|
||||||
for (int j = 0 ;j < tags.size() ; j++) {
|
for (String tag : tags) {
|
||||||
String tag = tags.get(j);
|
if(findTagWithPrefix(message, tag)!=null){
|
||||||
if(MessageCollectionUtils.GetTagByName(message.getMsg().getTagList(), tag)!=null){
|
|
||||||
wantedTagsCounter++;
|
wantedTagsCounter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,8 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
|
|
||||||
jobSemaphore.acquire();
|
jobSemaphore.acquire();
|
||||||
|
|
||||||
tags.add(id);
|
tags.clear();
|
||||||
|
tags.add(RegistryTags.ID_TAG + id);
|
||||||
|
|
||||||
int counter = countMessagesWithTags(bulletinHandler.messages, tags);
|
int counter = countMessagesWithTags(bulletinHandler.messages, tags);
|
||||||
assert counter == 1 : "The server don't have the new user data.";
|
assert counter == 1 : "The server don't have the new user data.";
|
||||||
|
@ -214,7 +215,9 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
|
|
||||||
jobSemaphore.acquire();
|
jobSemaphore.acquire();
|
||||||
|
|
||||||
tags.add(id);
|
tags.clear();
|
||||||
|
tags.add(RegistryTags.ID_TAG + id);
|
||||||
|
|
||||||
int counter = countMessagesWithTags(bulletinHandler.messages, tags);
|
int counter = countMessagesWithTags(bulletinHandler.messages, tags);
|
||||||
assert counter == 1 : "The server don't have the new user id.";
|
assert counter == 1 : "The server don't have the new user id.";
|
||||||
}
|
}
|
||||||
|
@ -244,8 +247,9 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
|
|
||||||
jobSemaphore.acquire();
|
jobSemaphore.acquire();
|
||||||
|
|
||||||
tags.add(voterId);
|
tags.clear();
|
||||||
tags.add(groupId);
|
tags.add(RegistryTags.ID_TAG + voterId);
|
||||||
|
tags.add(RegistryTags.GROUP_ID_TAG + groupId);
|
||||||
|
|
||||||
int counter = countMessagesWithTags(bulletinHandler.messages, tags);
|
int counter = countMessagesWithTags(bulletinHandler.messages, tags);
|
||||||
assert counter == 1 : "The server don't have the new user added to group.";
|
assert counter == 1 : "The server don't have the new user added to group.";
|
||||||
|
@ -277,8 +281,7 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
|
|
||||||
jobSemaphore.acquire(1);
|
jobSemaphore.acquire(1);
|
||||||
List<String> userGroups = groupsHandler.data;
|
List<String> userGroups = groupsHandler.data;
|
||||||
assert userGroups.contains(RegistryTags.GROUP_ID_TAG + groupId) :
|
assert userGroups.contains(groupId) : "The simple voter registry object does not retrieved right user groups";
|
||||||
"The simple voter registry object does not retrieved right user groups";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -303,10 +306,8 @@ public class SimpleRegistryTest extends TestCase {
|
||||||
registry.GetPersonIDDetails(VoterID.newBuilder().setId(id).build(), personalHandler);
|
registry.GetPersonIDDetails(VoterID.newBuilder().setId(id).build(), personalHandler);
|
||||||
|
|
||||||
jobSemaphore.acquire(1);
|
jobSemaphore.acquire(1);
|
||||||
assertEquals(RegistryTags.ID_TAG + id, MessageCollectionUtils.GetTagByName(personalHandler
|
assertEquals(id, findTagWithPrefix(personalHandler.data, RegistryTags.ID_TAG));
|
||||||
.data.getMsg().getTagList(), RegistryTags.ID_TAG));
|
assertTrue(findTagWithPrefix(personalHandler.data, RegistryTags.VOTER_DATA_TAG).contains(data));
|
||||||
assertTrue(MessageCollectionUtils.GetTagByName(personalHandler.data.getMsg().getTagList(),
|
|
||||||
RegistryTags.VOTER_DATA_TAG).contains(data));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue