@Test void shouldNotCloseDuringIteration() { // Given ResourceIterator<Long> it1 = spy( asResourceIterator( iterator( 1L, 2L, 3L ) ) ); ResourceIterator<Long> it2 = spy( asResourceIterator( iterator( 5L, 6L, 7L ) ) ); CombiningResourceIterator<Long> combingIterator = new CombiningResourceIterator<>( iterator(it1, it2) ); // When I iterate through it, things come back in the right order assertThat( Iterators.asList( combingIterator ), equalTo(asList( 1L, 2L, 3L, 5L, 6L, 7L )) ); // Then verify(it1, never()).close(); verify(it2, never()).close(); }
private static void addToResults( GraphDatabaseService db, HashMap<TestValue, Set<Object>> results, TestValue value ) { ResourceIterator<Node> foundNodes = db.findNodes( label( LABEL ), PROPERTY_KEY, value.value ); Set<Object> propertyValues = asSet( Iterators.map( PROPERTY_EXTRACTOR, foundNodes ) ); results.put( value, propertyValues ); }
/** * @return store files, namely the single "neostore.labelscanstore.db" store file. */ @Override public ResourceIterator<File> snapshotStoreFiles() { return asResourceIterator( iterator( storeFile ) ); }
private Iterable<CommonAbstractStore> instantiatedRecordStores() { Iterator<StoreType> storeTypes = new FilteringIterator<>( iterator( STORE_TYPES ), INSTANTIATED_RECORD_STORES ); return loop( new IteratorWrapper<CommonAbstractStore,StoreType>( storeTypes ) { @Override protected CommonAbstractStore underlyingObjectToObject( StoreType type ) { return (CommonAbstractStore) stores[type.ordinal()]; } } ); }
private void addDefinitions( List<IndexDefinition> definitions, final TokenRead tokenRead, Iterator<IndexReference> indexes ) { addToCollection( map( index -> descriptorToDefinition( tokenRead, index ), indexes ), definitions ); }
private SchemaRead schemaWithIndexes( IndexReference... indexes ) { final SchemaRead schemaRead = mock( SchemaRead.class ); when( schemaRead.indexesGetAll() ).thenReturn( Iterators.iterator( indexes ) ); return schemaRead; }
@Before public void setup() throws Throwable { jmxServer = mock( MBeanServer.class ); beanName = new ObjectName( "org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference" ); attributeName = "name"; when( jmxServer.queryNames( new ObjectName( "*:*" ), null ) ) .thenReturn( asSet( beanName ) ); when( jmxServer.getMBeanInfo( beanName ) ) .thenReturn( new MBeanInfo( "org.neo4j.SomeMBean", "This is a description", new MBeanAttributeInfo[]{ new MBeanAttributeInfo( attributeName, "someType", "This is the attribute desc.", true, false, false ) }, null, null, null ) ); } }
private static ResourceIterator<File> scanStoreFilesAre( LabelScanStore labelScanStore, String[] fileNames ) { ArrayList<File> files = new ArrayList<>(); mockFiles( fileNames, files, false ); ResourceIterator<File> snapshot = spy( asResourceIterator( files.iterator() ) ); when( labelScanStore.snapshotStoreFiles() ).thenReturn( snapshot ); return snapshot; }
@Test public void shouldThrowExceptionOnNodeDuplicateRuleFound() throws DuplicateSchemaRuleException, SchemaRuleNotFoundException { // GIVEN TokenNameLookup tokenNameLookup = getDefaultTokenNameLookup(); SchemaStorage schemaStorageSpy = Mockito.spy( storage ); Mockito.when( schemaStorageSpy.loadAllSchemaRules( any(), any(), anyBoolean() ) ).thenReturn( Iterators.iterator( getUniquePropertyConstraintRule( 1L, LABEL1, PROP1 ), getUniquePropertyConstraintRule( 2L, LABEL1, PROP1 ) ) ); //EXPECT expectedException.expect( DuplicateSchemaRuleException.class ); expectedException.expect( new KernelExceptionUserMessageMatcher( tokenNameLookup, "Multiple uniqueness constraints found for :Label1(prop1)." ) ); // WHEN schemaStorageSpy.constraintsGetSingle( ConstraintDescriptorFactory.uniqueForLabel( labelId( LABEL1 ), propId( PROP1 ) ) ); }
@Test public void shouldHandleBasicMBean() throws Throwable { // given when( jmxServer.getAttribute( beanName, "name" ) ).thenReturn( "Hello, world!" ); JmxQueryProcedure procedure = new JmxQueryProcedure( ProcedureSignature.procedureName( "bob" ), jmxServer ); // when RawIterator<Object[],ProcedureException> result = procedure.apply( null, new Object[]{"*:*"}, resourceTracker ); // then assertThat( asList( result ), contains( equalTo( new Object[]{ "org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference", "This is a description", map( attributeName, map( "description", "This is the attribute desc.", "value", "Hello, world!" ) ) } ) ) ); }
@Test public void shouldAcquireSchemaReadLockLazilyBeforeGettingAllConstraints() { // given int labelId = 1; int relTypeId = 2; UniquenessConstraintDescriptor uniquenessConstraint = uniqueForLabel( labelId, 2, 3, 3 ); RelExistenceConstraintDescriptor existenceConstraint = existsForRelType( relTypeId, 3, 4, 5 ); when( storageReader.constraintsGetAll() ) .thenReturn( Iterators.iterator( uniquenessConstraint, existenceConstraint ) ); // when Iterator<ConstraintDescriptor> result = allStoreHolder.constraintsGetAll( ); Iterators.count( result ); // then assertThat( asList( result ), empty() ); order.verify( storageReader ).constraintsGetAll(); order.verify( locks ).acquireShared( LockTracer.NONE, ResourceTypes.LABEL, labelId ); order.verify( locks ).acquireShared( LockTracer.NONE, ResourceTypes.RELATIONSHIP_TYPE, relTypeId ); }
StoreIndexDescriptor... rules ) throws IOException when( indexProvider.getInitialState( any( StoreIndexDescriptor.class ) ) ).thenReturn( ONLINE ); when( indexProvider.getProviderDescriptor() ).thenReturn( PROVIDER_DESCRIPTOR ); when( indexProvider.getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ) .thenReturn( populator ); data.getsProcessedByStoreScanFrom( storeView ); when( indexProvider.getOnlineAccessor( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ) storeView, nameLookup, loop( iterator( rules ) ), internalLogProvider, userLogProvider,
private List<Object[]> call( String name, Object... args ) throws ProcedureException, IndexNotFoundKernelException { BasicContext ctx = new BasicContext(); ctx.put( KERNEL_TRANSACTION, tx ); ctx.put( DEPENDENCY_RESOLVER, resolver ); ctx.put( GRAPHDATABASEAPI, graphDatabaseAPI ); ctx.put( SECURITY_CONTEXT, SecurityContext.AUTH_DISABLED ); ctx.put( LOG, log ); when( graphDatabaseAPI.getDependencyResolver() ).thenReturn( resolver ); when( resolver.resolveDependency( Procedures.class ) ).thenReturn( procs ); when( resolver.resolveDependency( IndexingService.class ) ).thenReturn( indexingService ); when( schemaRead.indexGetPopulationProgress( any( IndexReference.class) ) ).thenReturn( PopulationProgress.DONE ); return Iterators.asList( procs.callProcedure( ctx, ProcedureSignature.procedureName( name.split( "\\." ) ), args, resourceTracker ) ); } }
@Test public void shouldHandleMBeanThatThrowsOnGetAttribute() throws Throwable { // given some JVM MBeans do not allow accessing their attributes, despite marking // then as readable when( jmxServer.getAttribute( beanName, "name" ) ) // We throw the exact combo thrown by JVM MBeans here, so that any other exception will bubble up, // and we can make an informed decision about swallowing more exception on an as-needed basis. .thenThrow( new RuntimeMBeanException( new UnsupportedOperationException( "Haha, screw discoverable services!" ) ) ); JmxQueryProcedure procedure = new JmxQueryProcedure( ProcedureSignature.procedureName( "bob" ), jmxServer ); // when RawIterator<Object[],ProcedureException> result = procedure.apply( null, new Object[]{"*:*"}, resourceTracker ); // then assertThat( asList( result ), contains( equalTo( new Object[]{ "org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference", "This is a description", map( attributeName, map( "description", "This is the attribute desc.", "value", null ) ) } ) ) ); }
@Test public void shouldScanExistingNodesForALabel() throws Exception { // given EntityUpdateCollectingVisitor visitor = new EntityUpdateCollectingVisitor(); @SuppressWarnings( "unchecked" ) Visitor<NodeLabelUpdate,Exception> labelVisitor = mock( Visitor.class ); StoreScan<Exception> storeScan = storeView.visitNodes( new int[]{labelId}, id -> id == propertyKeyId, visitor, labelVisitor, false ); // when storeScan.run(); // then assertEquals( asSet( add( alistair.getId(), propertyKeyId, "Alistair", new long[] { labelId } ), add( stefan.getId(), propertyKeyId, "Stefan", new long[] { labelId } ) ), visitor.getUpdates() ); }
@Test void shouldReportOwningNodeRecordNotPointingBack() { // given long nodeId = 12L; Collection<DynamicRecord> validLabelRecords = new ArrayList<>(); DynamicRecord dynamicRecord = inUse( new DynamicRecord( 0 ) ); allocateFromNumbers( validLabelRecords, new long[] {nodeId}, new ReusableRecordsAllocator( 66, dynamicRecord ) ); Collection<DynamicRecord> fakePointedToRecords = new ArrayList<>(); DynamicRecord dynamicRecord1 = inUse( new DynamicRecord( 1 ) ); allocateFromNumbers( fakePointedToRecords, new long[] {nodeId}, new ReusableRecordsAllocator( 66, dynamicRecord1 ) ); NodeRecord nodeRecord = inUse( new NodeRecord( nodeId, false, -1, -1 ) ); nodeRecord.setLabelField( dynamicPointer( fakePointedToRecords ), fakePointedToRecords ); add( nodeRecord ); // when DynamicLabelConsistencyReport report = check( Iterators.single( validLabelRecords.iterator() ) ); // then verify( report ).orphanDynamicLabelRecordDueToInvalidOwner( nodeRecord ); } }
@Test public void testEmptyGraph() throws Throwable { // Given the database is empty // When Procedures procs = procs(); RawIterator<Object[],ProcedureException> stream = procs.procedureCallRead( procs.procedureGet( procedureName( "db", "schema" ) ).id(), new Object[0] ); // Then assertThat( asList( stream ), contains( equalTo( new Object[]{new ArrayList<>(), new ArrayList<>()} ) ) ); commit(); }
@Test public void shouldMatchOnTwoProperties() { // when List<IndexDescriptor> matched = new ArrayList<>(); NodeSchemaMatcher.onMatchingSchema( iterator( index1_2 ), node, new StubPropertyCursor(), unIndexedPropId, ( schema, props ) -> matched.add( schema ) ); // then assertThat( matched, contains( index1_2 ) ); }
@Test void shouldHandleSingleItemIterators() { // Given ResourceIterator<Long> it1 = asResourceIterator( iterator( 1L ) ); ResourceIterator<Long> it2 = asResourceIterator( iterator( 5L, 6L, 7L ) ); CombiningResourceIterator<Long> combingIterator = new CombiningResourceIterator<>( iterator(it1, it2) ); // When I iterate through it, things come back in the right order assertThat( Iterators.asList( combingIterator ), equalTo(asList( 1L, 5L, 6L, 7L )) ); } }