juan_gandhi: (VP)

def write2DB[T <: {def save(): Boolean }](t:T): Result[T] =
if (t.save()) Good(t) else Result.error(s"Failed to save $t")


The trick is, never call save(), because it involves implicits etc. Call write2DB. Mock this function in your unittests.
juan_gandhi: (Default)
Just wrote a couple of methods in my main mock class.

public void failingOn(String regex) {
  this.failureCondition = regex;
}

public void maybeFail(Object...objects) throws HBaseException {
  if (failureCondition != null) {
            String s = Arrays.asList(objects).toString();
    if (s.matches(failureCondition)) {
      throw new HBaseException("Congratulations, you hit the jackpot today: " + s);
    }
  }
}



and most of the methods look like this:

@Override
public void bulkDelete(String tableName, Collection rowKeys, String columnFamily) throws HBaseException {
  maybeFail("bulkDelete", tableName, rowKeys, columnFamily);
  table(tableName).family(columnFamily).delete(rowKeys);
}


Now in the test I write stuff like this:
@Test    
public void testPut_replicating_withErrors() throws Exception {
  MockHBaseOperations cluster2 = new MockHBaseOperations();
  cluster2.failingOn("\\[sendToCluster, BadTable,.*");
  ...
}


... do you need explanations on how it works?

What I personally enjoy here is the leisure JavaScript coding style, where you just join the arguments, not giving a fuck about their types.

Profile

juan_gandhi: (Default)
juan_gandhi

July 2017

S M T W T F S
       1
2 3 4 5 67 8
9 10 11 1213 14 15
16 17 18 19 20 21 22
23 24 2526272829
3031     

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 26th, 2017 04:44 am
Powered by Dreamwidth Studios