Skip to content

Commit

Permalink
remove class cast mock madness
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed Oct 23, 2023
1 parent d95388a commit d225253
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ private void scheduleSample() {
sample();
} catch (Throwable e) {
log.error("Unable to sample sync state on: {}", params.member().getId(), e);
sync.completeExceptionally(e);
sync.completeExceptionally(e);e.printStackTrace();
}
}, params.gossipDuration().toNanos(), TimeUnit.NANOSECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package com.salesforce.apollo.choam.support;

import com.google.common.util.concurrent.SettableFuture;
import com.salesfoce.apollo.choam.proto.BlockReplication;
import com.salesfoce.apollo.choam.proto.Blocks;
import com.salesfoce.apollo.choam.proto.Initial;
Expand Down Expand Up @@ -122,31 +121,25 @@ private Terminal mockClient(Member to, Store bootstrapStore, TestChain testChain
when(client.getMember()).thenReturn(to);

when(client.sync(any())).then(invocation -> {
SettableFuture<Initial> futureSailor = SettableFuture.create();
Initial.Builder initial = Initial.newBuilder()
.setCheckpoint(testChain.getSynchronizeCheckpoint().certifiedBlock)
.setCheckpointView(testChain.getSynchronizeView().certifiedBlock)
.setGenesis(testChain.getGenesis().certifiedBlock);
futureSailor.set(initial.build());
return futureSailor;
return initial.build();
});
when(client.fetchViewChain(any())).then(invocation -> {
SettableFuture<Blocks> futureSailor = SettableFuture.create();
BlockReplication rep = invocation.getArgument(0, BlockReplication.class);
BloomFilter<ULong> bff = BloomFilter.from(rep.getBlocksBff());
Blocks.Builder blocks = Blocks.newBuilder();
bootstrapStore.fetchViewChain(bff, blocks, 1, ULong.valueOf(rep.getFrom()), ULong.valueOf(rep.getTo()));
futureSailor.set(blocks.build());
return futureSailor;
return blocks.build();
});
when(client.fetchBlocks(any())).then(invocation -> {
SettableFuture<Blocks> futureSailor = SettableFuture.create();
BlockReplication rep = invocation.getArgument(0, BlockReplication.class);
BloomFilter<ULong> bff = BloomFilter.from(rep.getBlocksBff());
Blocks.Builder blocks = Blocks.newBuilder();
bootstrapStore.fetchBlocks(bff, blocks, 5, ULong.valueOf(rep.getFrom()), ULong.valueOf(rep.getTo()));
futureSailor.set(blocks.build());
return futureSailor;
return blocks.build();
});
return client;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*/
package com.salesforce.apollo.choam.support;

import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import com.salesfoce.apollo.choam.proto.Checkpoint;
import com.salesfoce.apollo.choam.proto.CheckpointReplication;
import com.salesfoce.apollo.choam.proto.CheckpointSegments;
Expand Down Expand Up @@ -115,13 +113,11 @@ public void functional() throws Exception {
Terminal client = mock(Terminal.class);
when(client.fetch(any())).then(new Answer<>() {
@Override
public ListenableFuture<CheckpointSegments> answer(InvocationOnMock invocation) throws Throwable {
SettableFuture<CheckpointSegments> futureSailor = SettableFuture.create();
public CheckpointSegments answer(InvocationOnMock invocation) throws Throwable {
CheckpointReplication rep = invocation.getArgument(0, CheckpointReplication.class);
List<Slice> fetched = state.fetchSegments(BloomFilter.from(rep.getCheckpointSegments()), 2);
System.out.println("Fetched: " + fetched.size());
futureSailor.set(CheckpointSegments.newBuilder().addAllSegments(fetched).build());
return futureSailor;
return CheckpointSegments.newBuilder().addAllSegments(fetched).build();
}
});
@SuppressWarnings("unchecked") CommonCommunications<Terminal, Concierge> comm = mock(CommonCommunications.class);
Expand Down

0 comments on commit d225253

Please sign in to comment.