public long nextLong( long origin, long bound ) { return nextLong( (bound - origin) + 1L ) + origin; }
public long nextLong( long n ) { return Math.abs( nextLong() ) % n; }
@Test public void writeAndReadLastTxInformation() throws IOException { StoreMigrator migrator = newStoreMigrator(); TransactionId writtenTxId = new TransactionId( random.nextLong(), random.nextLong(), random.nextLong() ); migrator.writeLastTxInformation( directory.databaseLayout(), writtenTxId ); TransactionId readTxId = migrator.readLastTxInformation( directory.databaseLayout() ); assertEquals( writtenTxId, readTxId ); }
private void updateOldNodes( LongStream idRange ) { try ( Transaction transaction = database.beginTx() ) { List<Node> nodes = idRange.mapToObj( id -> database.getNodeById( id ) ).collect( Collectors.toList() ); for ( int i = 0; i < NUMBER_OF_INDEXES; i++ ) { String propertyName = PROPERTY_PREFIX + i; nodes.forEach( node -> node.setProperty( propertyName, randomRule.nextLong() ) ); } transaction.success(); } }
@Override public void run() { for ( int o = 0; o < LAPS; o++ ) { for ( long i = contestant; i < COUNT; i += CONTESTANTS ) { long value = random.nextLong(); array.set( i, value ); assertEquals( value, array.get( i ) ); } } } }
@Test public void writeAndReadLastTxLogPosition() throws IOException { StoreMigrator migrator = newStoreMigrator(); LogPosition writtenLogPosition = new LogPosition( random.nextLong(), random.nextLong() ); migrator.writeLastTxLogPosition( directory.databaseLayout(), writtenLogPosition ); LogPosition readLogPosition = migrator.readLastTxLogPosition( directory.databaseLayout() ); assertEquals( writtenLogPosition, readLogPosition ); }
private void remove( int count, ValuesMap actualMap, MutableLongObjectMap<Value> expectedMap ) { for ( int i = 0; i < count / 2; i++ ) { final long key = rnd.nextLong( count ); final Value value = rnd.randomValues().nextValue(); actualMap.put( key, value ); expectedMap.put( key, value ); } }
private void put( int count, ValuesMap actualMap, MutableLongObjectMap<Value> expectedMap ) { for ( int i = 0; i < count * 2; i++ ) { final long key = rnd.nextLong( count ); final Value value = rnd.randomValues().nextValue(); actualMap.put( key, value ); expectedMap.put( key, value ); } }
@Test public void modifierMustOverwriteWithOverwriteMerger() throws Exception { // given initialize(); KEY key = key( random.nextLong() ); VALUE firstValue = value( random.nextLong() ); insert( key, firstValue ); // when generationManager.checkpoint(); VALUE secondValue = value( random.nextLong() ); insert( key, secondValue, ValueMergers.overwrite() ); // then goTo( readCursor, rootId ); assertThat( keyCount(), is( 1 ) ); assertEqualsValue( valueAt( 0 ), secondValue ); }
@Test public void shouldStoreAndLoadLongs() { // given try ( LongCollisionValues values = new LongCollisionValues( factory, 100 ) ) { // when long[] offsets = new long[100]; long[] longs = new long[offsets.length]; for ( int i = 0; i < offsets.length; i++ ) { long value = random.nextLong( Long.MAX_VALUE ); offsets[i] = values.add( value ); longs[i] = value; } // then for ( int i = 0; i < offsets.length; i++ ) { assertEquals( longs[i], (long) values.get( offsets[i] ) ); } } } }
@Test public void modifierMustKeepExistingWithKeepExistingMerger() throws Exception { // given initialize(); KEY key = key( random.nextLong() ); VALUE firstValue = value( random.nextLong() ); insert( key, firstValue, ValueMergers.keepExisting() ); goTo( readCursor, rootId ); assertThat( keyCount(), is( 1 ) ); VALUE actual = valueAt( 0 ); assertEqualsValue( actual, firstValue ); // when generationManager.checkpoint(); VALUE secondValue = value( random.nextLong() ); insert( key, secondValue, ValueMergers.keepExisting() ); // then goTo( readCursor, rootId ); assertThat( keyCount(), is( 1 ) ); actual = valueAt( 0 ); assertEqualsValue( actual, firstValue ); }
Groups groups = new Groups(); IdGroupDistribution groupDistribution = new IdGroupDistribution( NODE_COUNT, NUMBER_OF_ID_GROUPS, random.random(), groups ); long nodeRandomSeed = random.nextLong(); long relationshipRandomSeed = random.nextLong(); JobScheduler jobScheduler = new ThreadPoolJobScheduler(); final BatchImporter inserter = new ParallelBatchImporter( databaseLayout,
private ImmutableLongList generateKeyCollisions( int n ) { final long seed = rnd.nextLong(); final MutableLongList elements; try ( LinearProbeLongLongHashMap s = new LinearProbeLongLongHashMap( memoryAllocator ) ) { long v = s.hashAndMask( seed ); while ( s.hashAndMask( v ) != 0 || v == 0 || v == 1 ) { ++v; } final int h = s.hashAndMask( v ); elements = LongLists.mutable.with( v ); while ( elements.size() < n ) { ++v; if ( s.hashAndMask( v ) == h ) { elements.add( v ); } } } return elements.toImmutable(); }
private ImmutableLongList generateCollisions( int n ) { final long seed = rnd.nextLong(); final MutableLongList elements; try ( MutableLinearProbeLongHashSet s = new MutableLinearProbeLongHashSet( memoryAllocator ) ) { long v = s.hashAndMask( seed ); while ( s.hashAndMask( v ) != 0 || v == 0 || v == 1 ) { ++v; } final int h = s.hashAndMask( v ); elements = LongLists.mutable.with( v ); while ( elements.size() < n ) { ++v; if ( s.hashAndMask( v ) == h ) { elements.add( v ); } } } return elements.toImmutable(); }
@Test void randomizedTest() { final int count = 10000 + rnd.nextInt( 1000 ); final MutableLongSet uniqueValues = new LongHashSet(); while ( uniqueValues.size() < count ) { uniqueValues.add( rnd.nextLong() ); } final long[] values = uniqueValues.toArray(); for ( long v : values ) { assertTrue( set.add( v ) ); } shuffle( values ); for ( long v : values ) { assertTrue( set.contains( v ) ); assertFalse( set.add( v ) ); } assertTrue( set.containsAll( values ) ); final long[] toRemove = uniqueValues.select( v -> rnd.nextInt( 100 ) < 75 ).toArray(); shuffle( toRemove ); for ( long v : toRemove ) { assertTrue( set.remove( v ) ); assertFalse( set.contains( v ) ); } assertEquals( count - toRemove.length, set.size() ); }
public long nextLong( long origin, long bound ) { return nextLong( (bound - origin) + 1L ) + origin; }
public long nextLong( long n ) { return Math.abs( nextLong() ) % n; }