@Test public void getInserting() throws Exception { mockStatic(SwiftContext.class); when(SwiftContext.get()).thenReturn(mock(BeanFactory.class)); SegmentKey segKey = mock(SegmentKey.class); Segment realtimeSeg = mock(Segment.class); mockStatic(SegmentUtils.class); when(SegmentUtils.newSegment(segKey)).thenReturn(realtimeSeg); CubePathBuilder cubePathBuilder = mock(CubePathBuilder.class, RETURNS_DEEP_STUBS); whenNew(CubePathBuilder.class).withArguments(segKey).thenReturn(cubePathBuilder); ResourceLocation location = mock(ResourceLocation.class); whenNew(ResourceLocation.class).withArguments(eq(cubePathBuilder.asBackup().build()), eq(StoreType.NIO)).thenReturn(location); DataSource dataSource = mock(DataSource.class, RETURNS_DEEP_STUBS); BackupSegment backupSeg = mock(BackupSegment.class); whenNew(BackupSegment.class).withArguments(location, dataSource.getMetadata()).thenReturn(backupSeg); TransactionManager transactionManager = mock(TransactionManager.class); when(SwiftContext.get().getBean("transactionManager", TransactionManager.class, backupSeg)).thenReturn(transactionManager); TransactionProxyFactory proxyFactory = mock(TransactionProxyFactory.class); whenNew(TransactionProxyFactory.class).withArguments(transactionManager).thenReturn(proxyFactory); SwiftInserter inserter = mock(SwiftInserter.class); mockStatic(SwiftInserter.class); when(SwiftInserter.ofAppendMode(backupSeg)).thenReturn(inserter); SwiftInserter proxyInserter = mock(SwiftInserter.class); when(proxyFactory.getProxy(inserter)).thenReturn(proxyInserter); SwiftSourceAlloter alloter = mock(SwiftSourceAlloter.class); when(backupSeg.isReadable()).thenReturn(true); when(backupSeg.getRowCount()).thenReturn(1); Object inserting = new BackupBlockImporter(dataSource, alloter).getInserting(segKey); verify(transactionManager).setOldAttach(realtimeSeg); verify(proxyFactory).getProxy(inserter); assertEquals(proxyInserter, Whitebox.getInternalState(inserting, "inserter")); assertEquals(backupSeg, Whitebox.getInternalState(inserting, "seg")); assertEquals(1, (int) Whitebox.getInternalState(inserting, "rowCount")); }
@Override protected Inserting getInserting(SegmentKey segKey) { Segment realtimeSeg = SegmentUtils.newSegment(segKey); ResourceLocation location = new ResourceLocation(new CubePathBuilder(segKey).asBackup().build(), StoreType.NIO); Segment backupSeg = new BackupSegment(location, dataSource.getMetadata()); TransactionManager transactionManager = SwiftContext.get().getBean("transactionManager", TransactionManager.class, backupSeg); transactionManager.setOldAttach(realtimeSeg); TransactionProxyFactory proxyFactory = new TransactionProxyFactory(transactionManager); Inserter inserter = (Inserter) proxyFactory.getProxy(SwiftInserter.ofAppendMode(backupSeg)); return new Inserting(inserter, backupSeg, SegmentUtils.safeGetRowCount(backupSeg)); }
BackupBlockImporter extends BaseBlockImporter<A, SwiftResultSet> { @Override protected Inserting getInserting(SegmentKey segKey) { Segment realtimeSeg = SegmentUtils.newSegment(segKey); ResourceLocation location = new ResourceLocation(new CubePathBuilder(segKey).asBackup().build(), StoreType.NIO); Segment backupSeg = new BackupSegment(location, dataSource.getMetadata()); TransactionManager transactionManager = SwiftContext.get().getBean("transactionManager", TransactionManager.class, backupSeg); transactionManager.setOldAttach(realtimeSeg); TransactionProxyFactory proxyFactory = new TransactionProxyFactory(transactionManager); Inserter inserter = (Inserter) proxyFactory.getProxy(SwiftInserter.ofAppendMode(backupSeg)); return new Inserting(inserter, backupSeg, SegmentUtils.safeGetRowCount(backupSeg)); } }
BackupBlockImporter extends BaseBlockImporter<A, SwiftResultSet> { @Override protected Inserting getInserting(SegmentKey segKey) { Segment realtimeSeg = SegmentUtils.newSegment(segKey); ResourceLocation location = new ResourceLocation(new CubePathBuilder(segKey).asBackup().build(), StoreType.NIO); Segment backupSeg = new BackupSegment(location, dataSource.getMetadata()); TransactionManager transactionManager = SwiftContext.get().getBean("transactionManager", TransactionManager.class, backupSeg); transactionManager.setOldAttach(realtimeSeg); TransactionProxyFactory proxyFactory = new TransactionProxyFactory(transactionManager); Inserter inserter = (Inserter) proxyFactory.getProxy(SwiftInserter.ofAppendMode(backupSeg)); return new Inserting(inserter, backupSeg, SegmentUtils.safeGetRowCount(backupSeg)); } BackupBlockImporter(DataSource dataSource, A alloter); }
BackupBlockImporter extends BaseBlockImporter<A, SwiftResultSet> { @Override protected Inserting getInserting(SegmentKey segKey) { Segment realtimeSeg = SegmentUtils.newSegment(segKey); ResourceLocation location = new ResourceLocation(new CubePathBuilder(segKey).asBackup().build(), StoreType.NIO); Segment backupSeg = new BackupSegment(location, dataSource.getMetadata()); TransactionManager transactionManager = SwiftContext.get().getBean("transactionManager", TransactionManager.class, backupSeg); transactionManager.setOldAttach(realtimeSeg); TransactionProxyFactory proxyFactory = new TransactionProxyFactory(transactionManager); Inserter inserter = (Inserter) proxyFactory.getProxy(SwiftInserter.ofAppendMode(backupSeg)); return new Inserting(inserter, backupSeg, SegmentUtils.safeGetRowCount(backupSeg)); } BackupBlockImporter(DataSource dataSource, A alloter);  }
BackupBlockImporter extends BaseBlockImporter<A, SwiftResultSet> { @Override protected Inserting getInserting(SegmentKey segKey) { Segment realtimeSeg = SegmentUtils.newSegment(segKey); ResourceLocation location = new ResourceLocation(new CubePathBuilder(segKey).asBackup().build(), StoreType.NIO); Segment backupSeg = new BackupSegment(location, dataSource.getMetadata()); TransactionManager transactionManager = SwiftContext.get().getBean("transactionManager", TransactionManager.class, backupSeg); transactionManager.setOldAttach(realtimeSeg); TransactionProxyFactory proxyFactory = new TransactionProxyFactory(transactionManager); Inserter inserter = (Inserter) proxyFactory.getProxy(SwiftInserter.ofAppendMode(backupSeg)); return new Inserting(inserter, backupSeg, SegmentUtils.safeGetRowCount(backupSeg)); } BackupBlockImporter(DataSource dataSource, A alloter);   }