Skip to content

Commit

Permalink
#225 Improve tests and implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dvoraka committed May 12, 2017
1 parent 3d9487c commit d552e0c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ default ReplicationMessage createLoadMessage(
.build();
}

default ReplicationMessage createLoadReply(
FileMessage message, String toNodeId, String fromNodeId
) {
return new DefaultReplicationMessage.Builder(null)
.correlationId(message.getId())
.type(MessageType.REPLICATION_COMMAND)
.routing(MessageRouting.UNICAST)
.command(Command.LOAD)
.toId(fromNodeId)
.fromId(toNodeId)
.data(message.getData())
.filename(message.getFilename())
.owner(message.getOwner())
.build();
}

default ReplicationMessage createUpdateMessage(
FileMessage message, String nodeId, String neighbourId
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,27 @@ class DefaultReplicationServiceSpec extends Specification implements Replication
1 * fileService.exists(message.getFilename(), message.getOwner()) >> true
}

def "load without existing local file"() {
given:
FileMessage message = Utils.genFileMessage(MessageType.FILE_LOAD)

when:
service.loadFile(message)

then:
2 * fileService.exists(message.getFilename(), message.getOwner()) >> false
1 * responseClient.getResponseWait(_, _) >> replicationList(
createExistsReply(
createExistsRequest(message.getFilename(), message.getOwner(), nodeId),
otherNodeId
)
)

1 * responseClient.getResponseWait(_, _) >> replicationList(
createLoadReply(Mock(FileMessage), otherNodeId, nodeId)
)
}

def "load without existing file"() {
given:
FileMessage message = Utils.genFileMessage(MessageType.FILE_LOAD)
Expand Down

0 comments on commit d552e0c

Please sign in to comment.