Skip to content

Commit

Permalink
#302 Tuning and update test
Browse files Browse the repository at this point in the history
  • Loading branch information
dvoraka committed Jan 13, 2018
1 parent 947aa72 commit c2f7d76
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private void initializeSafe() {
/**
* Initializes the lock before start.
*/
public void initialize() {
private void initialize() {
waitUntil(responseClient::isRunning);
initializeSequence();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import dvoraka.avservice.client.service.ReplicationServiceClient
import dvoraka.avservice.client.service.response.ReplicationMessageList
import dvoraka.avservice.client.service.response.ReplicationResponseClient
import dvoraka.avservice.common.data.replication.ReplicationMessage
import dvoraka.avservice.common.helper.WaitingHelper
import dvoraka.avservice.common.helper.replication.ReplicationHelper
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Subject
import spock.util.concurrent.PollingConditions


class DefaultRemoteLockSpec extends Specification implements ReplicationHelper {
class DefaultRemoteLockSpec extends Specification implements ReplicationHelper, WaitingHelper {

@Subject
DefaultRemoteLock lock
Expand Down Expand Up @@ -83,7 +84,7 @@ class DefaultRemoteLockSpec extends Specification implements ReplicationHelper {
result
}

def "lock file and get lower lock count"() {
def "lock file with lower lock count"() {
when:
boolean result = lock.lockForFile('test', 'test', 2)

Expand All @@ -102,16 +103,6 @@ class DefaultRemoteLockSpec extends Specification implements ReplicationHelper {
1 * responseClient.getResponseWaitSize(_, _, _) >> Optional.empty()
}

def "synchronize"() {
when:
lock.initialize()

then:
1 * serviceClient.sendMessage(_)
1 * responseClient.getResponseWait(_, _) >> Optional.of(genSequenceResponse())
1 * responseClient.isRunning() >> true
}

def "on message with unicast message"() {
when:
lock.onMessage(createDiscoverReply(createDiscoverRequest(nodeId), nodeId))
Expand All @@ -130,7 +121,8 @@ class DefaultRemoteLockSpec extends Specification implements ReplicationHelper {

def "on message with sequence request with initialized lock"() {
when:
lock.initialize()
lock.start()
waitUntil({ lock.isRunning() })
lock.onMessage(createSequenceRequest(nodeId))

then:
Expand All @@ -144,7 +136,7 @@ class DefaultRemoteLockSpec extends Specification implements ReplicationHelper {
lock.onMessage(createSequenceRequest(nodeId))

then:
0 * serviceClient.sendMessage(_)
0 * _
}

//TODO: needs started lock
Expand Down

0 comments on commit c2f7d76

Please sign in to comment.