@Test void resetFlagShouldRecoverIfToggledAgain() { // Given DecayingFlags.Key featureA = new DecayingFlags.Key( 9 ); DecayingFlags set = new DecayingFlags( 2 ); set.flag( featureA ); // When set.sweep(); // Then assertEquals( "0000", set.asHex() ); // When set.flag( featureA ); // Then assertEquals( "0040", set.asHex() ); } }
public String asHex() { // Convert the flags to a byte-array, each // flag represented as a single bit. byte[] bits = new byte[flags.length / 8]; // Go over the flags, eight at a time to align // with sticking eight bits at a time into the // output array. for ( int i = 0; i < flags.length; i += 8 ) { bits[i / 8] = (byte)( (bit( i ) << 7) | (bit( i + 1 ) << 6) | (bit( i + 2 ) << 5) | (bit( i + 3 ) << 4) | (bit( i + 4 ) << 3) | (bit( i + 5 ) << 2) | (bit( i + 6 ) << 1) | (bit( i + 7 )) ) ; } return HexString.encodeHexString( bits ); }
public void flag( Key key ) { // We dynamically size this up as needed if ( key.index >= flags.length ) { resize( key.index ); } int flag = flags[key.index]; if ( flag < keepalive ) { flags[key.index] = flag + 1; } }
@Test void shouldTrackMultipleFlags() { // Given DecayingFlags.Key featureA = new DecayingFlags.Key( 1 ); DecayingFlags.Key featureB = new DecayingFlags.Key( 3 ); DecayingFlags set = new DecayingFlags( 2 ); // When set.flag( featureA ); set.flag( featureA ); set.flag( featureB ); // Then assertEquals( "5000", set.asHex() ); }
@POST public Response performBatchOperations( @Context UriInfo uriInfo, @Context HttpHeaders httpHeaders, @Context HttpServletRequest req, InputStream body ) { usage.get( features ).flag( http_batch_endpoint ); if ( isStreaming( httpHeaders ) ) { return batchProcessAndStream( uriInfo, httpHeaders, req, body ); } return batchProcess( uriInfo, httpHeaders, req, body ); }
@Override public Map<String,String> getUdcParams() { String classPath = getClassPath(); Map<String,String> udcFields = new HashMap<>(); add( udcFields, ID, storeId ); add( udcFields, VERSION, filterVersionForUDC( usageData.get( UsageDataKeys.version ) ) ); add( udcFields, REVISION, filterVersionForUDC( usageData.get( UsageDataKeys.revision ) ) ); add( udcFields, EDITION, usageData.get( UsageDataKeys.edition ).name().toLowerCase() ); add( udcFields, SOURCE, config.get( UdcSettings.udc_source ) ); add( udcFields, REGISTRATION, config.get( UdcSettings.udc_registration_key ) ); add( udcFields, DATABASE_MODE, usageData.get( UsageDataKeys.operationalMode ).name() ); add( udcFields, SERVER_ID, usageData.get( UsageDataKeys.serverId ) ); add( udcFields, USER_AGENTS, toCommaString( usageData.get( UsageDataKeys.clientNames ) ) ); add( udcFields, TAGS, determineTags( jarNamesForTags, classPath ) ); add( udcFields, CLUSTER_HASH, determineClusterNameHash() ); add( udcFields, MAC, determineMacAddress() ); add( udcFields, DISTRIBUTION, determineOsDistribution() ); add( udcFields, NUM_PROCESSORS, determineNumberOfProcessors() ); add( udcFields, TOTAL_MEMORY, determineTotalMemory() ); add( udcFields, HEAP_SIZE, determineHeapSize() ); add( udcFields, NODE_IDS_IN_USE, determineNodesIdsInUse() ); add( udcFields, RELATIONSHIP_IDS_IN_USE, determineRelationshipIdsInUse() ); add( udcFields, LABEL_IDS_IN_USE, determineLabelIdsInUse() ); add( udcFields, PROPERTY_IDS_IN_USE, determinePropertyIdsInUse() ); add( udcFields, FEATURES, usageData.get( UsageDataKeys.features ).asHex() ); addStoreFileSizes( udcFields ); udcFields.putAll( determineSystemProperties() ); return udcFields; }
@Test void shouldTrackToggle() { // Given DecayingFlags.Key myFeature = new DecayingFlags.Key( 1 ); DecayingFlags set = new DecayingFlags( 1 ); // When set.flag( myFeature ); // Then assertEquals( "4000", set.asHex() ); }
@POST @Consumes( {MediaType.APPLICATION_JSON} ) @Produces( {MediaType.APPLICATION_JSON} ) public Response executeStatementsInNewTransaction( final InputStream input, @Context final UriInfo uriInfo, @Context final HttpServletRequest request ) { usage.get( features ).flag( http_tx_endpoint ); LoginContext loginContext = AuthorizedRequestWrapper.getLoginContextFromHttpServletRequest( request ); long customTransactionTimeout = HttpHeaderUtils.getTransactionTimeout( request, log ); TransactionHandle transactionHandle = facade.newTransactionHandle( uriScheme, false, loginContext, customTransactionTimeout ); return createdResponse( transactionHandle, executeStatements( input, transactionHandle, uriInfo.getBaseUri(), request ) ); }
@Override public Map<String,String> getUdcParams() { String classPath = getClassPath(); Map<String,String> udcFields = new HashMap<>(); add( udcFields, ID, storeId ); add( udcFields, VERSION, filterVersionForUDC( usageData.get( UsageDataKeys.version ) ) ); add( udcFields, REVISION, filterVersionForUDC( usageData.get( UsageDataKeys.revision ) ) ); add( udcFields, EDITION, usageData.get( UsageDataKeys.edition ).name().toLowerCase() ); add( udcFields, SOURCE, config.get( UdcSettings.udc_source ) ); add( udcFields, REGISTRATION, config.get( UdcSettings.udc_registration_key ) ); add( udcFields, DATABASE_MODE, usageData.get( UsageDataKeys.operationalMode ).name() ); add( udcFields, SERVER_ID, usageData.get( UsageDataKeys.serverId ) ); add( udcFields, USER_AGENTS, toCommaString( usageData.get( UsageDataKeys.clientNames ) ) ); add( udcFields, TAGS, determineTags( jarNamesForTags, classPath ) ); add( udcFields, CLUSTER_HASH, determineClusterNameHash() ); add( udcFields, MAC, determineMacAddress() ); add( udcFields, DISTRIBUTION, determineOsDistribution() ); add( udcFields, NUM_PROCESSORS, determineNumberOfProcessors() ); add( udcFields, TOTAL_MEMORY, determineTotalMemory() ); add( udcFields, HEAP_SIZE, determineHeapSize() ); add( udcFields, NODE_IDS_IN_USE, determineNodesIdsInUse() ); add( udcFields, RELATIONSHIP_IDS_IN_USE, determineRelationshipIdsInUse() ); add( udcFields, LABEL_IDS_IN_USE, determineLabelIdsInUse() ); add( udcFields, PROPERTY_IDS_IN_USE, determinePropertyIdsInUse() ); add( udcFields, FEATURES, usageData.get( UsageDataKeys.features ).asHex() ); addStoreFileSizes( udcFields ); udcFields.putAll( determineSystemProperties() ); return udcFields; }
@Test void toggleShouldDecay() { // Given DecayingFlags.Key featureA = new DecayingFlags.Key( 1 ); DecayingFlags.Key featureB = new DecayingFlags.Key( 3 ); DecayingFlags set = new DecayingFlags( 2 ); // And given Feature A has been used quite a bit, while // feature B is not quite as popular.. set.flag( featureA ); set.flag( featureA ); set.flag( featureB ); // When set.sweep(); // Then assertEquals( "4000", set.asHex() ); // When set.sweep(); // Then assertEquals( "0000", set.asHex() ); }
@Test void shouldIncludePopularFeatures() { // Given usageData.get( UsageDataKeys.features ).flag( bolt ); // When & Then assertEquals( "1000", collector.getUdcParams().get( UdcConstants.FEATURES ) ); }
public void flag( Key key ) { // We dynamically size this up as needed if ( key.index >= flags.length ) { resize( key.index ); } int flag = flags[key.index]; if ( flag < keepalive ) { flags[key.index] = flag + 1; } }
public String asHex() { // Convert the flags to a byte-array, each // flag represented as a single bit. byte[] bits = new byte[flags.length / 8]; // Go over the flags, eight at a time to align // with sticking eight bits at a time into the // output array. for ( int i = 0; i < flags.length; i += 8 ) { bits[i / 8] = (byte)( (bit( i ) << 7) | (bit( i + 1 ) << 6) | (bit( i + 2 ) << 5) | (bit( i + 3 ) << 4) | (bit( i + 4 ) << 3) | (bit( i + 5 ) << 2) | (bit( i + 6 ) << 1) | (bit( i + 7 )) ) ; } return HexString.encodeHexString( bits ); }
usage.get( features ).flag( http_cypher_endpoint ); Map<String,Object> command = input.readMap( body );
@POST public Response performBatchOperations( @Context UriInfo uriInfo, @Context HttpHeaders httpHeaders, @Context HttpServletRequest req, InputStream body ) { usage.get( features ).flag( http_batch_endpoint ); if ( isStreaming( httpHeaders ) ) { return batchProcessAndStream( uriInfo, httpHeaders, req, body ); } return batchProcess( uriInfo, httpHeaders, req, body ); }
@POST @Consumes( {MediaType.APPLICATION_JSON} ) @Produces( {MediaType.APPLICATION_JSON} ) public Response executeStatementsInNewTransaction( final InputStream input, @Context final UriInfo uriInfo, @Context final HttpServletRequest request ) { usage.get( features ).flag( http_tx_endpoint ); LoginContext loginContext = AuthorizedRequestWrapper.getLoginContextFromHttpServletRequest( request ); long customTransactionTimeout = HttpHeaderUtils.getTransactionTimeout( request, log ); TransactionHandle transactionHandle = facade.newTransactionHandle( uriScheme, false, loginContext, customTransactionTimeout ); return createdResponse( transactionHandle, executeStatements( input, transactionHandle, uriInfo.getBaseUri(), request ) ); }
usage.get( features ).flag( http_cypher_endpoint ); Map<String,Object> command = input.readMap( body );