This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Datastore { | |
boolean open() {} | |
boolean storeField(key, value) { | |
// I should probably store this | |
false | |
} | |
def close() {} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
void testServiceStoresTheValues() { | |
//given | |
def mockForDataStore = new MockFor(Datastore) | |
mockForDataStore.demand.open { true } | |
mockForDataStore.demand.storeField { k, v -> true } | |
def mockDataStore = mockForDataStore.proxyInstance() | |
def service = new Service(mockDataStore) | |
//when |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def processEntry(Map<String, String> someStuffToStore) { | |
datastore.storeField("this is a made up key","this is a made up value") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mockForDataStore.demand.storeField { k, v -> assert v == "someValue"; assert k == "someKey" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
void testServiceStoresAllTheValues() { | |
//given | |
def mockForDataStore = new MockFor(Datastore) | |
mockForDataStore.demand.open { true } | |
mockForDataStore.demand.storeField { | |
k, v -> | |
if (k == "someKey") assert(v == "someValue") | |
if (k == "anotherKey") assert(k == "anotherValue") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Java Mocktio | |
when(someMock.someMethod("something")).thenReturn("oneThing") | |
when(someMock.someMethod("somethingElse")).thenReturn("anotherThing") | |
//Groovy MockFor | |
someMock.demand.someMethodThatReturns { | |
param1 -> | |
if (param1 == "something") return "oneThing" | |
if (param1 == "somethingElse") return "anotherThing" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.batey.examples | |
import grizzled.slf4j.Logging | |
class SomeClass extends Logging { | |
info("Some information") | |
error("Something terrible") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public RetryDecision onReadTimeout(Statement statement, ConsistencyLevel cl, int requiredResponses, int receivedResponses, boolean dataRetrieved, int nbRetry); | |
public RetryDecision onWriteTimeout(Statement statement, ConsistencyLevel cl, WriteType writeType, int requiredAcks, int receivedAcks, int nbRetry); | |
public RetryDecision onUnavailable(Statement statement, ConsistencyLevel cl, int requiredReplica, int aliveReplica, int nbRetry); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cluster cluster = Cluster.builder() | |
.addContactPoint("127.0.0.1") | |
.withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE) | |
.build(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test(groups = "unit") | |
public void shouldReadRetryIfNumberOfRetriesLessThanConfiguredRetries() { | |
ConsistencyLevel originalConsistency = ConsistencyLevel.ALL; | |
int numberOfRetries = NUMBER_OF_RETRIES - 1; | |
RetryPolicy.RetryDecision decision = underTest.onReadTimeout(null, originalConsistency, 1, 1, false, numberOfRetries); | |
assertEquals(decision.getType(), RetryPolicy.RetryDecision.Type.RETRY, "Should retry"); | |
} |