|
| 1 | +package zingg.common.core.executor.blockingverifier; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 5 | + |
| 6 | +import java.util.List; |
| 7 | + |
| 8 | +import org.apache.commons.logging.Log; |
| 9 | +import org.apache.commons.logging.LogFactory; |
| 10 | +import org.junit.jupiter.api.Test; |
| 11 | + |
| 12 | +import zingg.common.client.Arguments; |
| 13 | +import zingg.common.client.IArguments; |
| 14 | +import zingg.common.client.ZFrame; |
| 15 | +import zingg.common.client.ZinggClientException; |
| 16 | +import zingg.common.client.util.ColName; |
| 17 | +import zingg.common.client.util.DFObjectUtil; |
| 18 | +import zingg.common.core.context.Context; |
| 19 | +import zingg.common.core.executor.blockingverifier.data.BlockingVerifyData; |
| 20 | +import zingg.common.core.executor.blockingverifier.model.BlockCountsData; |
| 21 | +import zingg.common.core.executor.blockingverifier.model.BlockedData; |
| 22 | + |
| 23 | +public abstract class TestVerifyBlocking<S,D,R,C,T> { |
| 24 | + |
| 25 | + public static final Log LOG = LogFactory.getLog(TestVerifyBlocking.class); |
| 26 | + protected Context<S, D, R, C, T> context; |
| 27 | + protected DFObjectUtil<S, D, R, C> dfObjectUtil; |
| 28 | + protected IVerifyBlockingPipes<S,D,R,C> verifyBlockingPipes; |
| 29 | + IArguments arguments = new Arguments(); |
| 30 | + |
| 31 | + public TestVerifyBlocking(){ |
| 32 | + |
| 33 | + } |
| 34 | + |
| 35 | + public void initialize(DFObjectUtil<S, D, R, C> dfObjectUtil, Context<S, D, R, C, T> context) { |
| 36 | + this.dfObjectUtil = dfObjectUtil; |
| 37 | + this.context = context; |
| 38 | + } |
| 39 | + |
| 40 | + public abstract VerifyBlocking<S,D,R,C,T> getVerifyBlocker(); |
| 41 | + |
| 42 | + public abstract IVerifyBlockingPipes<S,D,R,C> getVerifyBlockingPipes(); |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testGetBlockCounts() throws ZinggClientException, Exception{ |
| 46 | + VerifyBlocking<S,D,R,C,T> vb = getVerifyBlocker(); |
| 47 | + verifyBlockingPipes = getVerifyBlockingPipes(); |
| 48 | + |
| 49 | + ZFrame<D,R,C> blocked = dfObjectUtil.getDFFromObjectList(BlockingVerifyData.getBlockedDF1(), BlockedData.class); |
| 50 | + ZFrame<D,R,C> blockCounts = vb.getBlockCounts(blocked,verifyBlockingPipes); |
| 51 | + blockCounts = blockCounts.sortDescending(ColName.HASH_COUNTS_COL); |
| 52 | + |
| 53 | + ZFrame<D,R,C> expBlockCounts = dfObjectUtil.getDFFromObjectList(BlockingVerifyData.getExpectedBlockedDF1(), BlockCountsData.class); |
| 54 | + |
| 55 | + assertTrue(expBlockCounts.except(blockCounts).isEmpty()); |
| 56 | + assertTrue(blockCounts.except(expBlockCounts).isEmpty()); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void testGetBlockSamples() throws Exception, ZinggClientException{ |
| 61 | + VerifyBlocking<S,D,R,C,T> vb = getVerifyBlocker(); |
| 62 | + verifyBlockingPipes = getVerifyBlockingPipes(); |
| 63 | + vb.setModelHelper(verifyBlockingPipes.getModelHelper()); |
| 64 | + verifyBlockingPipes.setTimestamp(vb.getTimestamp()); |
| 65 | + arguments.setModelId("junit_vb"); |
| 66 | + vb.setArgs(arguments); |
| 67 | + |
| 68 | + ZFrame<D,R,C> blocked = dfObjectUtil.getDFFromObjectList(BlockingVerifyData.getBlockedDF1(), BlockedData.class); |
| 69 | + ZFrame<D,R,C> blockCounts = vb.getBlockCounts(blocked,verifyBlockingPipes); |
| 70 | + ZFrame<D,R,C> blockTopRec = vb.getTopRecordsDF(blockCounts); |
| 71 | + assertTrue(checkNoOfTopBlocks(blockTopRec)); |
| 72 | + |
| 73 | + List<R> topRec = blockTopRec.collectAsList(); |
| 74 | + assertEquals("3930",blockTopRec.getAsString(topRec.get(1), ColName.HASH_COL)); |
| 75 | + |
| 76 | + ZFrame<D,R,C> matchingRec1 = vb.getMatchingRecords(topRec.get(0), blockTopRec, blocked, 3915); |
| 77 | + context.getPipeUtil().write(matchingRec1, verifyBlockingPipes.getBlockSamplesPipe(arguments, ColName.BLOCK_SAMPLES + "3915")); |
| 78 | + |
| 79 | + ZFrame<D,R,C> matchingRec2 = vb.getMatchingRecords(topRec.get(2), blockTopRec, blocked, -3910); |
| 80 | + context.getPipeUtil().write(matchingRec2, verifyBlockingPipes.getBlockSamplesPipe(arguments, ColName.BLOCK_SAMPLES + "-3910")); |
| 81 | + |
| 82 | + ZFrame<D, R, C> df1 = context.getPipeUtil().read(false, false, verifyBlockingPipes.getBlockSamplesPipe(arguments, ColName.BLOCK_SAMPLES + "3915")); |
| 83 | + ZFrame<D, R, C> df2 = context.getPipeUtil().read(false, false, verifyBlockingPipes.getBlockSamplesPipe(arguments, getMassagedTableName("-3910"))); |
| 84 | + |
| 85 | + assertTrue(df1.count() == 3L); |
| 86 | + assertTrue(df2.count() == 1L); |
| 87 | + } |
| 88 | + |
| 89 | + public boolean checkNoOfTopBlocks(ZFrame<D,R,C> blockTopRec){ |
| 90 | + if(blockTopRec.count() == 3L){ |
| 91 | + return true; |
| 92 | + } |
| 93 | + else{ |
| 94 | + return false; |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + public abstract String getMassagedTableName(String hash); |
| 99 | + |
| 100 | + |
| 101 | +} |
0 commit comments