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
|
||||
*/
|
||||
public static String findTagWithPrefix(BulletinBoardMessage message, String prefix) {
|
||||
|
||||
for (String tag : message.getMsg().getTagList()){
|
||||
if (tag.startsWith(prefix)) {
|
||||
return tag.substring(prefix.length());
|
||||
|
|
|
@ -80,9 +80,9 @@ public class Registry implements VoterRegistry{
|
|||
.addTag(RegistryTags.ADD_TO_GROUP_TAG)
|
||||
.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));
|
||||
|
|
|
@ -56,8 +56,7 @@ public class LatestMessagesCallBack implements FutureCallback<List<BulletinBoard
|
|||
*/
|
||||
private boolean isAddToGroupsList(List<BulletinBoardMessage> msg) {
|
||||
List<String> tags = msg.get(0).getMsg().getTagList();
|
||||
for (int i = 0 ;i < tags.size(); i++) {
|
||||
String tag = tags.get(i);
|
||||
for (String tag : tags) {
|
||||
if(tag.contains(RegistryTags.GROUP_ID_TAG))
|
||||
{
|
||||
return true;
|
||||
|
@ -123,9 +122,8 @@ public class LatestMessagesCallBack implements FutureCallback<List<BulletinBoard
|
|||
@Override
|
||||
public List<BulletinBoardMessage> validate(List<BulletinBoardMessage> object) throws ValidationError {
|
||||
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()))
|
||||
{
|
||||
verifiedMessages.add(message);
|
||||
|
|
|
@ -28,9 +28,8 @@ public abstract class MessageCollectionUtils {
|
|||
return filters.build();
|
||||
}
|
||||
|
||||
for (int i = 0 ;i < tags.size() ; i++) {
|
||||
String tag = tags.get(i);
|
||||
MessageFilter.Builder filter = MessageFilter.newBuilder().setTag(tag).setType(FilterType.TAG);
|
||||
for (String tag : tags) {
|
||||
MessageFilter filter = MessageFilter.newBuilder().setTag(tag).setType(FilterType.TAG).build();
|
||||
filters.addFilter(filter);
|
||||
}
|
||||
return filters.build();
|
||||
|
|
|
@ -5,13 +5,13 @@ package meerkat.registry;
|
|||
* Created by Vladimir Eliezer Tokarev on 1/9/2016.
|
||||
* Have the tags for the registry messages
|
||||
*/
|
||||
public abstract class RegistryTags {
|
||||
public final static String ID_TAG = "ID: ";
|
||||
public final static String VOTER_ENTRY_TAG = "VoterEntry: ";
|
||||
public final static String VOTER_DATA_TAG = "Data: ";
|
||||
public final static String GROUP_ID_TAG = "GroupID: ";
|
||||
public final static String ADD_TO_GROUP_TAG = "AddToGroups: ";
|
||||
public final static String VOTE_ACTION_TAG = "VoteAction: ";
|
||||
public interface RegistryTags {
|
||||
String ID_TAG = "ID: ";
|
||||
String VOTER_ENTRY_TAG = "VoterEntry: ";
|
||||
String VOTER_DATA_TAG = "Data: ";
|
||||
String GROUP_ID_TAG = "GroupID: ";
|
||||
String ADD_TO_GROUP_TAG = "AddToGroups: ";
|
||||
String VOTE_ACTION_TAG = "VoteAction: ";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@ import com.google.common.util.concurrent.FutureCallback;
|
|||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import junit.framework.TestCase;
|
||||
import meerkat.Registry;
|
||||
import meerkat.registry.MessageCollectionUtils;
|
||||
import meerkat.registry.RegistryTags;
|
||||
import meerkat.bulletinboard.AsyncBulletinBoardClient;
|
||||
import meerkat.bulletinboard.ThreadedBulletinBoardClient;
|
||||
import meerkat.crypto.concrete.ECDSASignature;
|
||||
|
@ -14,6 +12,8 @@ import meerkat.protobuf.VoterRegistry.GroupID;
|
|||
import meerkat.protobuf.VoterRegistry.VoterID;
|
||||
import meerkat.protobuf.VoterRegistry.VoterInfo;
|
||||
import meerkat.protobuf.Voting;
|
||||
import meerkat.registry.MessageCollectionUtils;
|
||||
import meerkat.registry.RegistryTags;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.math.BigInteger;
|
||||
|
@ -23,6 +23,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import static meerkat.util.BulletinBoardUtils.findTagWithPrefix;
|
||||
|
||||
/**
|
||||
* 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 ;
|
||||
|
||||
for (int i = 0 ; i < messages.size() ; i++) {
|
||||
BulletinBoardMessage message = messages.get(i);
|
||||
for (BulletinBoardMessage message : messages) {
|
||||
int wantedTagsCounter = 0;
|
||||
|
||||
for (int j = 0 ;j < tags.size() ; j++) {
|
||||
String tag = tags.get(j);
|
||||
if(MessageCollectionUtils.GetTagByName(message.getMsg().getTagList(), tag)!=null){
|
||||
for (String tag : tags) {
|
||||
if(findTagWithPrefix(message, tag)!=null){
|
||||
wantedTagsCounter++;
|
||||
}
|
||||
}
|
||||
|
@ -186,7 +186,8 @@ public class SimpleRegistryTest extends TestCase {
|
|||
|
||||
jobSemaphore.acquire();
|
||||
|
||||
tags.add(id);
|
||||
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.";
|
||||
|
@ -214,7 +215,9 @@ public class SimpleRegistryTest extends TestCase {
|
|||
|
||||
jobSemaphore.acquire();
|
||||
|
||||
tags.add(id);
|
||||
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.";
|
||||
}
|
||||
|
@ -244,8 +247,9 @@ public class SimpleRegistryTest extends TestCase {
|
|||
|
||||
jobSemaphore.acquire();
|
||||
|
||||
tags.add(voterId);
|
||||
tags.add(groupId);
|
||||
tags.clear();
|
||||
tags.add(RegistryTags.ID_TAG + voterId);
|
||||
tags.add(RegistryTags.GROUP_ID_TAG + groupId);
|
||||
|
||||
int counter = countMessagesWithTags(bulletinHandler.messages, tags);
|
||||
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);
|
||||
List<String> userGroups = groupsHandler.data;
|
||||
assert userGroups.contains(RegistryTags.GROUP_ID_TAG + groupId) :
|
||||
"The simple voter registry object does not retrieved right user groups";
|
||||
assert userGroups.contains(groupId) : "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);
|
||||
|
||||
jobSemaphore.acquire(1);
|
||||
assertEquals(RegistryTags.ID_TAG + id, MessageCollectionUtils.GetTagByName(personalHandler
|
||||
.data.getMsg().getTagList(), RegistryTags.ID_TAG));
|
||||
assertTrue(MessageCollectionUtils.GetTagByName(personalHandler.data.getMsg().getTagList(),
|
||||
RegistryTags.VOTER_DATA_TAG).contains(data));
|
||||
assertEquals(id, findTagWithPrefix(personalHandler.data, RegistryTags.ID_TAG));
|
||||
assertTrue(findTagWithPrefix(personalHandler.data, RegistryTags.VOTER_DATA_TAG).contains(data));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue