@Test public void fromSubscription() { Subscription s = mock(Subscription.class); Disposables.fromSubscription(s).dispose(); verify(s).cancel(); verify(s, never()).request(anyInt()); }
@Test public void initShouldCreateThreadPool() throws Throwable { ExecutorFactory mockExecutorFactory = mock( ExecutorFactory.class ); when( mockExecutorFactory.create( anyInt(), anyInt(), any(), anyInt(), anyBoolean(), any() ) ).thenReturn( Executors.newCachedThreadPool() ); ExecutorBoltScheduler scheduler = new ExecutorBoltScheduler( CONNECTOR_KEY, mockExecutorFactory, jobScheduler, logService, 0, 10, Duration.ofMinutes( 1 ), 0, ForkJoinPool.commonPool() ); scheduler.start(); verify( jobScheduler ).threadFactory( Group.BOLT_WORKER ); verify( mockExecutorFactory, times( 1 ) ).create( anyInt(), anyInt(), any( Duration.class ), anyInt(), anyBoolean(), any( ThreadFactory.class ) ); }
@BeforeMethod public void setup() { Mockito.reset(expiry); when(expiry.expireAfterCreate(anyInt(), anyInt(), anyLong())).thenReturn(ONE_MINUTE); when(expiry.expireAfterUpdate(anyInt(), anyInt(), anyLong(), anyLong())).thenReturn(ONE_MINUTE); when(expiry.expireAfterRead(anyInt(), anyInt(), anyLong(), anyLong())).thenReturn(ONE_MINUTE); }
@BeforeMethod public void setup() { Mockito.reset(expiry); when(expiry.expireAfterCreate(anyInt(), anyInt(), anyLong())).thenReturn(ONE_MINUTE); when(expiry.expireAfterUpdate(anyInt(), anyInt(), anyLong(), anyLong())).thenReturn(ONE_MINUTE); when(expiry.expireAfterRead(anyInt(), anyInt(), anyLong(), anyLong())).thenReturn(ONE_MINUTE); }
@Before public void setUpMocks() throws IOException { when( idGeneratorFactory.open( any( File.class ), eq( idType ), any( LongSupplier.class ), anyLong() ) ) .thenReturn( idGenerator ); when( pageFile.pageSize() ).thenReturn( PAGE_SIZE ); when( pageFile.io( anyLong(), anyInt() ) ).thenReturn( pageCursor ); when( pageCache.map( eq( storeFile ), anyInt() ) ).thenReturn( pageFile ); }
@Test public void configured() { jcache.put(KEY_1, VALUE_1); verify(expiry, times(1)).expireAfterCreate(anyInt(), anyInt(), anyLong()); jcache.put(KEY_1, VALUE_2); verify(expiry).expireAfterUpdate(anyInt(), anyInt(), anyLong(), anyLong()); jcache.get(KEY_1); verify(expiry).expireAfterRead(anyInt(), anyInt(), anyLong(), anyLong()); } }
@Test public void expiry() { jcache.put(KEY_1, VALUE_1); verify(expiry, times(1)).expireAfterCreate(anyInt(), anyInt(), anyLong()); jcache.put(KEY_1, VALUE_2); verify(expiry).expireAfterUpdate(anyInt(), anyInt(), anyLong(), anyLong()); jcache.get(KEY_1); verify(expiry).expireAfterRead(anyInt(), anyInt(), anyLong(), anyLong()); }
@BeforeEach void getPageCursor() throws IOException { PageCache mockedPageCache = mock( PageCache.class ); PagedFile mockedPagedFile = mock( PagedFile.class ); PageCursor mockedCursor = mock( PageCursor.class ); when( mockedPagedFile.io( anyLong(), anyInt() ) ).thenReturn( mockedCursor ); when( mockedPageCache.map( any( File.class ), anyInt(), any() ) ).thenReturn( mockedPagedFile ); pageCache = new AccessCheckingPageCache( mockedPageCache ); PagedFile file = pageCache.map( new File( "some file" ), 512 ); cursor = file.io( 0, PagedFile.PF_SHARED_READ_LOCK ); }
@Test public void shouldNotUpdateIndexesOnChangedIrrelevantLabel() { // WHEN indexTxUpdater.onLabelChange( unIndexedLabelId, node, propertyCursor, ADDED_LABEL ); indexTxUpdater.onLabelChange( unIndexedLabelId, node, propertyCursor, REMOVED_LABEL ); // THEN verify( txState, never() ).indexDoUpdateEntry( any(), anyInt(), any(), any() ); }
@Test public void shouldLookUpTheIndexByLabelIdAndPropertyKeyId() throws ProcedureException, SchemaRuleNotFoundException { IndexDescriptor index = TestIndexDescriptorFactory.forLabel( 0, 0 ); when( tokenRead.nodeLabel( anyString() ) ).thenReturn( 123 ); when( tokenRead.propertyKey( anyString() ) ).thenReturn( 456 ); when( schemaRead.index( anyInt(), any() ) ).thenReturn( index ); procedure.resampleIndex( ":Person(name)" ); verify( schemaRead ).index( 123, 456 ); }
@Test void shouldEncodeIgnoredMessage() throws Throwable { // Given Neo4jPack.Packer packer = mock( Neo4jPack.Packer.class ); IgnoredMessageEncoder encoder = new IgnoredMessageEncoder(); // When encoder.encode( packer, IGNORED_MESSAGE ); // Then verify( packer ).packStructHeader( anyInt(), eq( IgnoredMessage.SIGNATURE ) ); } }
@Test public void testOnePortAndSearchArchivedIsTrueAndFileOffsetIs1AndByteOffsetIs100() throws IOException { LogviewerLogSearchHandler handler = getStubbedSearchHandler(); handler.deepSearchLogsForTopology("", null, "search", "20", "6700", "1", "100", true, null, null); verify(handler, times(1)).findNMatches(anyList(), anyInt(), anyInt(), anyInt(), anyString()); verify(handler, times(2)).logsForPort(isNull(), any(File.class)); }
@Before public void setup() throws PropertyKeyIdNotFoundKernelException { when( transaction.tokenRead() ).thenReturn( tokenRead ); when( bridge.get() ).thenReturn( stmt ); when( tokenRead.propertyKeyName( anyInt() ) ).thenAnswer( invocationOnMock -> { int id = invocationOnMock.getArgument( 0 ); return ops.propertyKeyTokenHolder().getTokenById( id ).name(); } ); }
@Test public void shouldLookUpTheIndexByLabelIdAndPropertyKeyId() throws ProcedureException, IndexNotFoundKernelException { when( tokenRead.nodeLabel( anyString() ) ).thenReturn( descriptor.getLabelId() ); when( tokenRead.propertyKey( anyString() ) ).thenReturn( descriptor.getPropertyId() ); when( schemaRead.index( anyInt(), any() ) ).thenReturn( anyIndex ); when( schemaRead.indexGetState( any( IndexReference.class ) ) ).thenReturn( ONLINE ); procedure.awaitIndexByPattern( ":Person(name)", TIMEOUT, TIME_UNIT ); verify( schemaRead ).index( descriptor.getLabelId(), descriptor.getPropertyId() ); }
private TxStateTransactionDataSnapshot snapshot() { EmbeddedProxySPI spi = mock( EmbeddedProxySPI.class ); when( spi.newNodeProxy( anyLong() ) ).thenAnswer( invocation -> new NodeProxy( spi, invocation.getArgument( 0 ) ) ); when( spi.newRelationshipProxy( anyLong() ) ).thenAnswer( invocation -> new RelationshipProxy( spi, invocation.getArgument( 0 ) ) ); when( spi.newRelationshipProxy( anyLong(), anyLong(), anyInt(), anyLong() ) ).thenAnswer( invocation -> new RelationshipProxy( spi, invocation.getArgument( 0 ), invocation.getArgument( 1 ), invocation.getArgument( 2 ), invocation.getArgument( 3 ) ) ); return new TxStateTransactionDataSnapshot( state, spi, ops, transaction ); } }
@Test public void shouldTriggerResampling() throws SchemaRuleNotFoundException, ProcedureException, IndexNotFoundKernelException { IndexDescriptor index = TestIndexDescriptorFactory.forLabel( 123, 456 ); when( schemaRead.index( anyInt(), any() ) ).thenReturn( index ); procedure.resampleIndex( ":Person(name)" ); verify( indexingService ).triggerIndexSampling( index.schema(), IndexSamplingMode.TRIGGER_REBUILD_ALL ); } }
@BeforeEach void setUpPagedFile() throws IOException { cursor = new PageAwareByteArrayCursor( PAGE_SIZE ); when( pagedFile.io( anyLong(), anyInt() ) ).thenAnswer( invocation -> cursor.duplicate( invocation.getArgument( 0 ) ) ); freelist.initialize( BASE_ID + 1, BASE_ID + 1, BASE_ID + 1, 0, 0 ); }
@Test public void shouldNotUpdateIndexesOnChangedIrrelevantProperty() { // WHEN indexTxUpdater.onPropertyAdd( node, propertyCursor, unIndexedPropId, Values.of( "whAt" ) ); indexTxUpdater.onPropertyRemove( node, propertyCursor, unIndexedPropId, Values.of( "whAt" ) ); indexTxUpdater.onPropertyChange( node, propertyCursor, unIndexedPropId, Values.of( "whAt" ), Values.of( "whAt2" ) ); // THEN verify( txState, never() ).indexDoUpdateEntry( any(), anyInt(), any(), any() ); }
@Before public void setup() throws IOException, EntityNotFoundException { indexProvider = providerCreator.apply( this ); rules.fileSystem().mkdirs( indexProvider.directoryStructure().rootDirectory() ); populator = indexProvider.getPopulator( descriptor, samplingConfig ); when( nodePropertyAccessor.getNodePropertyValue( anyLong(), anyInt() ) ).thenThrow( UnsupportedOperationException.class ); prevAccessCheck = UnsafeUtil.exchangeNativeAccessCheckEnabled( false ); }