text
stringlengths
30
1.67M
<s> package com . senseidb . indexing . activity ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Map ; import java . util . Set ; import org . json . JSONException ; import org . json . JSONObject ; import com . senseidb . conf . SenseiSchema ; import com . senseidb . conf . SenseiSchema . FieldDefinition ; import com . senseidb . indexing . ShardingStrategy ; import com . senseidb . search . node . SenseiCore ; public class DefaultActivityFilter extends BaseActivityFilter { private volatile HashSet < String > cachedActivities ; @ Override public boolean acceptEventsForAllPartitions ( ) { return false ; } @ Override public ActivityFilteredResult filter ( JSONObject event , SenseiSchema senseiSchema , ShardingStrategy shardingStrategy , SenseiCore senseiCore ) { Map < Long , Map < String , Object > > columnValues = new HashMap < Long , Map < String , Object > > ( ) ; Map < String , Object > innerMap = new HashMap < String , Object > ( ) ; long uid ; try { uid = event . getLong ( senseiSchema . getUidField ( ) ) ; } catch ( JSONException e ) { throw new RuntimeException ( e ) ; } for ( String activityField : getActivities ( senseiSchema ) ) { Object obj = event . opt ( activityField ) ; if ( obj != null ) { event . remove ( activityField ) ; innerMap . put ( activityField , obj ) ; } } columnValues . put ( uid , innerMap ) ; ActivityFilteredResult activityFilteredResult = new ActivityFilteredResult ( event , columnValues ) ; return activityFilteredResult ; } private Set < String > getActivities ( SenseiSchema senseiSchema ) { if ( cachedActivities == null ) { cachedActivities = new HashSet < String > ( ) ; for ( String fieldName : senseiSchema . getFieldDefMap ( ) . keySet ( ) ) { FieldDefinition fieldDefinition = senseiSchema . getFieldDefMap ( ) . get ( fieldName ) ; if ( fieldDefinition . isActivity ) { cachedActivities . add ( fieldName ) ; } } } return cachedActivities ; } } </s>
<s> package com . senseidb . indexing . activity ; import com . senseidb . indexing . activity . primitives . ActivityPrimitivesStorage ; public class ActivityInMemoryFactory extends ActivityPersistenceFactory { protected ActivityInMemoryFactory ( ) { super ( "<STR_LIT>" , new ActivityConfig ( ) ) ; } @ Override public AggregatesMetadata createAggregatesMetadata ( String fieldName ) { return new InMemoryAggregatesMetadata ( ) ; } @ Override public Metadata getMetadata ( ) { return null ; } @ Override public ActivityPrimitivesStorage getActivivityPrimitivesStorage ( String fieldName ) { return null ; } @ Override protected CompositeActivityStorage getCompositeStorage ( ) { return null ; } private static class InMemoryAggregatesMetadata extends AggregatesMetadata { private volatile int currentTime = <NUM_LIT:0> ; public int getLastUpdatedTime ( ) { return currentTime ; } public void updateTime ( int currentTime ) { this . currentTime = currentTime ; } } } </s>
<s> package com . senseidb . indexing . activity . deletion ; import org . apache . lucene . index . IndexReader ; public interface DeletionListener { public void onDelete ( IndexReader indexReader , long ... uids ) ; } </s>
<s> package com . senseidb . indexing . activity . deletion ; import java . io . IOException ; import org . apache . lucene . index . IndexReader ; import org . apache . lucene . search . DocIdSet ; import org . apache . lucene . search . DocIdSetIterator ; import org . apache . lucene . search . Filter ; import proj . zoie . api . ZoieIndexReader ; public class PurgeFilterWrapper extends Filter { private final Filter internal ; private final DeletionListener deletionListener ; public PurgeFilterWrapper ( Filter internal , DeletionListener deletionListener ) { this . internal = internal ; this . deletionListener = deletionListener ; } @ Override public DocIdSet getDocIdSet ( final IndexReader reader ) throws IOException { final ZoieIndexReader zoieIndexReader = ( ZoieIndexReader ) reader ; return new DocIdSet ( ) { public DocIdSetIterator iterator ( ) throws IOException { return new DocIdSetIteratorWrapper ( internal . getDocIdSet ( reader ) . iterator ( ) ) { @ Override protected void handeDoc ( int ret ) { deletionListener . onDelete ( reader , zoieIndexReader . getUID ( ret ) ) ; } } ; } } ; } public abstract static class DocIdSetIteratorWrapper extends DocIdSetIterator { private final DocIdSetIterator iterator ; public DocIdSetIteratorWrapper ( DocIdSetIterator iterator ) { this . iterator = iterator ; } @ Override public int docID ( ) { return iterator . docID ( ) ; } @ Override public int nextDoc ( ) throws IOException { int ret = iterator . nextDoc ( ) ; if ( ret != DocIdSetIterator . NO_MORE_DOCS ) { handeDoc ( ret ) ; } return ret ; } @ Override public int advance ( int target ) throws IOException { int ret = iterator . advance ( target ) ; if ( ret != DocIdSetIterator . NO_MORE_DOCS ) { handeDoc ( ret ) ; } return ret ; } protected abstract void handeDoc ( int ret ) ; } } </s>
<s> package com . senseidb . indexing . activity . deletion ; import java . io . IOException ; import java . util . List ; import org . apache . lucene . index . IndexReader ; import proj . zoie . api . ZoieIndexReader ; import proj . zoie . api . ZoieMultiReader ; import proj . zoie . api . ZoieSegmentReader ; import proj . zoie . impl . indexing . ZoieSystem ; public class HourglassAdapterDeletionAdapter { private final DeletionListener deletionListener ; public HourglassAdapterDeletionAdapter ( DeletionListener deletionListener ) { this . deletionListener = deletionListener ; } public void onZoieInstanceRetire ( ZoieSystem < IndexReader , ? > zoieSystem ) { List < ZoieIndexReader < IndexReader > > indexReaders = null ; try { indexReaders = zoieSystem . getIndexReaders ( ) ; for ( ZoieIndexReader indexReader : indexReaders ) { handleIndexReader ( indexReader ) ; } } catch ( IOException e ) { throw new RuntimeException ( e ) ; } finally { if ( indexReaders != null ) { zoieSystem . returnIndexReaders ( indexReaders ) ; } } } public void handleIndexReader ( ZoieIndexReader indexReader ) { if ( indexReader instanceof ZoieMultiReader ) { ZoieSegmentReader [ ] segments = ( ZoieSegmentReader [ ] ) ( ( ZoieMultiReader ) indexReader ) . getSequentialSubReaders ( ) ; for ( ZoieSegmentReader segmentReader : segments ) { handleSegment ( segmentReader ) ; } } else if ( indexReader instanceof ZoieSegmentReader ) { handleSegment ( ( ZoieSegmentReader ) indexReader ) ; } else { throw new UnsupportedOperationException ( "<STR_LIT>" ) ; } } private void handleSegment ( ZoieSegmentReader segmentReader ) { deletionListener . onDelete ( segmentReader , segmentReader . getUIDArray ( ) ) ; } } </s>
<s> package com . senseidb . indexing . activity . deletion ; import org . apache . lucene . index . IndexReader ; import proj . zoie . impl . indexing . ZoieSystem ; public interface ZoieRetireListener { public void onZoieInstanceRetire ( ZoieSystem < IndexReader , ? > zoieSystem ) ; } </s>
<s> package com . senseidb . indexing . activity ; import java . io . File ; import java . io . IOException ; import org . apache . commons . io . FileUtils ; public class Metadata { public volatile String version ; public volatile int count ; private final String indexDir ; private File file1 ; private File file2 ; public Metadata ( String indexDir ) { super ( ) ; this . indexDir = indexDir ; } public void init ( ) { try { file1 = new File ( indexDir , "<STR_LIT>" ) ; file2 = new File ( indexDir , "<STR_LIT>" ) ; if ( ! file1 . exists ( ) ) { file1 . createNewFile ( ) ; } if ( ! file2 . exists ( ) ) { file2 . createNewFile ( ) ; } else { long modifiedTime1 = file1 . lastModified ( ) ; long modifiedTime2 = file2 . lastModified ( ) ; if ( modifiedTime1 > modifiedTime2 ) { init ( FileUtils . readFileToString ( file2 ) ) ; } else { init ( FileUtils . readFileToString ( file1 ) ) ; } } } catch ( Exception ex ) { throw new RuntimeException ( ex ) ; } } public void update ( String version , int count ) { this . version = version ; this . count = count ; try { FileUtils . writeStringToFile ( file1 , this . toString ( ) ) ; FileUtils . writeStringToFile ( file2 , this . toString ( ) ) ; } catch ( IOException ex ) { throw new RuntimeException ( ex ) ; } } @ Override public String toString ( ) { return version + "<STR_LIT:;>" + count ; } protected void init ( String str ) { if ( ! str . contains ( "<STR_LIT:;>" ) ) { return ; } version = str . split ( "<STR_LIT:;>" ) [ <NUM_LIT:0> ] ; count = Integer . parseInt ( str . split ( "<STR_LIT:;>" ) [ <NUM_LIT:1> ] ) ; } } </s>
<s> package com . senseidb . indexing . activity ; import java . util . ArrayList ; import java . util . List ; public class UpdateBatch < T > { int batchSize = <NUM_LIT> ; protected volatile List < T > updates = new ArrayList < T > ( batchSize ) ; long delay = <NUM_LIT:15> * <NUM_LIT:1000> ; long time = System . currentTimeMillis ( ) ; private UpdateBatch ( ) { } public UpdateBatch ( ActivityConfig activityConfig ) { batchSize = activityConfig . getFlushBufferSize ( ) ; delay = activityConfig . getFlushBufferMaxDelayInSeconds ( ) ; } public boolean addFieldUpdate ( T fieldUpdate ) { updates . add ( fieldUpdate ) ; if ( flushNeeded ( ) ) { return true ; } return false ; } public boolean flushNeeded ( ) { return updates . size ( ) >= batchSize || ( ( System . currentTimeMillis ( ) - time ) > <NUM_LIT:15> * <NUM_LIT:1000> && ! updates . isEmpty ( ) ) ; } public List < T > getUpdates ( ) { return updates ; } } </s>
<s> package com . senseidb . indexing . activity ; import org . apache . commons . configuration . Configuration ; import com . senseidb . plugin . SenseiPluginRegistry ; public class ActivityConfig { private int flushBufferSize = <NUM_LIT> ; private int flushBufferMaxDelayInSeconds = <NUM_LIT:15> ; private int purgeJobFrequencyInSeconds = <NUM_LIT:0> ; private int undeletableBufferSize = <NUM_LIT> ; public ActivityConfig ( SenseiPluginRegistry pluginRegistry ) { flushBufferSize = getInt ( pluginRegistry . getConfiguration ( ) , "<STR_LIT>" , <NUM_LIT> ) ; flushBufferMaxDelayInSeconds = getInt ( pluginRegistry . getConfiguration ( ) , "<STR_LIT>" , <NUM_LIT:15> ) ; purgeJobFrequencyInSeconds = getInt ( pluginRegistry . getConfiguration ( ) , "<STR_LIT>" , <NUM_LIT:0> ) ; undeletableBufferSize = getInt ( pluginRegistry . getConfiguration ( ) , "<STR_LIT>" , <NUM_LIT> ) ; } public ActivityConfig ( ) { } private static int getInt ( Configuration configuration , String key , int defaultValue ) { String compoundKey = "<STR_LIT>" + key ; return configuration . getInt ( compoundKey , defaultValue ) ; } public int getFlushBufferSize ( ) { return flushBufferSize ; } public int getFlushBufferMaxDelayInSeconds ( ) { return flushBufferMaxDelayInSeconds ; } public int getPurgeJobFrequencyInMinutes ( ) { return purgeJobFrequencyInSeconds ; } public int getUndeletableBufferSize ( ) { return undeletableBufferSize ; } } </s>
<s> package com . senseidb . indexing . activity ; import com . senseidb . metrics . MetricFactory ; import java . io . File ; import java . io . IOException ; import java . io . RandomAccessFile ; import java . nio . MappedByteBuffer ; import java . nio . channels . FileChannel . MapMode ; import java . util . List ; import java . util . concurrent . Callable ; import java . util . concurrent . TimeUnit ; import org . apache . log4j . Logger ; import org . springframework . util . Assert ; import com . senseidb . indexing . activity . primitives . ActivityPrimitivesStorage ; import com . senseidb . metrics . MetricsConstants ; import com . yammer . metrics . core . MetricName ; import com . yammer . metrics . core . Timer ; public class CompositeActivityStorage { private static final int BYTES_IN_LONG = <NUM_LIT:8> ; private static Logger logger = Logger . getLogger ( CompositeActivityStorage . class ) ; private RandomAccessFile storedFile ; private final String indexDir ; private volatile boolean closed = false ; private MappedByteBuffer buffer ; private long fileLength ; private boolean activateMemoryMappedBuffers = false ; private final Timer timer ; public CompositeActivityStorage ( String indexDir ) { this . indexDir = indexDir ; timer = MetricFactory . newTimer ( new MetricName ( MetricsConstants . Domain , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , TimeUnit . MILLISECONDS , TimeUnit . SECONDS ) ; } public synchronized void init ( ) { try { File dir = new File ( indexDir ) ; if ( ! dir . exists ( ) ) { dir . mkdirs ( ) ; } File file = new File ( dir , "<STR_LIT>" ) ; if ( ! file . exists ( ) ) { file . createNewFile ( ) ; } storedFile = new RandomAccessFile ( file , "<STR_LIT>" ) ; fileLength = storedFile . length ( ) ; if ( activateMemoryMappedBuffers ) { buffer = storedFile . getChannel ( ) . map ( MapMode . READ_WRITE , <NUM_LIT:0> , file . length ( ) ) ; } } catch ( IOException e ) { logger . error ( e . getMessage ( ) , e ) ; throw new RuntimeException ( e ) ; } } public synchronized void flush ( List < Update > updates ) { Assert . state ( storedFile != null , "<STR_LIT>" ) ; try { for ( Update update : updates ) { ensureCapacity ( update . index * BYTES_IN_LONG + BYTES_IN_LONG ) ; if ( activateMemoryMappedBuffers ) { buffer . putLong ( update . index * BYTES_IN_LONG , update . value ) ; } else { storedFile . seek ( update . index * BYTES_IN_LONG ) ; storedFile . writeLong ( update . value ) ; } } if ( activateMemoryMappedBuffers ) { buffer . force ( ) ; } storedFile . getFD ( ) . sync ( ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } private void ensureCapacity ( int i ) { try { if ( fileLength > i + <NUM_LIT:100> ) { return ; } if ( fileLength > ActivityPrimitivesStorage . LENGTH_THRESHOLD ) { fileLength = fileLength * ActivityPrimitivesStorage . FILE_GROWTH_RATIO ; } else { fileLength = ActivityPrimitivesStorage . INITIAL_FILE_LENGTH ; } storedFile . setLength ( fileLength ) ; if ( activateMemoryMappedBuffers ) { buffer = storedFile . getChannel ( ) . map ( MapMode . READ_WRITE , <NUM_LIT:0> , fileLength ) ; } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } public synchronized void close ( ) { try { if ( activateMemoryMappedBuffers ) { buffer . force ( ) ; } storedFile . close ( ) ; closed = true ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } public void decorateCompositeActivityValues ( final CompositeActivityValues activityValues , final Metadata metadata ) { try { timer . time ( new Callable < CompositeActivityValues > ( ) { @ Override public CompositeActivityValues call ( ) throws Exception { Assert . state ( storedFile != null , "<STR_LIT>" ) ; activityValues . activityStorage = CompositeActivityStorage . this ; try { if ( metadata . count == <NUM_LIT:0> ) { activityValues . init ( ) ; return activityValues ; } activityValues . init ( ( int ) ( metadata . count * ActivityPrimitivesStorage . INIT_GROWTH_RATIO ) ) ; synchronized ( activityValues . deletedIndexes ) { if ( metadata . count * BYTES_IN_LONG > fileLength ) { logger . warn ( "<STR_LIT>" + ( fileLength / BYTES_IN_LONG ) + "<STR_LIT>" + metadata . count ) ; logger . warn ( "<STR_LIT>" ) ; int newCount = ( int ) ( fileLength / BYTES_IN_LONG ) ; metadata . update ( metadata . version , newCount ) ; } for ( int i = <NUM_LIT:0> ; i < metadata . count ; i ++ ) { long value ; if ( activateMemoryMappedBuffers ) { value = buffer . getLong ( i * BYTES_IN_LONG ) ; } else { storedFile . seek ( i * BYTES_IN_LONG ) ; value = storedFile . readLong ( ) ; } if ( value != Long . MIN_VALUE ) { activityValues . uidToArrayIndex . put ( value , i ) ; } else { activityValues . deletedIndexes . add ( i ) ; } } } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return activityValues ; } } ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } public boolean isClosed ( ) { return closed ; } public static class Update { public int index ; public long value ; public Update ( int index , long value ) { this . index = index ; this . value = value ; } @ Override public String toString ( ) { return "<STR_LIT>" + index + "<STR_LIT>" + value ; } } } </s>
<s> package com . senseidb . indexing . activity ; import java . util . Map ; import org . json . JSONObject ; import com . senseidb . conf . SenseiSchema ; import com . senseidb . indexing . ShardingStrategy ; import com . senseidb . plugin . SenseiPlugin ; import com . senseidb . plugin . SenseiPluginRegistry ; import com . senseidb . search . node . SenseiCore ; import com . senseidb . util . Pair ; public abstract class BaseActivityFilter implements SenseiPlugin { protected Map < String , String > config ; protected SenseiPluginRegistry pluginRegistry ; @ Override public final void init ( Map < String , String > config , SenseiPluginRegistry pluginRegistry ) { this . config = config ; this . pluginRegistry = pluginRegistry ; } public abstract ActivityFilteredResult filter ( JSONObject event , SenseiSchema senseiSchema , ShardingStrategy shardingStrategy , SenseiCore senseiCore ) ; public boolean acceptEventsForAllPartitions ( ) { return false ; } public static class ActivityFilteredResult { private JSONObject filteredObject ; private Map < Long , Map < String , Object > > activityValues ; public ActivityFilteredResult ( JSONObject filteredObject , Map < Long , Map < String , Object > > activityValues ) { super ( ) ; this . filteredObject = filteredObject ; this . activityValues = activityValues ; } public JSONObject getFilteredObject ( ) { return filteredObject ; } public void setFilteredObject ( JSONObject filteredObject ) { this . filteredObject = filteredObject ; } public Map < Long , Map < String , Object > > getActivityValues ( ) { return activityValues ; } public void setActivityValues ( Map < Long , Map < String , Object > > activityValues ) { this . activityValues = activityValues ; } } @ Override public void start ( ) { } @ Override public void stop ( ) { } } </s>
<s> package com . senseidb . indexing . activity . primitives ; import java . io . IOException ; import java . io . RandomAccessFile ; import java . nio . MappedByteBuffer ; import com . senseidb . indexing . activity . AtomicFieldUpdate ; public class ActivityIntValues extends ActivityPrimitiveValues { public int [ ] fieldValues ; public void init ( int capacity ) { fieldValues = new int [ capacity ] ; } @ Override public boolean update ( int index , Object value ) { ensureCapacity ( index ) ; if ( fieldValues [ index ] == Integer . MIN_VALUE ) { fieldValues [ index ] = <NUM_LIT:0> ; } setValue ( fieldValues , value , index ) ; return updateBatch . addFieldUpdate ( AtomicFieldUpdate . valueOf ( index , fieldValues [ index ] ) ) ; } protected ActivityIntValues ( ) { } public ActivityIntValues ( int capacity ) { init ( capacity ) ; } public int getIntValue ( int index ) { return fieldValues [ index ] ; } private synchronized void ensureCapacity ( int currentArraySize ) { if ( fieldValues . length == <NUM_LIT:0> ) { this . fieldValues = new int [ <NUM_LIT> ] ; return ; } if ( fieldValues . length - currentArraySize < <NUM_LIT:2> ) { int newSize = fieldValues . length < <NUM_LIT> ? fieldValues . length * <NUM_LIT:2> : ( int ) ( fieldValues . length * <NUM_LIT> ) ; int [ ] newFieldValues = new int [ newSize ] ; System . arraycopy ( fieldValues , <NUM_LIT:0> , newFieldValues , <NUM_LIT:0> , fieldValues . length ) ; this . fieldValues = newFieldValues ; } } private static void setValue ( int [ ] fieldValues , Object value , int index ) { if ( value == null ) { return ; } if ( value instanceof Integer ) { fieldValues [ index ] = ( Integer ) value ; } else if ( value instanceof Long ) { fieldValues [ index ] = ( ( Long ) value ) . intValue ( ) ; } else if ( value instanceof String ) { String valStr = ( String ) value ; if ( valStr . isEmpty ( ) ) { return ; } if ( valStr . startsWith ( "<STR_LIT:+>" ) ) { fieldValues [ index ] = fieldValues [ index ] + Integer . parseInt ( valStr . substring ( <NUM_LIT:1> ) ) ; } else if ( valStr . startsWith ( "<STR_LIT:->" ) ) { fieldValues [ index ] = fieldValues [ index ] + Integer . parseInt ( valStr ) ; } else { fieldValues [ index ] = Integer . parseInt ( valStr ) ; } } else { throw new UnsupportedOperationException ( "<STR_LIT>" ) ; } } public int [ ] getFieldValues ( ) { return fieldValues ; } public void setFieldValues ( int [ ] fieldValues ) { this . fieldValues = fieldValues ; } @ Override public void initFieldValues ( int count , MappedByteBuffer buffer ) { for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { int value ; value = buffer . getInt ( i * <NUM_LIT:4> ) ; fieldValues [ i ] = value ; } } @ Override public void initFieldValues ( int count , RandomAccessFile storedFile ) { for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { int value ; try { storedFile . seek ( i * <NUM_LIT:4> ) ; value = storedFile . readInt ( ) ; fieldValues [ i ] = value ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } } @ Override public void delete ( int index ) { fieldValues [ index ] = Integer . MIN_VALUE ; } @ Override public int getFieldSizeInBytes ( ) { return <NUM_LIT:4> ; } @ Override public Number getValue ( int index ) { return fieldValues [ index ] ; } } </s>
<s> package com . senseidb . indexing . activity . primitives ; import java . io . IOException ; import java . io . RandomAccessFile ; import java . nio . MappedByteBuffer ; import com . senseidb . indexing . activity . AtomicFieldUpdate ; public class ActivityFloatValues extends ActivityPrimitiveValues { public float [ ] fieldValues ; public void init ( int capacity ) { fieldValues = new float [ capacity ] ; } @ Override public boolean update ( int index , Object value ) { ensureCapacity ( index ) ; if ( fieldValues [ index ] == Float . MIN_VALUE ) { fieldValues [ index ] = <NUM_LIT:0> ; } setValue ( fieldValues , value , index ) ; return updateBatch . addFieldUpdate ( AtomicFieldUpdate . valueOf ( index , fieldValues [ index ] ) ) ; } protected ActivityFloatValues ( ) { } public ActivityFloatValues ( int capacity ) { init ( capacity ) ; } public float getFloatValue ( int index ) { return fieldValues [ index ] ; } private synchronized void ensureCapacity ( int currentArraySize ) { if ( fieldValues . length == <NUM_LIT:0> ) { this . fieldValues = new float [ <NUM_LIT> ] ; return ; } if ( fieldValues . length - currentArraySize < <NUM_LIT:2> ) { int newSize = fieldValues . length < <NUM_LIT> ? fieldValues . length * <NUM_LIT:2> : ( int ) ( fieldValues . length * <NUM_LIT> ) ; float [ ] newFieldValues = new float [ newSize ] ; System . arraycopy ( fieldValues , <NUM_LIT:0> , newFieldValues , <NUM_LIT:0> , fieldValues . length ) ; this . fieldValues = newFieldValues ; } } private static void setValue ( float [ ] fieldValues , Object value , int index ) { if ( value == null ) { return ; } if ( value instanceof Number ) { fieldValues [ index ] = ( ( Number ) value ) . floatValue ( ) ; } else if ( value instanceof String ) { String valStr = ( String ) value ; if ( valStr . isEmpty ( ) ) { return ; } if ( valStr . startsWith ( "<STR_LIT:+>" ) ) { fieldValues [ index ] = fieldValues [ index ] + Float . parseFloat ( valStr . substring ( <NUM_LIT:1> ) ) ; } else if ( valStr . startsWith ( "<STR_LIT:->" ) ) { fieldValues [ index ] = fieldValues [ index ] + Float . parseFloat ( valStr ) ; } else { fieldValues [ index ] = Float . parseFloat ( valStr ) ; } } else { throw new UnsupportedOperationException ( "<STR_LIT>" ) ; } } public float [ ] getFieldValues ( ) { return fieldValues ; } public void setFieldValues ( float [ ] fieldValues ) { this . fieldValues = fieldValues ; } @ Override public void initFieldValues ( int count , MappedByteBuffer buffer ) { for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { float value ; value = buffer . getFloat ( i * <NUM_LIT:4> ) ; fieldValues [ i ] = value ; } } @ Override public void initFieldValues ( int count , RandomAccessFile storedFile ) { for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { float value ; try { storedFile . seek ( i * <NUM_LIT:4> ) ; value = storedFile . readFloat ( ) ; fieldValues [ i ] = value ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } } @ Override public void delete ( int index ) { fieldValues [ index ] = Float . MIN_VALUE ; } @ Override public int getFieldSizeInBytes ( ) { return <NUM_LIT:4> ; } @ Override public Number getValue ( int index ) { return getFloatValue ( index ) ; } } </s>
<s> package com . senseidb . indexing . activity . primitives ; import java . io . RandomAccessFile ; import java . nio . MappedByteBuffer ; import org . apache . log4j . Logger ; import com . senseidb . conf . SenseiSchema ; import com . senseidb . indexing . activity . ActivityConfig ; import com . senseidb . indexing . activity . ActivityPersistenceFactory ; import com . senseidb . indexing . activity . ActivityValues ; import com . senseidb . indexing . activity . AtomicFieldUpdate ; import com . senseidb . indexing . activity . UpdateBatch ; public abstract class ActivityPrimitiveValues implements ActivityValues { private static Logger logger = Logger . getLogger ( ActivityIntValues . class ) ; protected String fieldName ; protected ActivityPrimitivesStorage activityFieldStore ; protected volatile UpdateBatch < AtomicFieldUpdate > updateBatch ; private ActivityConfig activityConfig ; public ActivityPrimitiveValues ( ) { super ( ) ; } public void init ( ) { init ( <NUM_LIT> ) ; } public abstract void init ( int count ) ; @ Override public Runnable prepareFlush ( ) { if ( activityFieldStore == null ) { return new Runnable ( ) { public void run ( ) { } } ; } if ( activityFieldStore . isClosed ( ) ) { throw new IllegalStateException ( "<STR_LIT>" ) ; } final UpdateBatch < AtomicFieldUpdate > oldBatch = updateBatch ; updateBatch = new UpdateBatch < AtomicFieldUpdate > ( activityConfig ) ; return new Runnable ( ) { public void run ( ) { try { if ( activityFieldStore . isClosed ( ) ) { throw new IllegalStateException ( "<STR_LIT>" ) ; } activityFieldStore . flush ( oldBatch . getUpdates ( ) ) ; } catch ( Exception ex ) { logger . error ( "<STR_LIT>" + oldBatch . getUpdates ( ) , ex ) ; } } } ; } @ Override public void close ( ) { if ( activityFieldStore != null ) { activityFieldStore . close ( ) ; } } @ Override public String getFieldName ( ) { return fieldName ; } public abstract void initFieldValues ( int count , RandomAccessFile storedFile ) ; public abstract void initFieldValues ( int count , MappedByteBuffer buffer ) ; public abstract int getFieldSizeInBytes ( ) ; public abstract Number getValue ( int index ) ; public static ActivityPrimitiveValues createActivityPrimitiveValues ( ActivityPersistenceFactory activityPersistenceFactory , SenseiSchema . FieldDefinition field , int count ) { return createActivityPrimitiveValues ( activityPersistenceFactory , field . type , field . name , count ) ; } public static ActivityPrimitiveValues createActivityPrimitiveValues ( ActivityPersistenceFactory activityPersistenceFactory , Class < ? > type , String fieldName , int count ) { ActivityPrimitiveValues values = null ; if ( type == int . class ) { values = new ActivityIntValues ( ) ; } else if ( type == float . class || type == double . class ) { values = new ActivityFloatValues ( ) ; } else throw new UnsupportedOperationException ( "<STR_LIT>" + type + "<STR_LIT>" ) ; ActivityPrimitivesStorage primitivesStorage = activityPersistenceFactory . getActivivityPrimitivesStorage ( fieldName ) ; values . fieldName = fieldName ; values . activityConfig = activityPersistenceFactory . getActivityConfig ( ) ; values . updateBatch = new UpdateBatch < AtomicFieldUpdate > ( activityPersistenceFactory . getActivityConfig ( ) ) ; if ( primitivesStorage != null ) { primitivesStorage . initActivityDataFromFile ( values , count ) ; } else { values . init ( ) ; } return values ; } } </s>
<s> package com . senseidb . indexing . activity . primitives ; import com . senseidb . metrics . MetricFactory ; import java . io . File ; import java . io . IOException ; import java . io . RandomAccessFile ; import java . nio . MappedByteBuffer ; import java . nio . channels . FileChannel . MapMode ; import java . util . List ; import java . util . concurrent . Callable ; import java . util . concurrent . TimeUnit ; import org . apache . log4j . Logger ; import org . springframework . util . Assert ; import com . senseidb . indexing . activity . AtomicFieldUpdate ; import com . senseidb . metrics . MetricsConstants ; import com . yammer . metrics . core . MetricName ; import com . yammer . metrics . core . Timer ; public class ActivityPrimitivesStorage { public static final double INIT_GROWTH_RATIO = <NUM_LIT> ; public static final int BYTES_IN_INT = <NUM_LIT:4> ; public static final int LENGTH_THRESHOLD = <NUM_LIT> ; public static final int FILE_GROWTH_RATIO = <NUM_LIT:2> ; public static final int INITIAL_FILE_LENGTH = <NUM_LIT> ; private static Logger logger = Logger . getLogger ( ActivityPrimitivesStorage . class ) ; private RandomAccessFile storedFile ; protected final String fieldName ; private final String indexDir ; private volatile boolean closed = false ; private MappedByteBuffer buffer ; private long fileLength ; private boolean activateMemoryMappedBuffers = true ; private final Timer timer ; private String fileName ; public ActivityPrimitivesStorage ( String fieldName , String indexDir ) { this . fieldName = fieldName ; this . indexDir = indexDir ; timer = MetricFactory . newTimer ( new MetricName ( MetricsConstants . Domain , "<STR_LIT>" , "<STR_LIT>" + fieldName . replaceAll ( "<STR_LIT::>" , "<STR_LIT:->" ) , "<STR_LIT>" ) , TimeUnit . MILLISECONDS , TimeUnit . SECONDS ) ; } public synchronized void init ( ) { try { fileName = fieldName . replace ( '<CHAR_LIT::>' , '<CHAR_LIT:->' ) ; File file = new File ( indexDir , fileName + "<STR_LIT>" ) ; if ( ! file . exists ( ) ) { file . createNewFile ( ) ; } storedFile = new RandomAccessFile ( file , "<STR_LIT>" ) ; fileLength = storedFile . length ( ) ; if ( activateMemoryMappedBuffers ) { buffer = storedFile . getChannel ( ) . map ( MapMode . READ_WRITE , <NUM_LIT:0> , file . length ( ) ) ; } } catch ( IOException e ) { logger . error ( e . getMessage ( ) , e ) ; throw new RuntimeException ( e ) ; } } public synchronized void flush ( List < AtomicFieldUpdate > updates ) { Assert . state ( storedFile != null , "<STR_LIT>" ) ; try { for ( AtomicFieldUpdate update : updates ) { ensureCapacity ( ( update . index + <NUM_LIT:1> ) * update . getFieldSizeInBytes ( ) ) ; if ( activateMemoryMappedBuffers ) { update . update ( buffer , update . index * update . getFieldSizeInBytes ( ) ) ; } else { update . update ( storedFile , update . index * update . getFieldSizeInBytes ( ) ) ; } } if ( activateMemoryMappedBuffers ) { buffer . force ( ) ; } storedFile . getFD ( ) . sync ( ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } private void ensureCapacity ( int i ) { try { if ( fileLength > i + <NUM_LIT:100> ) { return ; } if ( fileLength > LENGTH_THRESHOLD ) { fileLength = fileLength * FILE_GROWTH_RATIO ; } else { fileLength = INITIAL_FILE_LENGTH ; } storedFile . setLength ( fileLength ) ; if ( activateMemoryMappedBuffers ) { buffer = storedFile . getChannel ( ) . map ( MapMode . READ_WRITE , <NUM_LIT:0> , fileLength ) ; } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } public synchronized void close ( ) { try { if ( activateMemoryMappedBuffers ) { buffer . force ( ) ; } storedFile . close ( ) ; closed = true ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } protected void initActivityDataFromFile ( final ActivityPrimitiveValues activityPrimitiveValues , final int count ) { try { timer . time ( new Callable < ActivityPrimitiveValues > ( ) { @ Override public ActivityPrimitiveValues call ( ) throws Exception { Assert . state ( storedFile != null , "<STR_LIT>" ) ; activityPrimitiveValues . activityFieldStore = ActivityPrimitivesStorage . this ; activityPrimitiveValues . fieldName = fieldName ; try { if ( count == <NUM_LIT:0> ) { activityPrimitiveValues . init ( ) ; return activityPrimitiveValues ; } activityPrimitiveValues . init ( ( int ) ( count * INIT_GROWTH_RATIO ) ) ; if ( fileLength < count * BYTES_IN_INT ) { logger . warn ( "<STR_LIT>" + fieldName + "<STR_LIT>" + ( fileLength / BYTES_IN_INT ) + "<STR_LIT>" + count ) ; logger . warn ( "<STR_LIT>" ) ; ensureCapacity ( count * activityPrimitiveValues . getFieldSizeInBytes ( ) ) ; } if ( activateMemoryMappedBuffers ) { activityPrimitiveValues . initFieldValues ( count , buffer ) ; } else { activityPrimitiveValues . initFieldValues ( count , storedFile ) ; } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return activityPrimitiveValues ; } } ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } public boolean isClosed ( ) { return closed ; } } </s>
<s> package com . senseidb . indexing . activity ; import java . util . BitSet ; import it . unimi . dsi . fastutil . longs . LongLinkedOpenHashSet ; public class RecentlyAddedUids { private final int capacity ; private LongLinkedOpenHashSet elems ; public RecentlyAddedUids ( int capacity ) { this . capacity = capacity ; elems = new LongLinkedOpenHashSet ( capacity ) ; } public synchronized void add ( long uid ) { if ( elems . size ( ) == capacity ) { elems . remove ( elems . firstLong ( ) ) ; } elems . add ( uid ) ; } public synchronized int markRecentAsFoundInBitSet ( long [ ] uids , BitSet found , int bitSetLength ) { if ( found . length ( ) == <NUM_LIT:0> ) { return <NUM_LIT:0> ; } int ret = <NUM_LIT:0> ; int index = <NUM_LIT:0> ; while ( true ) { if ( index < <NUM_LIT:0> || index >= bitSetLength ) { break ; } index = found . nextClearBit ( index ) ; if ( index < <NUM_LIT:0> || index >= bitSetLength ) { break ; } if ( elems . contains ( uids [ index ] ) ) { found . set ( index ) ; ret ++ ; } else { } index ++ ; } return ret ; } protected synchronized void clear ( ) { elems . clear ( ) ; } } </s>
<s> package com . senseidb . indexing . activity ; public interface ActivityValues { public void init ( int capacity ) ; public boolean update ( int index , Object value ) ; public void delete ( int index ) ; public Runnable prepareFlush ( ) ; public String getFieldName ( ) ; public void close ( ) ; } </s>
<s> package com . senseidb . indexing ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; @ Target ( ElementType . FIELD ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface Uid { } </s>
<s> package com . senseidb . indexing ; public enum MetaType { String , Integer , Short , Long , Float , Double , Date , Char , Boolean , Auto } </s>
<s> package com . senseidb . indexing ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; @ Target ( ElementType . METHOD ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface DeleteChecker { } </s>
<s> package com . senseidb . indexing ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; @ Target ( ElementType . FIELD ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface Meta { String name ( ) default "<STR_LIT>" ; MetaType type ( ) default MetaType . Auto ; String format ( ) default "<STR_LIT>" ; } </s>
<s> package com . senseidb . indexing ; import org . json . JSONObject ; public class StringJsonFilter extends DataSourceFilter < String > { private JsonFilter _innerFilter ; public StringJsonFilter ( ) { _innerFilter = null ; } public void setInnerFilter ( JsonFilter innerFilter ) { _innerFilter = innerFilter ; } public JsonFilter getInnerFilter ( ) { return _innerFilter ; } @ Override protected JSONObject doFilter ( String data ) throws Exception { JSONObject json = new JSONObject ( data ) ; if ( _innerFilter != null ) { json = _innerFilter . doFilter ( json ) ; } return json ; } } </s>
<s> package com . senseidb . gateway ; import java . util . Comparator ; import java . util . Set ; import org . json . JSONObject ; import proj . zoie . impl . indexing . StreamDataProvider ; import proj . zoie . impl . indexing . ZoieConfig ; import com . senseidb . conf . SenseiSchema ; import com . senseidb . indexing . DataSourceFilter ; import com . senseidb . indexing . ShardingStrategy ; import com . senseidb . plugin . AbstractSenseiPlugin ; import com . senseidb . plugin . SenseiPluginRegistry ; public abstract class SenseiGateway < V > extends AbstractSenseiPlugin { public static Comparator < String > DEFAULT_VERSION_COMPARATOR = ZoieConfig . DEFAULT_VERSION_COMPARATOR ; final public DataSourceFilter < V > getDataSourceFilter ( SenseiSchema senseiSchema , SenseiPluginRegistry pluginRegistry ) { DataSourceFilter < V > dataSourceFilter = pluginRegistry . getBeanByFullPrefix ( "<STR_LIT>" , DataSourceFilter . class ) ; if ( dataSourceFilter != null ) { dataSourceFilter . setSrcDataStore ( senseiSchema . getSrcDataStore ( ) ) ; dataSourceFilter . setSrcDataField ( senseiSchema . getSrcDataField ( ) ) ; return dataSourceFilter ; } return null ; } final public StreamDataProvider < JSONObject > buildDataProvider ( SenseiSchema senseiSchema , String oldSinceKey , SenseiPluginRegistry pluginRegistry , ShardingStrategy shardingStrategy , Set < Integer > partitions ) throws Exception { DataSourceFilter < V > filter = getDataSourceFilter ( senseiSchema , pluginRegistry ) ; return buildDataProvider ( filter , oldSinceKey , shardingStrategy , partitions ) ; } abstract public StreamDataProvider < JSONObject > buildDataProvider ( DataSourceFilter < V > dataFilter , String oldSinceKey , ShardingStrategy shardingStrategy , Set < Integer > partitions ) throws Exception ; abstract public Comparator < String > getVersionComparator ( ) ; } </s>
<s> package com . senseidb . gateway . file ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . InputStreamReader ; import java . nio . charset . Charset ; import java . util . Comparator ; import org . apache . log4j . Logger ; import proj . zoie . api . DataConsumer . DataEvent ; import proj . zoie . impl . indexing . StreamDataProvider ; public abstract class LinedFileDataProvider < D > extends StreamDataProvider < D > { private static final Logger logger = Logger . getLogger ( LinedFileDataProvider . class ) ; private final File _file ; private long _startingOffset ; protected long _offset ; private BufferedReader _reader ; private static Charset UTF8 = Charset . forName ( "<STR_LIT:UTF-8>" ) ; public LinedFileDataProvider ( Comparator < String > versionComparator , File file , long startingOffset ) { super ( versionComparator ) ; _file = file ; _reader = null ; _startingOffset = startingOffset ; } protected abstract D convertLine ( String line ) throws IOException ; @ Override public DataEvent < D > next ( ) { DataEvent < D > event = null ; if ( _reader != null ) { try { String line = _reader . readLine ( ) ; if ( line == null ) return null ; D dataObj = convertLine ( line ) ; String version = String . valueOf ( _offset ) ; _offset ++ ; event = new DataEvent < D > ( dataObj , version ) ; } catch ( IOException ioe ) { logger . error ( ioe . getMessage ( ) , ioe ) ; } } return event ; } @ Override public void setStartingOffset ( String version ) { if ( version != null ) _startingOffset = Long . parseLong ( version ) ; else _startingOffset = <NUM_LIT:0> ; } @ Override public void reset ( ) { if ( _reader != null ) { try { _offset = _startingOffset ; for ( int i = <NUM_LIT:0> ; i < _offset ; ++ i ) { _reader . readLine ( ) ; } } catch ( IOException e ) { logger . error ( e . getMessage ( ) , e ) ; } } } @ Override public void start ( ) { super . start ( ) ; try { _reader = new BufferedReader ( new InputStreamReader ( new FileInputStream ( _file ) , UTF8 ) , <NUM_LIT> ) ; _offset = _startingOffset ; reset ( ) ; } catch ( IOException ioe ) { logger . error ( ioe . getMessage ( ) , ioe ) ; } } @ Override public void stop ( ) { try { try { if ( _reader != null ) { _reader . close ( ) ; } } catch ( IOException ioe ) { logger . error ( ioe . getMessage ( ) , ioe ) ; } finally { _reader = null ; } } finally { super . stop ( ) ; } } } </s>
<s> package com . senseidb . gateway . file ; import java . io . File ; import java . io . IOException ; import java . util . Comparator ; import org . json . JSONException ; import org . json . JSONObject ; import com . senseidb . indexing . DataSourceFilter ; import com . senseidb . indexing . DataSourceFilterable ; public class LinedJsonFileDataProvider extends LinedFileDataProvider < JSONObject > implements DataSourceFilterable < String > { private DataSourceFilter < String > _dataSourceFilter ; public LinedJsonFileDataProvider ( Comparator < String > versionComparator , File file , long startingOffset ) { super ( versionComparator , file , startingOffset ) ; } @ Override public void setFilter ( DataSourceFilter < String > filter ) { _dataSourceFilter = filter ; } @ Override protected JSONObject convertLine ( String line ) throws IOException { try { if ( _dataSourceFilter != null ) return _dataSourceFilter . filter ( line ) ; } catch ( Exception e ) { throw new IOException ( e . getMessage ( ) , e ) ; } try { return new JSONObject ( line ) ; } catch ( JSONException e ) { throw new IOException ( e . getMessage ( ) , e ) ; } } } </s>
<s> package com . senseidb . gateway . file ; import java . io . File ; import java . util . Comparator ; import java . util . Set ; import org . json . JSONObject ; import proj . zoie . impl . indexing . StreamDataProvider ; import proj . zoie . impl . indexing . ZoieConfig ; import com . senseidb . gateway . SenseiGateway ; import com . senseidb . indexing . DataSourceFilter ; import com . senseidb . indexing . ShardingStrategy ; public class LinedFileDataProviderBuilder extends SenseiGateway < String > { private Comparator < String > _versionComparator = ZoieConfig . DEFAULT_VERSION_COMPARATOR ; @ Override public StreamDataProvider < JSONObject > buildDataProvider ( DataSourceFilter < String > dataFilter , String oldSinceKey , ShardingStrategy shardingStrategy , Set < Integer > partitions ) throws Exception { String path = config . get ( "<STR_LIT>" ) ; long offset = oldSinceKey == null ? <NUM_LIT> : Long . parseLong ( oldSinceKey ) ; LinedJsonFileDataProvider provider = new LinedJsonFileDataProvider ( _versionComparator , new File ( path ) , offset ) ; if ( dataFilter != null ) { provider . setFilter ( dataFilter ) ; } return provider ; } @ Override public Comparator < String > getVersionComparator ( ) { return _versionComparator ; } } </s>
<s> package com . sensei . search . req . protobuf ; public final class SenseiGenericResultBPO { private SenseiGenericResultBPO ( ) { } public static void registerAllExtensions ( com . google . protobuf . ExtensionRegistry registry ) { } public interface GenericResultOrBuilder extends com . google . protobuf . MessageOrBuilder { boolean hasClassname ( ) ; String getClassname ( ) ; boolean hasVal ( ) ; com . google . protobuf . ByteString getVal ( ) ; } public static final class GenericResult extends com . google . protobuf . GeneratedMessage implements GenericResultOrBuilder { private GenericResult ( Builder builder ) { super ( builder ) ; } private GenericResult ( boolean noInit ) { } private static final GenericResult defaultInstance ; public static GenericResult getDefaultInstance ( ) { return defaultInstance ; } public GenericResult getDefaultInstanceForType ( ) { return defaultInstance ; } public static final com . google . protobuf . Descriptors . Descriptor getDescriptor ( ) { return com . sensei . search . req . protobuf . SenseiGenericResultBPO . internal_static_com_sensei_search_req_protobuf_GenericResult_descriptor ; } protected com . google . protobuf . GeneratedMessage . FieldAccessorTable internalGetFieldAccessorTable ( ) { return com . sensei . search . req . protobuf . SenseiGenericResultBPO . internal_static_com_sensei_search_req_protobuf_GenericResult_fieldAccessorTable ; } private int bitField0_ ; public static final int CLASSNAME_FIELD_NUMBER = <NUM_LIT:1> ; private Object classname_ ; public boolean hasClassname ( ) { return ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ; } public String getClassname ( ) { Object ref = classname_ ; if ( ref instanceof String ) { return ( String ) ref ; } else { com . google . protobuf . ByteString bs = ( com . google . protobuf . ByteString ) ref ; String s = bs . toStringUtf8 ( ) ; if ( com . google . protobuf . Internal . isValidUtf8 ( bs ) ) { classname_ = s ; } return s ; } } private com . google . protobuf . ByteString getClassnameBytes ( ) { Object ref = classname_ ; if ( ref instanceof String ) { com . google . protobuf . ByteString b = com . google . protobuf . ByteString . copyFromUtf8 ( ( String ) ref ) ; classname_ = b ; return b ; } else { return ( com . google . protobuf . ByteString ) ref ; } } public static final int VAL_FIELD_NUMBER = <NUM_LIT:2> ; private com . google . protobuf . ByteString val_ ; public boolean hasVal ( ) { return ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ; } public com . google . protobuf . ByteString getVal ( ) { return val_ ; } private void initFields ( ) { classname_ = "<STR_LIT>" ; val_ = com . google . protobuf . ByteString . EMPTY ; } private byte memoizedIsInitialized = - <NUM_LIT:1> ; public final boolean isInitialized ( ) { byte isInitialized = memoizedIsInitialized ; if ( isInitialized != - <NUM_LIT:1> ) return isInitialized == <NUM_LIT:1> ; if ( ! hasClassname ( ) ) { memoizedIsInitialized = <NUM_LIT:0> ; return false ; } if ( ! hasVal ( ) ) { memoizedIsInitialized = <NUM_LIT:0> ; return false ; } memoizedIsInitialized = <NUM_LIT:1> ; return true ; } public void writeTo ( com . google . protobuf . CodedOutputStream output ) throws java . io . IOException { getSerializedSize ( ) ; if ( ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { output . writeBytes ( <NUM_LIT:1> , getClassnameBytes ( ) ) ; } if ( ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { output . writeBytes ( <NUM_LIT:2> , val_ ) ; } getUnknownFields ( ) . writeTo ( output ) ; } private int memoizedSerializedSize = - <NUM_LIT:1> ; public int getSerializedSize ( ) { int size = memoizedSerializedSize ; if ( size != - <NUM_LIT:1> ) return size ; size = <NUM_LIT:0> ; if ( ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { size += com . google . protobuf . CodedOutputStream . computeBytesSize ( <NUM_LIT:1> , getClassnameBytes ( ) ) ; } if ( ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { size += com . google . protobuf . CodedOutputStream . computeBytesSize ( <NUM_LIT:2> , val_ ) ; } size += getUnknownFields ( ) . getSerializedSize ( ) ; memoizedSerializedSize = size ; return size ; } @ java . lang . Override protected Object writeReplace ( ) throws java . io . ObjectStreamException { return super . writeReplace ( ) ; } public static com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult parseFrom ( com . google . protobuf . ByteString data ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult parseFrom ( com . google . protobuf . ByteString data , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult parseFrom ( byte [ ] data ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult parseFrom ( byte [ ] data , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult parseFrom ( java . io . InputStream input ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult parseFrom ( java . io . InputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult parseDelimitedFrom ( java . io . InputStream input ) throws java . io . IOException { Builder builder = newBuilder ( ) ; if ( builder . mergeDelimitedFrom ( input ) ) { return builder . buildParsed ( ) ; } else { return null ; } } public static com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult parseDelimitedFrom ( java . io . InputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { Builder builder = newBuilder ( ) ; if ( builder . mergeDelimitedFrom ( input , extensionRegistry ) ) { return builder . buildParsed ( ) ; } else { return null ; } } public static com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult parseFrom ( com . google . protobuf . CodedInputStream input ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult parseFrom ( com . google . protobuf . CodedInputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input , extensionRegistry ) . buildParsed ( ) ; } public static Builder newBuilder ( ) { return Builder . create ( ) ; } public Builder newBuilderForType ( ) { return newBuilder ( ) ; } public static Builder newBuilder ( com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult prototype ) { return newBuilder ( ) . mergeFrom ( prototype ) ; } public Builder toBuilder ( ) { return newBuilder ( this ) ; } @ java . lang . Override protected Builder newBuilderForType ( com . google . protobuf . GeneratedMessage . BuilderParent parent ) { Builder builder = new Builder ( parent ) ; return builder ; } public static final class Builder extends com . google . protobuf . GeneratedMessage . Builder < Builder > implements com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResultOrBuilder { public static final com . google . protobuf . Descriptors . Descriptor getDescriptor ( ) { return com . sensei . search . req . protobuf . SenseiGenericResultBPO . internal_static_com_sensei_search_req_protobuf_GenericResult_descriptor ; } protected com . google . protobuf . GeneratedMessage . FieldAccessorTable internalGetFieldAccessorTable ( ) { return com . sensei . search . req . protobuf . SenseiGenericResultBPO . internal_static_com_sensei_search_req_protobuf_GenericResult_fieldAccessorTable ; } private Builder ( ) { maybeForceBuilderInitialization ( ) ; } private Builder ( BuilderParent parent ) { super ( parent ) ; maybeForceBuilderInitialization ( ) ; } private void maybeForceBuilderInitialization ( ) { if ( com . google . protobuf . GeneratedMessage . alwaysUseFieldBuilders ) { } } private static Builder create ( ) { return new Builder ( ) ; } public Builder clear ( ) { super . clear ( ) ; classname_ = "<STR_LIT>" ; bitField0_ = ( bitField0_ & ~ <NUM_LIT> ) ; val_ = com . google . protobuf . ByteString . EMPTY ; bitField0_ = ( bitField0_ & ~ <NUM_LIT> ) ; return this ; } public Builder clone ( ) { return create ( ) . mergeFrom ( buildPartial ( ) ) ; } public com . google . protobuf . Descriptors . Descriptor getDescriptorForType ( ) { return com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult . getDescriptor ( ) ; } public com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult getDefaultInstanceForType ( ) { return com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult . getDefaultInstance ( ) ; } public com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult build ( ) { com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult result = buildPartial ( ) ; if ( ! result . isInitialized ( ) ) { throw newUninitializedMessageException ( result ) ; } return result ; } private com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult buildParsed ( ) throws com . google . protobuf . InvalidProtocolBufferException { com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult result = buildPartial ( ) ; if ( ! result . isInitialized ( ) ) { throw newUninitializedMessageException ( result ) . asInvalidProtocolBufferException ( ) ; } return result ; } public com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult buildPartial ( ) { com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult result = new com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult ( this ) ; int from_bitField0_ = bitField0_ ; int to_bitField0_ = <NUM_LIT:0> ; if ( ( ( from_bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { to_bitField0_ |= <NUM_LIT> ; } result . classname_ = classname_ ; if ( ( ( from_bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { to_bitField0_ |= <NUM_LIT> ; } result . val_ = val_ ; result . bitField0_ = to_bitField0_ ; onBuilt ( ) ; return result ; } public Builder mergeFrom ( com . google . protobuf . Message other ) { if ( other instanceof com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult ) { return mergeFrom ( ( com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult ) other ) ; } else { super . mergeFrom ( other ) ; return this ; } } public Builder mergeFrom ( com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult other ) { if ( other == com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult . getDefaultInstance ( ) ) return this ; if ( other . hasClassname ( ) ) { setClassname ( other . getClassname ( ) ) ; } if ( other . hasVal ( ) ) { setVal ( other . getVal ( ) ) ; } this . mergeUnknownFields ( other . getUnknownFields ( ) ) ; return this ; } public final boolean isInitialized ( ) { if ( ! hasClassname ( ) ) { return false ; } if ( ! hasVal ( ) ) { return false ; } return true ; } public Builder mergeFrom ( com . google . protobuf . CodedInputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { com . google . protobuf . UnknownFieldSet . Builder unknownFields = com . google . protobuf . UnknownFieldSet . newBuilder ( this . getUnknownFields ( ) ) ; while ( true ) { int tag = input . readTag ( ) ; switch ( tag ) { case <NUM_LIT:0> : this . setUnknownFields ( unknownFields . build ( ) ) ; onChanged ( ) ; return this ; default : { if ( ! parseUnknownField ( input , unknownFields , extensionRegistry , tag ) ) { this . setUnknownFields ( unknownFields . build ( ) ) ; onChanged ( ) ; return this ; } break ; } case <NUM_LIT:10> : { bitField0_ |= <NUM_LIT> ; classname_ = input . readBytes ( ) ; break ; } case <NUM_LIT> : { bitField0_ |= <NUM_LIT> ; val_ = input . readBytes ( ) ; break ; } } } } private int bitField0_ ; private Object classname_ = "<STR_LIT>" ; public boolean hasClassname ( ) { return ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ; } public String getClassname ( ) { Object ref = classname_ ; if ( ! ( ref instanceof String ) ) { String s = ( ( com . google . protobuf . ByteString ) ref ) . toStringUtf8 ( ) ; classname_ = s ; return s ; } else { return ( String ) ref ; } } public Builder setClassname ( String value ) { if ( value == null ) { throw new NullPointerException ( ) ; } bitField0_ |= <NUM_LIT> ; classname_ = value ; onChanged ( ) ; return this ; } public Builder clearClassname ( ) { bitField0_ = ( bitField0_ & ~ <NUM_LIT> ) ; classname_ = getDefaultInstance ( ) . getClassname ( ) ; onChanged ( ) ; return this ; } void setClassname ( com . google . protobuf . ByteString value ) { bitField0_ |= <NUM_LIT> ; classname_ = value ; onChanged ( ) ; } private com . google . protobuf . ByteString val_ = com . google . protobuf . ByteString . EMPTY ; public boolean hasVal ( ) { return ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ; } public com . google . protobuf . ByteString getVal ( ) { return val_ ; } public Builder setVal ( com . google . protobuf . ByteString value ) { if ( value == null ) { throw new NullPointerException ( ) ; } bitField0_ |= <NUM_LIT> ; val_ = value ; onChanged ( ) ; return this ; } public Builder clearVal ( ) { bitField0_ = ( bitField0_ & ~ <NUM_LIT> ) ; val_ = getDefaultInstance ( ) . getVal ( ) ; onChanged ( ) ; return this ; } } static { defaultInstance = new GenericResult ( true ) ; defaultInstance . initFields ( ) ; } } private static com . google . protobuf . Descriptors . Descriptor internal_static_com_sensei_search_req_protobuf_GenericResult_descriptor ; private static com . google . protobuf . GeneratedMessage . FieldAccessorTable internal_static_com_sensei_search_req_protobuf_GenericResult_fieldAccessorTable ; public static com . google . protobuf . Descriptors . FileDescriptor getDescriptor ( ) { return descriptor ; } private static com . google . protobuf . Descriptors . FileDescriptor descriptor ; static { java . lang . String [ ] descriptorData = { "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" } ; com . google . protobuf . Descriptors . FileDescriptor . InternalDescriptorAssigner assigner = new com . google . protobuf . Descriptors . FileDescriptor . InternalDescriptorAssigner ( ) { public com . google . protobuf . ExtensionRegistry assignDescriptors ( com . google . protobuf . Descriptors . FileDescriptor root ) { descriptor = root ; internal_static_com_sensei_search_req_protobuf_GenericResult_descriptor = getDescriptor ( ) . getMessageTypes ( ) . get ( <NUM_LIT:0> ) ; internal_static_com_sensei_search_req_protobuf_GenericResult_fieldAccessorTable = new com . google . protobuf . GeneratedMessage . FieldAccessorTable ( internal_static_com_sensei_search_req_protobuf_GenericResult_descriptor , new java . lang . String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult . class , com . sensei . search . req . protobuf . SenseiGenericResultBPO . GenericResult . Builder . class ) ; return null ; } } ; com . google . protobuf . Descriptors . FileDescriptor . internalBuildGeneratedFileFrom ( descriptorData , new com . google . protobuf . Descriptors . FileDescriptor [ ] { } , assigner ) ; } } </s>
<s> package com . sensei . search . req . protobuf ; import com . google . protobuf . ByteString ; import com . google . protobuf . InvalidProtocolBufferException ; import com . google . protobuf . TextFormat ; import com . linkedin . norbert . network . Serializer ; import com . senseidb . search . req . SenseiRequest ; import com . senseidb . search . req . SenseiResult ; public class SenseiReqProtoSerializer implements Serializer < SenseiRequest , SenseiResult > { public String requestName ( ) { return SenseiRequestBPO . Request . getDescriptor ( ) . getName ( ) ; } public String responseName ( ) { return SenseiResultBPO . Result . getDescriptor ( ) . getName ( ) ; } public byte [ ] requestToBytes ( SenseiRequest request ) { return SenseiRequestBPO . Request . newBuilder ( ) . setVal ( serialize ( request ) ) . build ( ) . toByteArray ( ) ; } public byte [ ] responseToBytes ( SenseiResult response ) { return SenseiResultBPO . Result . newBuilder ( ) . setVal ( serialize ( response ) ) . build ( ) . toByteArray ( ) ; } private < T > ByteString serialize ( T obj ) { try { return ProtoConvertUtil . serializeOut ( obj ) ; } catch ( TextFormat . ParseException e ) { throw new RuntimeException ( e ) ; } } public SenseiRequest requestFromBytes ( byte [ ] request ) { try { return ( SenseiRequest ) ProtoConvertUtil . serializeIn ( SenseiRequestBPO . Request . newBuilder ( ) . mergeFrom ( request ) . build ( ) . getVal ( ) ) ; } catch ( TextFormat . ParseException e ) { throw new RuntimeException ( e ) ; } catch ( InvalidProtocolBufferException e ) { throw new RuntimeException ( e ) ; } } public SenseiResult responseFromBytes ( byte [ ] result ) { try { return ( SenseiResult ) ProtoConvertUtil . serializeIn ( SenseiResultBPO . Result . newBuilder ( ) . mergeFrom ( result ) . build ( ) . getVal ( ) ) ; } catch ( TextFormat . ParseException e ) { throw new RuntimeException ( e ) ; } catch ( InvalidProtocolBufferException e ) { throw new RuntimeException ( e ) ; } } } </s>
<s> package com . sensei . search . req . protobuf ; public final class SenseiRequestBPO { private SenseiRequestBPO ( ) { } public static void registerAllExtensions ( com . google . protobuf . ExtensionRegistry registry ) { } public interface RequestOrBuilder extends com . google . protobuf . MessageOrBuilder { boolean hasVal ( ) ; com . google . protobuf . ByteString getVal ( ) ; } public static final class Request extends com . google . protobuf . GeneratedMessage implements RequestOrBuilder { private Request ( Builder builder ) { super ( builder ) ; } private Request ( boolean noInit ) { } private static final Request defaultInstance ; public static Request getDefaultInstance ( ) { return defaultInstance ; } public Request getDefaultInstanceForType ( ) { return defaultInstance ; } public static final com . google . protobuf . Descriptors . Descriptor getDescriptor ( ) { return com . sensei . search . req . protobuf . SenseiRequestBPO . internal_static_com_sensei_search_req_protobuf_Request_descriptor ; } protected com . google . protobuf . GeneratedMessage . FieldAccessorTable internalGetFieldAccessorTable ( ) { return com . sensei . search . req . protobuf . SenseiRequestBPO . internal_static_com_sensei_search_req_protobuf_Request_fieldAccessorTable ; } private int bitField0_ ; public static final int VAL_FIELD_NUMBER = <NUM_LIT:1> ; private com . google . protobuf . ByteString val_ ; public boolean hasVal ( ) { return ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ; } public com . google . protobuf . ByteString getVal ( ) { return val_ ; } private void initFields ( ) { val_ = com . google . protobuf . ByteString . EMPTY ; } private byte memoizedIsInitialized = - <NUM_LIT:1> ; public final boolean isInitialized ( ) { byte isInitialized = memoizedIsInitialized ; if ( isInitialized != - <NUM_LIT:1> ) return isInitialized == <NUM_LIT:1> ; if ( ! hasVal ( ) ) { memoizedIsInitialized = <NUM_LIT:0> ; return false ; } memoizedIsInitialized = <NUM_LIT:1> ; return true ; } public void writeTo ( com . google . protobuf . CodedOutputStream output ) throws java . io . IOException { getSerializedSize ( ) ; if ( ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { output . writeBytes ( <NUM_LIT:1> , val_ ) ; } getUnknownFields ( ) . writeTo ( output ) ; } private int memoizedSerializedSize = - <NUM_LIT:1> ; public int getSerializedSize ( ) { int size = memoizedSerializedSize ; if ( size != - <NUM_LIT:1> ) return size ; size = <NUM_LIT:0> ; if ( ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { size += com . google . protobuf . CodedOutputStream . computeBytesSize ( <NUM_LIT:1> , val_ ) ; } size += getUnknownFields ( ) . getSerializedSize ( ) ; memoizedSerializedSize = size ; return size ; } @ java . lang . Override protected Object writeReplace ( ) throws java . io . ObjectStreamException { return super . writeReplace ( ) ; } public static com . sensei . search . req . protobuf . SenseiRequestBPO . Request parseFrom ( com . google . protobuf . ByteString data ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiRequestBPO . Request parseFrom ( com . google . protobuf . ByteString data , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiRequestBPO . Request parseFrom ( byte [ ] data ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiRequestBPO . Request parseFrom ( byte [ ] data , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiRequestBPO . Request parseFrom ( java . io . InputStream input ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiRequestBPO . Request parseFrom ( java . io . InputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiRequestBPO . Request parseDelimitedFrom ( java . io . InputStream input ) throws java . io . IOException { Builder builder = newBuilder ( ) ; if ( builder . mergeDelimitedFrom ( input ) ) { return builder . buildParsed ( ) ; } else { return null ; } } public static com . sensei . search . req . protobuf . SenseiRequestBPO . Request parseDelimitedFrom ( java . io . InputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { Builder builder = newBuilder ( ) ; if ( builder . mergeDelimitedFrom ( input , extensionRegistry ) ) { return builder . buildParsed ( ) ; } else { return null ; } } public static com . sensei . search . req . protobuf . SenseiRequestBPO . Request parseFrom ( com . google . protobuf . CodedInputStream input ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiRequestBPO . Request parseFrom ( com . google . protobuf . CodedInputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input , extensionRegistry ) . buildParsed ( ) ; } public static Builder newBuilder ( ) { return Builder . create ( ) ; } public Builder newBuilderForType ( ) { return newBuilder ( ) ; } public static Builder newBuilder ( com . sensei . search . req . protobuf . SenseiRequestBPO . Request prototype ) { return newBuilder ( ) . mergeFrom ( prototype ) ; } public Builder toBuilder ( ) { return newBuilder ( this ) ; } @ java . lang . Override protected Builder newBuilderForType ( com . google . protobuf . GeneratedMessage . BuilderParent parent ) { Builder builder = new Builder ( parent ) ; return builder ; } public static final class Builder extends com . google . protobuf . GeneratedMessage . Builder < Builder > implements com . sensei . search . req . protobuf . SenseiRequestBPO . RequestOrBuilder { public static final com . google . protobuf . Descriptors . Descriptor getDescriptor ( ) { return com . sensei . search . req . protobuf . SenseiRequestBPO . internal_static_com_sensei_search_req_protobuf_Request_descriptor ; } protected com . google . protobuf . GeneratedMessage . FieldAccessorTable internalGetFieldAccessorTable ( ) { return com . sensei . search . req . protobuf . SenseiRequestBPO . internal_static_com_sensei_search_req_protobuf_Request_fieldAccessorTable ; } private Builder ( ) { maybeForceBuilderInitialization ( ) ; } private Builder ( BuilderParent parent ) { super ( parent ) ; maybeForceBuilderInitialization ( ) ; } private void maybeForceBuilderInitialization ( ) { if ( com . google . protobuf . GeneratedMessage . alwaysUseFieldBuilders ) { } } private static Builder create ( ) { return new Builder ( ) ; } public Builder clear ( ) { super . clear ( ) ; val_ = com . google . protobuf . ByteString . EMPTY ; bitField0_ = ( bitField0_ & ~ <NUM_LIT> ) ; return this ; } public Builder clone ( ) { return create ( ) . mergeFrom ( buildPartial ( ) ) ; } public com . google . protobuf . Descriptors . Descriptor getDescriptorForType ( ) { return com . sensei . search . req . protobuf . SenseiRequestBPO . Request . getDescriptor ( ) ; } public com . sensei . search . req . protobuf . SenseiRequestBPO . Request getDefaultInstanceForType ( ) { return com . sensei . search . req . protobuf . SenseiRequestBPO . Request . getDefaultInstance ( ) ; } public com . sensei . search . req . protobuf . SenseiRequestBPO . Request build ( ) { com . sensei . search . req . protobuf . SenseiRequestBPO . Request result = buildPartial ( ) ; if ( ! result . isInitialized ( ) ) { throw newUninitializedMessageException ( result ) ; } return result ; } private com . sensei . search . req . protobuf . SenseiRequestBPO . Request buildParsed ( ) throws com . google . protobuf . InvalidProtocolBufferException { com . sensei . search . req . protobuf . SenseiRequestBPO . Request result = buildPartial ( ) ; if ( ! result . isInitialized ( ) ) { throw newUninitializedMessageException ( result ) . asInvalidProtocolBufferException ( ) ; } return result ; } public com . sensei . search . req . protobuf . SenseiRequestBPO . Request buildPartial ( ) { com . sensei . search . req . protobuf . SenseiRequestBPO . Request result = new com . sensei . search . req . protobuf . SenseiRequestBPO . Request ( this ) ; int from_bitField0_ = bitField0_ ; int to_bitField0_ = <NUM_LIT:0> ; if ( ( ( from_bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { to_bitField0_ |= <NUM_LIT> ; } result . val_ = val_ ; result . bitField0_ = to_bitField0_ ; onBuilt ( ) ; return result ; } public Builder mergeFrom ( com . google . protobuf . Message other ) { if ( other instanceof com . sensei . search . req . protobuf . SenseiRequestBPO . Request ) { return mergeFrom ( ( com . sensei . search . req . protobuf . SenseiRequestBPO . Request ) other ) ; } else { super . mergeFrom ( other ) ; return this ; } } public Builder mergeFrom ( com . sensei . search . req . protobuf . SenseiRequestBPO . Request other ) { if ( other == com . sensei . search . req . protobuf . SenseiRequestBPO . Request . getDefaultInstance ( ) ) return this ; if ( other . hasVal ( ) ) { setVal ( other . getVal ( ) ) ; } this . mergeUnknownFields ( other . getUnknownFields ( ) ) ; return this ; } public final boolean isInitialized ( ) { if ( ! hasVal ( ) ) { return false ; } return true ; } public Builder mergeFrom ( com . google . protobuf . CodedInputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { com . google . protobuf . UnknownFieldSet . Builder unknownFields = com . google . protobuf . UnknownFieldSet . newBuilder ( this . getUnknownFields ( ) ) ; while ( true ) { int tag = input . readTag ( ) ; switch ( tag ) { case <NUM_LIT:0> : this . setUnknownFields ( unknownFields . build ( ) ) ; onChanged ( ) ; return this ; default : { if ( ! parseUnknownField ( input , unknownFields , extensionRegistry , tag ) ) { this . setUnknownFields ( unknownFields . build ( ) ) ; onChanged ( ) ; return this ; } break ; } case <NUM_LIT:10> : { bitField0_ |= <NUM_LIT> ; val_ = input . readBytes ( ) ; break ; } } } } private int bitField0_ ; private com . google . protobuf . ByteString val_ = com . google . protobuf . ByteString . EMPTY ; public boolean hasVal ( ) { return ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ; } public com . google . protobuf . ByteString getVal ( ) { return val_ ; } public Builder setVal ( com . google . protobuf . ByteString value ) { if ( value == null ) { throw new NullPointerException ( ) ; } bitField0_ |= <NUM_LIT> ; val_ = value ; onChanged ( ) ; return this ; } public Builder clearVal ( ) { bitField0_ = ( bitField0_ & ~ <NUM_LIT> ) ; val_ = getDefaultInstance ( ) . getVal ( ) ; onChanged ( ) ; return this ; } } static { defaultInstance = new Request ( true ) ; defaultInstance . initFields ( ) ; } } private static com . google . protobuf . Descriptors . Descriptor internal_static_com_sensei_search_req_protobuf_Request_descriptor ; private static com . google . protobuf . GeneratedMessage . FieldAccessorTable internal_static_com_sensei_search_req_protobuf_Request_fieldAccessorTable ; public static com . google . protobuf . Descriptors . FileDescriptor getDescriptor ( ) { return descriptor ; } private static com . google . protobuf . Descriptors . FileDescriptor descriptor ; static { java . lang . String [ ] descriptorData = { "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" } ; com . google . protobuf . Descriptors . FileDescriptor . InternalDescriptorAssigner assigner = new com . google . protobuf . Descriptors . FileDescriptor . InternalDescriptorAssigner ( ) { public com . google . protobuf . ExtensionRegistry assignDescriptors ( com . google . protobuf . Descriptors . FileDescriptor root ) { descriptor = root ; internal_static_com_sensei_search_req_protobuf_Request_descriptor = getDescriptor ( ) . getMessageTypes ( ) . get ( <NUM_LIT:0> ) ; internal_static_com_sensei_search_req_protobuf_Request_fieldAccessorTable = new com . google . protobuf . GeneratedMessage . FieldAccessorTable ( internal_static_com_sensei_search_req_protobuf_Request_descriptor , new java . lang . String [ ] { "<STR_LIT>" , } , com . sensei . search . req . protobuf . SenseiRequestBPO . Request . class , com . sensei . search . req . protobuf . SenseiRequestBPO . Request . Builder . class ) ; return null ; } } ; com . google . protobuf . Descriptors . FileDescriptor . internalBuildGeneratedFileFrom ( descriptorData , new com . google . protobuf . Descriptors . FileDescriptor [ ] { } , assigner ) ; } } </s>
<s> package com . sensei . search . req . protobuf ; public final class SenseiGenericRequestBPO { private SenseiGenericRequestBPO ( ) { } public static void registerAllExtensions ( com . google . protobuf . ExtensionRegistry registry ) { } public interface GenericRequestOrBuilder extends com . google . protobuf . MessageOrBuilder { boolean hasClassname ( ) ; String getClassname ( ) ; boolean hasVal ( ) ; com . google . protobuf . ByteString getVal ( ) ; } public static final class GenericRequest extends com . google . protobuf . GeneratedMessage implements GenericRequestOrBuilder { private GenericRequest ( Builder builder ) { super ( builder ) ; } private GenericRequest ( boolean noInit ) { } private static final GenericRequest defaultInstance ; public static GenericRequest getDefaultInstance ( ) { return defaultInstance ; } public GenericRequest getDefaultInstanceForType ( ) { return defaultInstance ; } public static final com . google . protobuf . Descriptors . Descriptor getDescriptor ( ) { return com . sensei . search . req . protobuf . SenseiGenericRequestBPO . internal_static_com_sensei_search_req_protobuf_GenericRequest_descriptor ; } protected com . google . protobuf . GeneratedMessage . FieldAccessorTable internalGetFieldAccessorTable ( ) { return com . sensei . search . req . protobuf . SenseiGenericRequestBPO . internal_static_com_sensei_search_req_protobuf_GenericRequest_fieldAccessorTable ; } private int bitField0_ ; public static final int CLASSNAME_FIELD_NUMBER = <NUM_LIT:1> ; private Object classname_ ; public boolean hasClassname ( ) { return ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ; } public String getClassname ( ) { Object ref = classname_ ; if ( ref instanceof String ) { return ( String ) ref ; } else { com . google . protobuf . ByteString bs = ( com . google . protobuf . ByteString ) ref ; String s = bs . toStringUtf8 ( ) ; if ( com . google . protobuf . Internal . isValidUtf8 ( bs ) ) { classname_ = s ; } return s ; } } private com . google . protobuf . ByteString getClassnameBytes ( ) { Object ref = classname_ ; if ( ref instanceof String ) { com . google . protobuf . ByteString b = com . google . protobuf . ByteString . copyFromUtf8 ( ( String ) ref ) ; classname_ = b ; return b ; } else { return ( com . google . protobuf . ByteString ) ref ; } } public static final int VAL_FIELD_NUMBER = <NUM_LIT:2> ; private com . google . protobuf . ByteString val_ ; public boolean hasVal ( ) { return ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ; } public com . google . protobuf . ByteString getVal ( ) { return val_ ; } private void initFields ( ) { classname_ = "<STR_LIT>" ; val_ = com . google . protobuf . ByteString . EMPTY ; } private byte memoizedIsInitialized = - <NUM_LIT:1> ; public final boolean isInitialized ( ) { byte isInitialized = memoizedIsInitialized ; if ( isInitialized != - <NUM_LIT:1> ) return isInitialized == <NUM_LIT:1> ; if ( ! hasClassname ( ) ) { memoizedIsInitialized = <NUM_LIT:0> ; return false ; } if ( ! hasVal ( ) ) { memoizedIsInitialized = <NUM_LIT:0> ; return false ; } memoizedIsInitialized = <NUM_LIT:1> ; return true ; } public void writeTo ( com . google . protobuf . CodedOutputStream output ) throws java . io . IOException { getSerializedSize ( ) ; if ( ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { output . writeBytes ( <NUM_LIT:1> , getClassnameBytes ( ) ) ; } if ( ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { output . writeBytes ( <NUM_LIT:2> , val_ ) ; } getUnknownFields ( ) . writeTo ( output ) ; } private int memoizedSerializedSize = - <NUM_LIT:1> ; public int getSerializedSize ( ) { int size = memoizedSerializedSize ; if ( size != - <NUM_LIT:1> ) return size ; size = <NUM_LIT:0> ; if ( ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { size += com . google . protobuf . CodedOutputStream . computeBytesSize ( <NUM_LIT:1> , getClassnameBytes ( ) ) ; } if ( ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { size += com . google . protobuf . CodedOutputStream . computeBytesSize ( <NUM_LIT:2> , val_ ) ; } size += getUnknownFields ( ) . getSerializedSize ( ) ; memoizedSerializedSize = size ; return size ; } @ java . lang . Override protected Object writeReplace ( ) throws java . io . ObjectStreamException { return super . writeReplace ( ) ; } public static com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest parseFrom ( com . google . protobuf . ByteString data ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest parseFrom ( com . google . protobuf . ByteString data , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest parseFrom ( byte [ ] data ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest parseFrom ( byte [ ] data , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest parseFrom ( java . io . InputStream input ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest parseFrom ( java . io . InputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest parseDelimitedFrom ( java . io . InputStream input ) throws java . io . IOException { Builder builder = newBuilder ( ) ; if ( builder . mergeDelimitedFrom ( input ) ) { return builder . buildParsed ( ) ; } else { return null ; } } public static com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest parseDelimitedFrom ( java . io . InputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { Builder builder = newBuilder ( ) ; if ( builder . mergeDelimitedFrom ( input , extensionRegistry ) ) { return builder . buildParsed ( ) ; } else { return null ; } } public static com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest parseFrom ( com . google . protobuf . CodedInputStream input ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest parseFrom ( com . google . protobuf . CodedInputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input , extensionRegistry ) . buildParsed ( ) ; } public static Builder newBuilder ( ) { return Builder . create ( ) ; } public Builder newBuilderForType ( ) { return newBuilder ( ) ; } public static Builder newBuilder ( com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest prototype ) { return newBuilder ( ) . mergeFrom ( prototype ) ; } public Builder toBuilder ( ) { return newBuilder ( this ) ; } @ java . lang . Override protected Builder newBuilderForType ( com . google . protobuf . GeneratedMessage . BuilderParent parent ) { Builder builder = new Builder ( parent ) ; return builder ; } public static final class Builder extends com . google . protobuf . GeneratedMessage . Builder < Builder > implements com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequestOrBuilder { public static final com . google . protobuf . Descriptors . Descriptor getDescriptor ( ) { return com . sensei . search . req . protobuf . SenseiGenericRequestBPO . internal_static_com_sensei_search_req_protobuf_GenericRequest_descriptor ; } protected com . google . protobuf . GeneratedMessage . FieldAccessorTable internalGetFieldAccessorTable ( ) { return com . sensei . search . req . protobuf . SenseiGenericRequestBPO . internal_static_com_sensei_search_req_protobuf_GenericRequest_fieldAccessorTable ; } private Builder ( ) { maybeForceBuilderInitialization ( ) ; } private Builder ( BuilderParent parent ) { super ( parent ) ; maybeForceBuilderInitialization ( ) ; } private void maybeForceBuilderInitialization ( ) { if ( com . google . protobuf . GeneratedMessage . alwaysUseFieldBuilders ) { } } private static Builder create ( ) { return new Builder ( ) ; } public Builder clear ( ) { super . clear ( ) ; classname_ = "<STR_LIT>" ; bitField0_ = ( bitField0_ & ~ <NUM_LIT> ) ; val_ = com . google . protobuf . ByteString . EMPTY ; bitField0_ = ( bitField0_ & ~ <NUM_LIT> ) ; return this ; } public Builder clone ( ) { return create ( ) . mergeFrom ( buildPartial ( ) ) ; } public com . google . protobuf . Descriptors . Descriptor getDescriptorForType ( ) { return com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest . getDescriptor ( ) ; } public com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest getDefaultInstanceForType ( ) { return com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest . getDefaultInstance ( ) ; } public com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest build ( ) { com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest result = buildPartial ( ) ; if ( ! result . isInitialized ( ) ) { throw newUninitializedMessageException ( result ) ; } return result ; } private com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest buildParsed ( ) throws com . google . protobuf . InvalidProtocolBufferException { com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest result = buildPartial ( ) ; if ( ! result . isInitialized ( ) ) { throw newUninitializedMessageException ( result ) . asInvalidProtocolBufferException ( ) ; } return result ; } public com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest buildPartial ( ) { com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest result = new com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest ( this ) ; int from_bitField0_ = bitField0_ ; int to_bitField0_ = <NUM_LIT:0> ; if ( ( ( from_bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { to_bitField0_ |= <NUM_LIT> ; } result . classname_ = classname_ ; if ( ( ( from_bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { to_bitField0_ |= <NUM_LIT> ; } result . val_ = val_ ; result . bitField0_ = to_bitField0_ ; onBuilt ( ) ; return result ; } public Builder mergeFrom ( com . google . protobuf . Message other ) { if ( other instanceof com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest ) { return mergeFrom ( ( com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest ) other ) ; } else { super . mergeFrom ( other ) ; return this ; } } public Builder mergeFrom ( com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest other ) { if ( other == com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest . getDefaultInstance ( ) ) return this ; if ( other . hasClassname ( ) ) { setClassname ( other . getClassname ( ) ) ; } if ( other . hasVal ( ) ) { setVal ( other . getVal ( ) ) ; } this . mergeUnknownFields ( other . getUnknownFields ( ) ) ; return this ; } public final boolean isInitialized ( ) { if ( ! hasClassname ( ) ) { return false ; } if ( ! hasVal ( ) ) { return false ; } return true ; } public Builder mergeFrom ( com . google . protobuf . CodedInputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { com . google . protobuf . UnknownFieldSet . Builder unknownFields = com . google . protobuf . UnknownFieldSet . newBuilder ( this . getUnknownFields ( ) ) ; while ( true ) { int tag = input . readTag ( ) ; switch ( tag ) { case <NUM_LIT:0> : this . setUnknownFields ( unknownFields . build ( ) ) ; onChanged ( ) ; return this ; default : { if ( ! parseUnknownField ( input , unknownFields , extensionRegistry , tag ) ) { this . setUnknownFields ( unknownFields . build ( ) ) ; onChanged ( ) ; return this ; } break ; } case <NUM_LIT:10> : { bitField0_ |= <NUM_LIT> ; classname_ = input . readBytes ( ) ; break ; } case <NUM_LIT> : { bitField0_ |= <NUM_LIT> ; val_ = input . readBytes ( ) ; break ; } } } } private int bitField0_ ; private Object classname_ = "<STR_LIT>" ; public boolean hasClassname ( ) { return ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ; } public String getClassname ( ) { Object ref = classname_ ; if ( ! ( ref instanceof String ) ) { String s = ( ( com . google . protobuf . ByteString ) ref ) . toStringUtf8 ( ) ; classname_ = s ; return s ; } else { return ( String ) ref ; } } public Builder setClassname ( String value ) { if ( value == null ) { throw new NullPointerException ( ) ; } bitField0_ |= <NUM_LIT> ; classname_ = value ; onChanged ( ) ; return this ; } public Builder clearClassname ( ) { bitField0_ = ( bitField0_ & ~ <NUM_LIT> ) ; classname_ = getDefaultInstance ( ) . getClassname ( ) ; onChanged ( ) ; return this ; } void setClassname ( com . google . protobuf . ByteString value ) { bitField0_ |= <NUM_LIT> ; classname_ = value ; onChanged ( ) ; } private com . google . protobuf . ByteString val_ = com . google . protobuf . ByteString . EMPTY ; public boolean hasVal ( ) { return ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ; } public com . google . protobuf . ByteString getVal ( ) { return val_ ; } public Builder setVal ( com . google . protobuf . ByteString value ) { if ( value == null ) { throw new NullPointerException ( ) ; } bitField0_ |= <NUM_LIT> ; val_ = value ; onChanged ( ) ; return this ; } public Builder clearVal ( ) { bitField0_ = ( bitField0_ & ~ <NUM_LIT> ) ; val_ = getDefaultInstance ( ) . getVal ( ) ; onChanged ( ) ; return this ; } } static { defaultInstance = new GenericRequest ( true ) ; defaultInstance . initFields ( ) ; } } private static com . google . protobuf . Descriptors . Descriptor internal_static_com_sensei_search_req_protobuf_GenericRequest_descriptor ; private static com . google . protobuf . GeneratedMessage . FieldAccessorTable internal_static_com_sensei_search_req_protobuf_GenericRequest_fieldAccessorTable ; public static com . google . protobuf . Descriptors . FileDescriptor getDescriptor ( ) { return descriptor ; } private static com . google . protobuf . Descriptors . FileDescriptor descriptor ; static { java . lang . String [ ] descriptorData = { "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" } ; com . google . protobuf . Descriptors . FileDescriptor . InternalDescriptorAssigner assigner = new com . google . protobuf . Descriptors . FileDescriptor . InternalDescriptorAssigner ( ) { public com . google . protobuf . ExtensionRegistry assignDescriptors ( com . google . protobuf . Descriptors . FileDescriptor root ) { descriptor = root ; internal_static_com_sensei_search_req_protobuf_GenericRequest_descriptor = getDescriptor ( ) . getMessageTypes ( ) . get ( <NUM_LIT:0> ) ; internal_static_com_sensei_search_req_protobuf_GenericRequest_fieldAccessorTable = new com . google . protobuf . GeneratedMessage . FieldAccessorTable ( internal_static_com_sensei_search_req_protobuf_GenericRequest_descriptor , new java . lang . String [ ] { "<STR_LIT>" , "<STR_LIT>" , } , com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest . class , com . sensei . search . req . protobuf . SenseiGenericRequestBPO . GenericRequest . Builder . class ) ; return null ; } } ; com . google . protobuf . Descriptors . FileDescriptor . internalBuildGeneratedFileFrom ( descriptorData , new com . google . protobuf . Descriptors . FileDescriptor [ ] { } , assigner ) ; } } </s>
<s> package com . sensei . search . req . protobuf ; public final class SenseiSysResultBPO { private SenseiSysResultBPO ( ) { } public static void registerAllExtensions ( com . google . protobuf . ExtensionRegistry registry ) { } public interface SysResultOrBuilder extends com . google . protobuf . MessageOrBuilder { boolean hasVal ( ) ; com . google . protobuf . ByteString getVal ( ) ; } public static final class SysResult extends com . google . protobuf . GeneratedMessage implements SysResultOrBuilder { private SysResult ( Builder builder ) { super ( builder ) ; } private SysResult ( boolean noInit ) { } private static final SysResult defaultInstance ; public static SysResult getDefaultInstance ( ) { return defaultInstance ; } public SysResult getDefaultInstanceForType ( ) { return defaultInstance ; } public static final com . google . protobuf . Descriptors . Descriptor getDescriptor ( ) { return com . sensei . search . req . protobuf . SenseiSysResultBPO . internal_static_com_sensei_search_req_protobuf_SysResult_descriptor ; } protected com . google . protobuf . GeneratedMessage . FieldAccessorTable internalGetFieldAccessorTable ( ) { return com . sensei . search . req . protobuf . SenseiSysResultBPO . internal_static_com_sensei_search_req_protobuf_SysResult_fieldAccessorTable ; } private int bitField0_ ; public static final int VAL_FIELD_NUMBER = <NUM_LIT:1> ; private com . google . protobuf . ByteString val_ ; public boolean hasVal ( ) { return ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ; } public com . google . protobuf . ByteString getVal ( ) { return val_ ; } private void initFields ( ) { val_ = com . google . protobuf . ByteString . EMPTY ; } private byte memoizedIsInitialized = - <NUM_LIT:1> ; public final boolean isInitialized ( ) { byte isInitialized = memoizedIsInitialized ; if ( isInitialized != - <NUM_LIT:1> ) return isInitialized == <NUM_LIT:1> ; if ( ! hasVal ( ) ) { memoizedIsInitialized = <NUM_LIT:0> ; return false ; } memoizedIsInitialized = <NUM_LIT:1> ; return true ; } public void writeTo ( com . google . protobuf . CodedOutputStream output ) throws java . io . IOException { getSerializedSize ( ) ; if ( ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { output . writeBytes ( <NUM_LIT:1> , val_ ) ; } getUnknownFields ( ) . writeTo ( output ) ; } private int memoizedSerializedSize = - <NUM_LIT:1> ; public int getSerializedSize ( ) { int size = memoizedSerializedSize ; if ( size != - <NUM_LIT:1> ) return size ; size = <NUM_LIT:0> ; if ( ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { size += com . google . protobuf . CodedOutputStream . computeBytesSize ( <NUM_LIT:1> , val_ ) ; } size += getUnknownFields ( ) . getSerializedSize ( ) ; memoizedSerializedSize = size ; return size ; } @ java . lang . Override protected Object writeReplace ( ) throws java . io . ObjectStreamException { return super . writeReplace ( ) ; } public static com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult parseFrom ( com . google . protobuf . ByteString data ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult parseFrom ( com . google . protobuf . ByteString data , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult parseFrom ( byte [ ] data ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult parseFrom ( byte [ ] data , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult parseFrom ( java . io . InputStream input ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult parseFrom ( java . io . InputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult parseDelimitedFrom ( java . io . InputStream input ) throws java . io . IOException { Builder builder = newBuilder ( ) ; if ( builder . mergeDelimitedFrom ( input ) ) { return builder . buildParsed ( ) ; } else { return null ; } } public static com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult parseDelimitedFrom ( java . io . InputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { Builder builder = newBuilder ( ) ; if ( builder . mergeDelimitedFrom ( input , extensionRegistry ) ) { return builder . buildParsed ( ) ; } else { return null ; } } public static com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult parseFrom ( com . google . protobuf . CodedInputStream input ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult parseFrom ( com . google . protobuf . CodedInputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input , extensionRegistry ) . buildParsed ( ) ; } public static Builder newBuilder ( ) { return Builder . create ( ) ; } public Builder newBuilderForType ( ) { return newBuilder ( ) ; } public static Builder newBuilder ( com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult prototype ) { return newBuilder ( ) . mergeFrom ( prototype ) ; } public Builder toBuilder ( ) { return newBuilder ( this ) ; } @ java . lang . Override protected Builder newBuilderForType ( com . google . protobuf . GeneratedMessage . BuilderParent parent ) { Builder builder = new Builder ( parent ) ; return builder ; } public static final class Builder extends com . google . protobuf . GeneratedMessage . Builder < Builder > implements com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResultOrBuilder { public static final com . google . protobuf . Descriptors . Descriptor getDescriptor ( ) { return com . sensei . search . req . protobuf . SenseiSysResultBPO . internal_static_com_sensei_search_req_protobuf_SysResult_descriptor ; } protected com . google . protobuf . GeneratedMessage . FieldAccessorTable internalGetFieldAccessorTable ( ) { return com . sensei . search . req . protobuf . SenseiSysResultBPO . internal_static_com_sensei_search_req_protobuf_SysResult_fieldAccessorTable ; } private Builder ( ) { maybeForceBuilderInitialization ( ) ; } private Builder ( BuilderParent parent ) { super ( parent ) ; maybeForceBuilderInitialization ( ) ; } private void maybeForceBuilderInitialization ( ) { if ( com . google . protobuf . GeneratedMessage . alwaysUseFieldBuilders ) { } } private static Builder create ( ) { return new Builder ( ) ; } public Builder clear ( ) { super . clear ( ) ; val_ = com . google . protobuf . ByteString . EMPTY ; bitField0_ = ( bitField0_ & ~ <NUM_LIT> ) ; return this ; } public Builder clone ( ) { return create ( ) . mergeFrom ( buildPartial ( ) ) ; } public com . google . protobuf . Descriptors . Descriptor getDescriptorForType ( ) { return com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult . getDescriptor ( ) ; } public com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult getDefaultInstanceForType ( ) { return com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult . getDefaultInstance ( ) ; } public com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult build ( ) { com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult result = buildPartial ( ) ; if ( ! result . isInitialized ( ) ) { throw newUninitializedMessageException ( result ) ; } return result ; } private com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult buildParsed ( ) throws com . google . protobuf . InvalidProtocolBufferException { com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult result = buildPartial ( ) ; if ( ! result . isInitialized ( ) ) { throw newUninitializedMessageException ( result ) . asInvalidProtocolBufferException ( ) ; } return result ; } public com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult buildPartial ( ) { com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult result = new com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult ( this ) ; int from_bitField0_ = bitField0_ ; int to_bitField0_ = <NUM_LIT:0> ; if ( ( ( from_bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { to_bitField0_ |= <NUM_LIT> ; } result . val_ = val_ ; result . bitField0_ = to_bitField0_ ; onBuilt ( ) ; return result ; } public Builder mergeFrom ( com . google . protobuf . Message other ) { if ( other instanceof com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult ) { return mergeFrom ( ( com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult ) other ) ; } else { super . mergeFrom ( other ) ; return this ; } } public Builder mergeFrom ( com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult other ) { if ( other == com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult . getDefaultInstance ( ) ) return this ; if ( other . hasVal ( ) ) { setVal ( other . getVal ( ) ) ; } this . mergeUnknownFields ( other . getUnknownFields ( ) ) ; return this ; } public final boolean isInitialized ( ) { if ( ! hasVal ( ) ) { return false ; } return true ; } public Builder mergeFrom ( com . google . protobuf . CodedInputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { com . google . protobuf . UnknownFieldSet . Builder unknownFields = com . google . protobuf . UnknownFieldSet . newBuilder ( this . getUnknownFields ( ) ) ; while ( true ) { int tag = input . readTag ( ) ; switch ( tag ) { case <NUM_LIT:0> : this . setUnknownFields ( unknownFields . build ( ) ) ; onChanged ( ) ; return this ; default : { if ( ! parseUnknownField ( input , unknownFields , extensionRegistry , tag ) ) { this . setUnknownFields ( unknownFields . build ( ) ) ; onChanged ( ) ; return this ; } break ; } case <NUM_LIT:10> : { bitField0_ |= <NUM_LIT> ; val_ = input . readBytes ( ) ; break ; } } } } private int bitField0_ ; private com . google . protobuf . ByteString val_ = com . google . protobuf . ByteString . EMPTY ; public boolean hasVal ( ) { return ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ; } public com . google . protobuf . ByteString getVal ( ) { return val_ ; } public Builder setVal ( com . google . protobuf . ByteString value ) { if ( value == null ) { throw new NullPointerException ( ) ; } bitField0_ |= <NUM_LIT> ; val_ = value ; onChanged ( ) ; return this ; } public Builder clearVal ( ) { bitField0_ = ( bitField0_ & ~ <NUM_LIT> ) ; val_ = getDefaultInstance ( ) . getVal ( ) ; onChanged ( ) ; return this ; } } static { defaultInstance = new SysResult ( true ) ; defaultInstance . initFields ( ) ; } } private static com . google . protobuf . Descriptors . Descriptor internal_static_com_sensei_search_req_protobuf_SysResult_descriptor ; private static com . google . protobuf . GeneratedMessage . FieldAccessorTable internal_static_com_sensei_search_req_protobuf_SysResult_fieldAccessorTable ; public static com . google . protobuf . Descriptors . FileDescriptor getDescriptor ( ) { return descriptor ; } private static com . google . protobuf . Descriptors . FileDescriptor descriptor ; static { java . lang . String [ ] descriptorData = { "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" } ; com . google . protobuf . Descriptors . FileDescriptor . InternalDescriptorAssigner assigner = new com . google . protobuf . Descriptors . FileDescriptor . InternalDescriptorAssigner ( ) { public com . google . protobuf . ExtensionRegistry assignDescriptors ( com . google . protobuf . Descriptors . FileDescriptor root ) { descriptor = root ; internal_static_com_sensei_search_req_protobuf_SysResult_descriptor = getDescriptor ( ) . getMessageTypes ( ) . get ( <NUM_LIT:0> ) ; internal_static_com_sensei_search_req_protobuf_SysResult_fieldAccessorTable = new com . google . protobuf . GeneratedMessage . FieldAccessorTable ( internal_static_com_sensei_search_req_protobuf_SysResult_descriptor , new java . lang . String [ ] { "<STR_LIT>" , } , com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult . class , com . sensei . search . req . protobuf . SenseiSysResultBPO . SysResult . Builder . class ) ; return null ; } } ; com . google . protobuf . Descriptors . FileDescriptor . internalBuildGeneratedFileFrom ( descriptorData , new com . google . protobuf . Descriptors . FileDescriptor [ ] { } , assigner ) ; } } </s>
<s> package com . sensei . search . req . protobuf ; public final class SenseiSysRequestBPO { private SenseiSysRequestBPO ( ) { } public static void registerAllExtensions ( com . google . protobuf . ExtensionRegistry registry ) { } public interface SysRequestOrBuilder extends com . google . protobuf . MessageOrBuilder { boolean hasVal ( ) ; com . google . protobuf . ByteString getVal ( ) ; } public static final class SysRequest extends com . google . protobuf . GeneratedMessage implements SysRequestOrBuilder { private SysRequest ( Builder builder ) { super ( builder ) ; } private SysRequest ( boolean noInit ) { } private static final SysRequest defaultInstance ; public static SysRequest getDefaultInstance ( ) { return defaultInstance ; } public SysRequest getDefaultInstanceForType ( ) { return defaultInstance ; } public static final com . google . protobuf . Descriptors . Descriptor getDescriptor ( ) { return com . sensei . search . req . protobuf . SenseiSysRequestBPO . internal_static_com_sensei_search_req_protobuf_SysRequest_descriptor ; } protected com . google . protobuf . GeneratedMessage . FieldAccessorTable internalGetFieldAccessorTable ( ) { return com . sensei . search . req . protobuf . SenseiSysRequestBPO . internal_static_com_sensei_search_req_protobuf_SysRequest_fieldAccessorTable ; } private int bitField0_ ; public static final int VAL_FIELD_NUMBER = <NUM_LIT:1> ; private com . google . protobuf . ByteString val_ ; public boolean hasVal ( ) { return ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ; } public com . google . protobuf . ByteString getVal ( ) { return val_ ; } private void initFields ( ) { val_ = com . google . protobuf . ByteString . EMPTY ; } private byte memoizedIsInitialized = - <NUM_LIT:1> ; public final boolean isInitialized ( ) { byte isInitialized = memoizedIsInitialized ; if ( isInitialized != - <NUM_LIT:1> ) return isInitialized == <NUM_LIT:1> ; if ( ! hasVal ( ) ) { memoizedIsInitialized = <NUM_LIT:0> ; return false ; } memoizedIsInitialized = <NUM_LIT:1> ; return true ; } public void writeTo ( com . google . protobuf . CodedOutputStream output ) throws java . io . IOException { getSerializedSize ( ) ; if ( ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { output . writeBytes ( <NUM_LIT:1> , val_ ) ; } getUnknownFields ( ) . writeTo ( output ) ; } private int memoizedSerializedSize = - <NUM_LIT:1> ; public int getSerializedSize ( ) { int size = memoizedSerializedSize ; if ( size != - <NUM_LIT:1> ) return size ; size = <NUM_LIT:0> ; if ( ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { size += com . google . protobuf . CodedOutputStream . computeBytesSize ( <NUM_LIT:1> , val_ ) ; } size += getUnknownFields ( ) . getSerializedSize ( ) ; memoizedSerializedSize = size ; return size ; } @ java . lang . Override protected Object writeReplace ( ) throws java . io . ObjectStreamException { return super . writeReplace ( ) ; } public static com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest parseFrom ( com . google . protobuf . ByteString data ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest parseFrom ( com . google . protobuf . ByteString data , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest parseFrom ( byte [ ] data ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest parseFrom ( byte [ ] data , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest parseFrom ( java . io . InputStream input ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest parseFrom ( java . io . InputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest parseDelimitedFrom ( java . io . InputStream input ) throws java . io . IOException { Builder builder = newBuilder ( ) ; if ( builder . mergeDelimitedFrom ( input ) ) { return builder . buildParsed ( ) ; } else { return null ; } } public static com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest parseDelimitedFrom ( java . io . InputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { Builder builder = newBuilder ( ) ; if ( builder . mergeDelimitedFrom ( input , extensionRegistry ) ) { return builder . buildParsed ( ) ; } else { return null ; } } public static com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest parseFrom ( com . google . protobuf . CodedInputStream input ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest parseFrom ( com . google . protobuf . CodedInputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input , extensionRegistry ) . buildParsed ( ) ; } public static Builder newBuilder ( ) { return Builder . create ( ) ; } public Builder newBuilderForType ( ) { return newBuilder ( ) ; } public static Builder newBuilder ( com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest prototype ) { return newBuilder ( ) . mergeFrom ( prototype ) ; } public Builder toBuilder ( ) { return newBuilder ( this ) ; } @ java . lang . Override protected Builder newBuilderForType ( com . google . protobuf . GeneratedMessage . BuilderParent parent ) { Builder builder = new Builder ( parent ) ; return builder ; } public static final class Builder extends com . google . protobuf . GeneratedMessage . Builder < Builder > implements com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequestOrBuilder { public static final com . google . protobuf . Descriptors . Descriptor getDescriptor ( ) { return com . sensei . search . req . protobuf . SenseiSysRequestBPO . internal_static_com_sensei_search_req_protobuf_SysRequest_descriptor ; } protected com . google . protobuf . GeneratedMessage . FieldAccessorTable internalGetFieldAccessorTable ( ) { return com . sensei . search . req . protobuf . SenseiSysRequestBPO . internal_static_com_sensei_search_req_protobuf_SysRequest_fieldAccessorTable ; } private Builder ( ) { maybeForceBuilderInitialization ( ) ; } private Builder ( BuilderParent parent ) { super ( parent ) ; maybeForceBuilderInitialization ( ) ; } private void maybeForceBuilderInitialization ( ) { if ( com . google . protobuf . GeneratedMessage . alwaysUseFieldBuilders ) { } } private static Builder create ( ) { return new Builder ( ) ; } public Builder clear ( ) { super . clear ( ) ; val_ = com . google . protobuf . ByteString . EMPTY ; bitField0_ = ( bitField0_ & ~ <NUM_LIT> ) ; return this ; } public Builder clone ( ) { return create ( ) . mergeFrom ( buildPartial ( ) ) ; } public com . google . protobuf . Descriptors . Descriptor getDescriptorForType ( ) { return com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest . getDescriptor ( ) ; } public com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest getDefaultInstanceForType ( ) { return com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest . getDefaultInstance ( ) ; } public com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest build ( ) { com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest result = buildPartial ( ) ; if ( ! result . isInitialized ( ) ) { throw newUninitializedMessageException ( result ) ; } return result ; } private com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest buildParsed ( ) throws com . google . protobuf . InvalidProtocolBufferException { com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest result = buildPartial ( ) ; if ( ! result . isInitialized ( ) ) { throw newUninitializedMessageException ( result ) . asInvalidProtocolBufferException ( ) ; } return result ; } public com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest buildPartial ( ) { com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest result = new com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest ( this ) ; int from_bitField0_ = bitField0_ ; int to_bitField0_ = <NUM_LIT:0> ; if ( ( ( from_bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { to_bitField0_ |= <NUM_LIT> ; } result . val_ = val_ ; result . bitField0_ = to_bitField0_ ; onBuilt ( ) ; return result ; } public Builder mergeFrom ( com . google . protobuf . Message other ) { if ( other instanceof com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest ) { return mergeFrom ( ( com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest ) other ) ; } else { super . mergeFrom ( other ) ; return this ; } } public Builder mergeFrom ( com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest other ) { if ( other == com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest . getDefaultInstance ( ) ) return this ; if ( other . hasVal ( ) ) { setVal ( other . getVal ( ) ) ; } this . mergeUnknownFields ( other . getUnknownFields ( ) ) ; return this ; } public final boolean isInitialized ( ) { if ( ! hasVal ( ) ) { return false ; } return true ; } public Builder mergeFrom ( com . google . protobuf . CodedInputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { com . google . protobuf . UnknownFieldSet . Builder unknownFields = com . google . protobuf . UnknownFieldSet . newBuilder ( this . getUnknownFields ( ) ) ; while ( true ) { int tag = input . readTag ( ) ; switch ( tag ) { case <NUM_LIT:0> : this . setUnknownFields ( unknownFields . build ( ) ) ; onChanged ( ) ; return this ; default : { if ( ! parseUnknownField ( input , unknownFields , extensionRegistry , tag ) ) { this . setUnknownFields ( unknownFields . build ( ) ) ; onChanged ( ) ; return this ; } break ; } case <NUM_LIT:10> : { bitField0_ |= <NUM_LIT> ; val_ = input . readBytes ( ) ; break ; } } } } private int bitField0_ ; private com . google . protobuf . ByteString val_ = com . google . protobuf . ByteString . EMPTY ; public boolean hasVal ( ) { return ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ; } public com . google . protobuf . ByteString getVal ( ) { return val_ ; } public Builder setVal ( com . google . protobuf . ByteString value ) { if ( value == null ) { throw new NullPointerException ( ) ; } bitField0_ |= <NUM_LIT> ; val_ = value ; onChanged ( ) ; return this ; } public Builder clearVal ( ) { bitField0_ = ( bitField0_ & ~ <NUM_LIT> ) ; val_ = getDefaultInstance ( ) . getVal ( ) ; onChanged ( ) ; return this ; } } static { defaultInstance = new SysRequest ( true ) ; defaultInstance . initFields ( ) ; } } private static com . google . protobuf . Descriptors . Descriptor internal_static_com_sensei_search_req_protobuf_SysRequest_descriptor ; private static com . google . protobuf . GeneratedMessage . FieldAccessorTable internal_static_com_sensei_search_req_protobuf_SysRequest_fieldAccessorTable ; public static com . google . protobuf . Descriptors . FileDescriptor getDescriptor ( ) { return descriptor ; } private static com . google . protobuf . Descriptors . FileDescriptor descriptor ; static { java . lang . String [ ] descriptorData = { "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" } ; com . google . protobuf . Descriptors . FileDescriptor . InternalDescriptorAssigner assigner = new com . google . protobuf . Descriptors . FileDescriptor . InternalDescriptorAssigner ( ) { public com . google . protobuf . ExtensionRegistry assignDescriptors ( com . google . protobuf . Descriptors . FileDescriptor root ) { descriptor = root ; internal_static_com_sensei_search_req_protobuf_SysRequest_descriptor = getDescriptor ( ) . getMessageTypes ( ) . get ( <NUM_LIT:0> ) ; internal_static_com_sensei_search_req_protobuf_SysRequest_fieldAccessorTable = new com . google . protobuf . GeneratedMessage . FieldAccessorTable ( internal_static_com_sensei_search_req_protobuf_SysRequest_descriptor , new java . lang . String [ ] { "<STR_LIT>" , } , com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest . class , com . sensei . search . req . protobuf . SenseiSysRequestBPO . SysRequest . Builder . class ) ; return null ; } } ; com . google . protobuf . Descriptors . FileDescriptor . internalBuildGeneratedFileFrom ( descriptorData , new com . google . protobuf . Descriptors . FileDescriptor [ ] { } , assigner ) ; } } </s>
<s> package com . sensei . search . req . protobuf ; import com . google . protobuf . ByteString ; import com . google . protobuf . InvalidProtocolBufferException ; import com . google . protobuf . TextFormat ; import com . linkedin . norbert . network . Serializer ; import com . senseidb . search . req . SenseiRequest ; import com . senseidb . search . req . SenseiSystemInfo ; public class SenseiSysReqProtoSerializer implements Serializer < SenseiRequest , SenseiSystemInfo > { public String requestName ( ) { return SenseiSysRequestBPO . getDescriptor ( ) . getName ( ) ; } public String responseName ( ) { return SenseiSysResultBPO . getDescriptor ( ) . getName ( ) ; } public byte [ ] requestToBytes ( SenseiRequest request ) { return SenseiRequestBPO . Request . newBuilder ( ) . setVal ( serialize ( request ) ) . build ( ) . toByteArray ( ) ; } public byte [ ] responseToBytes ( SenseiSystemInfo response ) { return SenseiSysResultBPO . SysResult . newBuilder ( ) . setVal ( serialize ( response ) ) . build ( ) . toByteArray ( ) ; } private < T > ByteString serialize ( T obj ) { try { return ProtoConvertUtil . serializeOut ( obj ) ; } catch ( TextFormat . ParseException e ) { throw new RuntimeException ( e ) ; } } public SenseiRequest requestFromBytes ( byte [ ] request ) { try { return ( SenseiRequest ) ProtoConvertUtil . serializeIn ( SenseiRequestBPO . Request . newBuilder ( ) . mergeFrom ( request ) . build ( ) . getVal ( ) ) ; } catch ( TextFormat . ParseException e ) { throw new RuntimeException ( e ) ; } catch ( InvalidProtocolBufferException e ) { throw new RuntimeException ( e ) ; } } public SenseiSystemInfo responseFromBytes ( byte [ ] result ) { try { return ( SenseiSystemInfo ) ProtoConvertUtil . serializeIn ( SenseiSysResultBPO . SysResult . newBuilder ( ) . mergeFrom ( result ) . build ( ) . getVal ( ) ) ; } catch ( TextFormat . ParseException e ) { throw new RuntimeException ( e ) ; } catch ( InvalidProtocolBufferException e ) { throw new RuntimeException ( e ) ; } } } </s>
<s> package com . sensei . search . req . protobuf ; import java . io . ByteArrayInputStream ; import java . io . ByteArrayOutputStream ; import java . io . IOException ; import java . io . ObjectInputStream ; import java . io . ObjectOutputStream ; import java . io . Serializable ; import java . util . LinkedList ; import java . util . List ; import java . util . zip . GZIPInputStream ; import java . util . zip . GZIPOutputStream ; import com . senseidb . search . req . SenseiGenericRequest ; import com . senseidb . search . req . SenseiGenericResult ; import org . apache . log4j . Logger ; import com . google . protobuf . ByteString ; public class SenseiGenericBPOConverter { private static Logger logger = Logger . getLogger ( SenseiGenericBPOConverter . class ) ; public static SenseiGenericRequest convert ( SenseiGenericRequestBPO . GenericRequest req ) { try { String classname = req . getClassname ( ) ; ByteString value = req . getVal ( ) ; byte [ ] raw = value . toByteArray ( ) ; ByteArrayInputStream bais = new ByteArrayInputStream ( raw ) ; ObjectInputStream ois = new ObjectInputStream ( bais ) ; SenseiGenericRequest ret = new SenseiGenericRequest ( ) ; ret . setClassname ( classname ) ; ret . setRequest ( ( Serializable ) ois . readObject ( ) ) ; return ret ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } return ( SenseiGenericRequest ) null ; } public static SenseiGenericRequestBPO . GenericRequest convert ( SenseiGenericRequest req ) { SenseiGenericRequestBPO . GenericRequest . Builder builder = SenseiGenericRequestBPO . GenericRequest . newBuilder ( ) ; try { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; ObjectOutputStream oos ; oos = new ObjectOutputStream ( baos ) ; oos . writeObject ( req . getRequest ( ) ) ; oos . close ( ) ; byte [ ] raw = baos . toByteArray ( ) ; builder . setClassname ( req . getClassname ( ) ) ; builder . setVal ( ByteString . copyFrom ( raw ) ) ; return builder . build ( ) ; } catch ( IOException e ) { logger . error ( "<STR_LIT>" , e ) ; } return SenseiGenericRequestBPO . GenericRequest . getDefaultInstance ( ) ; } public static SenseiGenericResult convert ( SenseiGenericResultBPO . GenericResult req ) { try { String classname = req . getClassname ( ) ; ByteString value = req . getVal ( ) ; byte [ ] raw = value . toByteArray ( ) ; ByteArrayInputStream bais = new ByteArrayInputStream ( raw ) ; ObjectInputStream ois = new ObjectInputStream ( bais ) ; SenseiGenericResult ret = new SenseiGenericResult ( ) ; ret . setClassname ( classname ) ; ret . setResult ( ( Serializable ) ois . readObject ( ) ) ; return ret ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } return ( SenseiGenericResult ) null ; } public static SenseiGenericResultBPO . GenericResult convert ( SenseiGenericResult req ) { SenseiGenericResultBPO . GenericResult . Builder builder = SenseiGenericResultBPO . GenericResult . newBuilder ( ) ; try { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; ObjectOutputStream oos ; oos = new ObjectOutputStream ( baos ) ; oos . writeObject ( req . getResult ( ) ) ; oos . close ( ) ; byte [ ] raw = baos . toByteArray ( ) ; builder . setClassname ( req . getClassname ( ) ) ; builder . setVal ( ByteString . copyFrom ( raw ) ) ; return builder . build ( ) ; } catch ( IOException e ) { logger . error ( "<STR_LIT>" , e ) ; } return SenseiGenericResultBPO . GenericResult . getDefaultInstance ( ) ; } public static byte [ ] decompress ( byte [ ] output ) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream ( output ) ; GZIPInputStream gzis = new GZIPInputStream ( bais ) ; byte [ ] buf = new byte [ <NUM_LIT> ] ; List < byte [ ] > list = new LinkedList < byte [ ] > ( ) ; int len = gzis . read ( buf , <NUM_LIT:0> , <NUM_LIT> ) ; int i = <NUM_LIT:0> ; while ( len > <NUM_LIT:0> ) { byte [ ] b1 = new byte [ len ] ; System . arraycopy ( buf , <NUM_LIT:0> , b1 , <NUM_LIT:0> , len ) ; list . add ( b1 ) ; i += len ; len = gzis . read ( buf , <NUM_LIT:0> , <NUM_LIT> ) ; } gzis . close ( ) ; byte [ ] whole = new byte [ i ] ; int start = <NUM_LIT:0> ; for ( byte [ ] part : list ) { System . arraycopy ( part , <NUM_LIT:0> , whole , start , part . length ) ; start += part . length ; } return whole ; } public static byte [ ] compress ( byte [ ] b ) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; GZIPOutputStream gzos = new GZIPOutputStream ( baos ) ; gzos . write ( b ) ; gzos . close ( ) ; byte [ ] output = baos . toByteArray ( ) ; return output ; } } </s>
<s> package com . sensei . search . req . protobuf ; public final class SenseiResultBPO { private SenseiResultBPO ( ) { } public static void registerAllExtensions ( com . google . protobuf . ExtensionRegistry registry ) { } public interface ResultOrBuilder extends com . google . protobuf . MessageOrBuilder { boolean hasVal ( ) ; com . google . protobuf . ByteString getVal ( ) ; } public static final class Result extends com . google . protobuf . GeneratedMessage implements ResultOrBuilder { private Result ( Builder builder ) { super ( builder ) ; } private Result ( boolean noInit ) { } private static final Result defaultInstance ; public static Result getDefaultInstance ( ) { return defaultInstance ; } public Result getDefaultInstanceForType ( ) { return defaultInstance ; } public static final com . google . protobuf . Descriptors . Descriptor getDescriptor ( ) { return com . sensei . search . req . protobuf . SenseiResultBPO . internal_static_com_sensei_search_req_protobuf_Result_descriptor ; } protected com . google . protobuf . GeneratedMessage . FieldAccessorTable internalGetFieldAccessorTable ( ) { return com . sensei . search . req . protobuf . SenseiResultBPO . internal_static_com_sensei_search_req_protobuf_Result_fieldAccessorTable ; } private int bitField0_ ; public static final int VAL_FIELD_NUMBER = <NUM_LIT:1> ; private com . google . protobuf . ByteString val_ ; public boolean hasVal ( ) { return ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ; } public com . google . protobuf . ByteString getVal ( ) { return val_ ; } private void initFields ( ) { val_ = com . google . protobuf . ByteString . EMPTY ; } private byte memoizedIsInitialized = - <NUM_LIT:1> ; public final boolean isInitialized ( ) { byte isInitialized = memoizedIsInitialized ; if ( isInitialized != - <NUM_LIT:1> ) return isInitialized == <NUM_LIT:1> ; if ( ! hasVal ( ) ) { memoizedIsInitialized = <NUM_LIT:0> ; return false ; } memoizedIsInitialized = <NUM_LIT:1> ; return true ; } public void writeTo ( com . google . protobuf . CodedOutputStream output ) throws java . io . IOException { getSerializedSize ( ) ; if ( ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { output . writeBytes ( <NUM_LIT:1> , val_ ) ; } getUnknownFields ( ) . writeTo ( output ) ; } private int memoizedSerializedSize = - <NUM_LIT:1> ; public int getSerializedSize ( ) { int size = memoizedSerializedSize ; if ( size != - <NUM_LIT:1> ) return size ; size = <NUM_LIT:0> ; if ( ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { size += com . google . protobuf . CodedOutputStream . computeBytesSize ( <NUM_LIT:1> , val_ ) ; } size += getUnknownFields ( ) . getSerializedSize ( ) ; memoizedSerializedSize = size ; return size ; } @ java . lang . Override protected Object writeReplace ( ) throws java . io . ObjectStreamException { return super . writeReplace ( ) ; } public static com . sensei . search . req . protobuf . SenseiResultBPO . Result parseFrom ( com . google . protobuf . ByteString data ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiResultBPO . Result parseFrom ( com . google . protobuf . ByteString data , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiResultBPO . Result parseFrom ( byte [ ] data ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiResultBPO . Result parseFrom ( byte [ ] data , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws com . google . protobuf . InvalidProtocolBufferException { return newBuilder ( ) . mergeFrom ( data , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiResultBPO . Result parseFrom ( java . io . InputStream input ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiResultBPO . Result parseFrom ( java . io . InputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input , extensionRegistry ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiResultBPO . Result parseDelimitedFrom ( java . io . InputStream input ) throws java . io . IOException { Builder builder = newBuilder ( ) ; if ( builder . mergeDelimitedFrom ( input ) ) { return builder . buildParsed ( ) ; } else { return null ; } } public static com . sensei . search . req . protobuf . SenseiResultBPO . Result parseDelimitedFrom ( java . io . InputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { Builder builder = newBuilder ( ) ; if ( builder . mergeDelimitedFrom ( input , extensionRegistry ) ) { return builder . buildParsed ( ) ; } else { return null ; } } public static com . sensei . search . req . protobuf . SenseiResultBPO . Result parseFrom ( com . google . protobuf . CodedInputStream input ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input ) . buildParsed ( ) ; } public static com . sensei . search . req . protobuf . SenseiResultBPO . Result parseFrom ( com . google . protobuf . CodedInputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { return newBuilder ( ) . mergeFrom ( input , extensionRegistry ) . buildParsed ( ) ; } public static Builder newBuilder ( ) { return Builder . create ( ) ; } public Builder newBuilderForType ( ) { return newBuilder ( ) ; } public static Builder newBuilder ( com . sensei . search . req . protobuf . SenseiResultBPO . Result prototype ) { return newBuilder ( ) . mergeFrom ( prototype ) ; } public Builder toBuilder ( ) { return newBuilder ( this ) ; } @ java . lang . Override protected Builder newBuilderForType ( com . google . protobuf . GeneratedMessage . BuilderParent parent ) { Builder builder = new Builder ( parent ) ; return builder ; } public static final class Builder extends com . google . protobuf . GeneratedMessage . Builder < Builder > implements com . sensei . search . req . protobuf . SenseiResultBPO . ResultOrBuilder { public static final com . google . protobuf . Descriptors . Descriptor getDescriptor ( ) { return com . sensei . search . req . protobuf . SenseiResultBPO . internal_static_com_sensei_search_req_protobuf_Result_descriptor ; } protected com . google . protobuf . GeneratedMessage . FieldAccessorTable internalGetFieldAccessorTable ( ) { return com . sensei . search . req . protobuf . SenseiResultBPO . internal_static_com_sensei_search_req_protobuf_Result_fieldAccessorTable ; } private Builder ( ) { maybeForceBuilderInitialization ( ) ; } private Builder ( BuilderParent parent ) { super ( parent ) ; maybeForceBuilderInitialization ( ) ; } private void maybeForceBuilderInitialization ( ) { if ( com . google . protobuf . GeneratedMessage . alwaysUseFieldBuilders ) { } } private static Builder create ( ) { return new Builder ( ) ; } public Builder clear ( ) { super . clear ( ) ; val_ = com . google . protobuf . ByteString . EMPTY ; bitField0_ = ( bitField0_ & ~ <NUM_LIT> ) ; return this ; } public Builder clone ( ) { return create ( ) . mergeFrom ( buildPartial ( ) ) ; } public com . google . protobuf . Descriptors . Descriptor getDescriptorForType ( ) { return com . sensei . search . req . protobuf . SenseiResultBPO . Result . getDescriptor ( ) ; } public com . sensei . search . req . protobuf . SenseiResultBPO . Result getDefaultInstanceForType ( ) { return com . sensei . search . req . protobuf . SenseiResultBPO . Result . getDefaultInstance ( ) ; } public com . sensei . search . req . protobuf . SenseiResultBPO . Result build ( ) { com . sensei . search . req . protobuf . SenseiResultBPO . Result result = buildPartial ( ) ; if ( ! result . isInitialized ( ) ) { throw newUninitializedMessageException ( result ) ; } return result ; } private com . sensei . search . req . protobuf . SenseiResultBPO . Result buildParsed ( ) throws com . google . protobuf . InvalidProtocolBufferException { com . sensei . search . req . protobuf . SenseiResultBPO . Result result = buildPartial ( ) ; if ( ! result . isInitialized ( ) ) { throw newUninitializedMessageException ( result ) . asInvalidProtocolBufferException ( ) ; } return result ; } public com . sensei . search . req . protobuf . SenseiResultBPO . Result buildPartial ( ) { com . sensei . search . req . protobuf . SenseiResultBPO . Result result = new com . sensei . search . req . protobuf . SenseiResultBPO . Result ( this ) ; int from_bitField0_ = bitField0_ ; int to_bitField0_ = <NUM_LIT:0> ; if ( ( ( from_bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ) { to_bitField0_ |= <NUM_LIT> ; } result . val_ = val_ ; result . bitField0_ = to_bitField0_ ; onBuilt ( ) ; return result ; } public Builder mergeFrom ( com . google . protobuf . Message other ) { if ( other instanceof com . sensei . search . req . protobuf . SenseiResultBPO . Result ) { return mergeFrom ( ( com . sensei . search . req . protobuf . SenseiResultBPO . Result ) other ) ; } else { super . mergeFrom ( other ) ; return this ; } } public Builder mergeFrom ( com . sensei . search . req . protobuf . SenseiResultBPO . Result other ) { if ( other == com . sensei . search . req . protobuf . SenseiResultBPO . Result . getDefaultInstance ( ) ) return this ; if ( other . hasVal ( ) ) { setVal ( other . getVal ( ) ) ; } this . mergeUnknownFields ( other . getUnknownFields ( ) ) ; return this ; } public final boolean isInitialized ( ) { if ( ! hasVal ( ) ) { return false ; } return true ; } public Builder mergeFrom ( com . google . protobuf . CodedInputStream input , com . google . protobuf . ExtensionRegistryLite extensionRegistry ) throws java . io . IOException { com . google . protobuf . UnknownFieldSet . Builder unknownFields = com . google . protobuf . UnknownFieldSet . newBuilder ( this . getUnknownFields ( ) ) ; while ( true ) { int tag = input . readTag ( ) ; switch ( tag ) { case <NUM_LIT:0> : this . setUnknownFields ( unknownFields . build ( ) ) ; onChanged ( ) ; return this ; default : { if ( ! parseUnknownField ( input , unknownFields , extensionRegistry , tag ) ) { this . setUnknownFields ( unknownFields . build ( ) ) ; onChanged ( ) ; return this ; } break ; } case <NUM_LIT:10> : { bitField0_ |= <NUM_LIT> ; val_ = input . readBytes ( ) ; break ; } } } } private int bitField0_ ; private com . google . protobuf . ByteString val_ = com . google . protobuf . ByteString . EMPTY ; public boolean hasVal ( ) { return ( ( bitField0_ & <NUM_LIT> ) == <NUM_LIT> ) ; } public com . google . protobuf . ByteString getVal ( ) { return val_ ; } public Builder setVal ( com . google . protobuf . ByteString value ) { if ( value == null ) { throw new NullPointerException ( ) ; } bitField0_ |= <NUM_LIT> ; val_ = value ; onChanged ( ) ; return this ; } public Builder clearVal ( ) { bitField0_ = ( bitField0_ & ~ <NUM_LIT> ) ; val_ = getDefaultInstance ( ) . getVal ( ) ; onChanged ( ) ; return this ; } } static { defaultInstance = new Result ( true ) ; defaultInstance . initFields ( ) ; } } private static com . google . protobuf . Descriptors . Descriptor internal_static_com_sensei_search_req_protobuf_Result_descriptor ; private static com . google . protobuf . GeneratedMessage . FieldAccessorTable internal_static_com_sensei_search_req_protobuf_Result_fieldAccessorTable ; public static com . google . protobuf . Descriptors . FileDescriptor getDescriptor ( ) { return descriptor ; } private static com . google . protobuf . Descriptors . FileDescriptor descriptor ; static { java . lang . String [ ] descriptorData = { "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" } ; com . google . protobuf . Descriptors . FileDescriptor . InternalDescriptorAssigner assigner = new com . google . protobuf . Descriptors . FileDescriptor . InternalDescriptorAssigner ( ) { public com . google . protobuf . ExtensionRegistry assignDescriptors ( com . google . protobuf . Descriptors . FileDescriptor root ) { descriptor = root ; internal_static_com_sensei_search_req_protobuf_Result_descriptor = getDescriptor ( ) . getMessageTypes ( ) . get ( <NUM_LIT:0> ) ; internal_static_com_sensei_search_req_protobuf_Result_fieldAccessorTable = new com . google . protobuf . GeneratedMessage . FieldAccessorTable ( internal_static_com_sensei_search_req_protobuf_Result_descriptor , new java . lang . String [ ] { "<STR_LIT>" , } , com . sensei . search . req . protobuf . SenseiResultBPO . Result . class , com . sensei . search . req . protobuf . SenseiResultBPO . Result . Builder . class ) ; return null ; } } ; com . google . protobuf . Descriptors . FileDescriptor . internalBuildGeneratedFileFrom ( descriptorData , new com . google . protobuf . Descriptors . FileDescriptor [ ] { } , assigner ) ; } } </s>
<s> package com . sensei . search . req . protobuf ; import java . io . ByteArrayInputStream ; import java . io . ByteArrayOutputStream ; import java . io . IOException ; import java . io . ObjectInputStream ; import java . io . ObjectOutputStream ; import com . senseidb . search . req . SenseiRequest ; import com . senseidb . search . req . SenseiResult ; import org . apache . log4j . Logger ; import com . google . protobuf . ByteString ; public class SenseiRequestBPOConverter { private static Logger logger = Logger . getLogger ( SenseiRequestBPOConverter . class ) ; public static SenseiRequest convert ( SenseiRequestBPO . Request req ) { try { ByteString value = req . getVal ( ) ; byte [ ] raw = value . toByteArray ( ) ; ByteArrayInputStream bais = new ByteArrayInputStream ( raw ) ; ObjectInputStream ois = new ObjectInputStream ( bais ) ; SenseiRequest ret = ( SenseiRequest ) ois . readObject ( ) ; return ret ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } return null ; } public static SenseiRequestBPO . Request convert ( SenseiRequest req ) { SenseiRequestBPO . Request . Builder builder = SenseiRequestBPO . Request . newBuilder ( ) ; try { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; ObjectOutputStream oos ; oos = new ObjectOutputStream ( baos ) ; oos . writeObject ( req ) ; oos . close ( ) ; byte [ ] raw = baos . toByteArray ( ) ; builder . setVal ( ByteString . copyFrom ( raw ) ) ; return builder . build ( ) ; } catch ( IOException e ) { logger . error ( "<STR_LIT>" , e ) ; } return SenseiRequestBPO . Request . getDefaultInstance ( ) ; } public static SenseiResult convert ( SenseiResultBPO . Result req ) { try { ByteString value = req . getVal ( ) ; byte [ ] raw = value . toByteArray ( ) ; ByteArrayInputStream bais = new ByteArrayInputStream ( raw ) ; ObjectInputStream ois = new ObjectInputStream ( bais ) ; SenseiResult ret = ( SenseiResult ) ois . readObject ( ) ; return ret ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } return null ; } public static SenseiResultBPO . Result convert ( SenseiResult req ) { SenseiResultBPO . Result . Builder builder = SenseiResultBPO . Result . newBuilder ( ) ; try { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; ObjectOutputStream oos ; oos = new ObjectOutputStream ( baos ) ; oos . writeObject ( req ) ; oos . close ( ) ; byte [ ] raw = baos . toByteArray ( ) ; builder . setVal ( ByteString . copyFrom ( raw ) ) ; return builder . build ( ) ; } catch ( IOException e ) { logger . error ( "<STR_LIT>" , e ) ; } return SenseiResultBPO . Result . getDefaultInstance ( ) ; } } </s>
<s> package com . sensei . search . req . protobuf ; import java . io . ByteArrayInputStream ; import java . io . ByteArrayOutputStream ; import java . io . ObjectInputStream ; import java . io . ObjectOutputStream ; import java . util . HashSet ; import java . util . Set ; import org . apache . log4j . Logger ; import com . google . protobuf . ByteString ; import com . google . protobuf . TextFormat . ParseException ; public class ProtoConvertUtil { private final static Logger logger = Logger . getLogger ( ProtoConvertUtil . class ) ; public static Object serializeIn ( ByteString byteString ) throws ParseException { if ( byteString == null ) return null ; try { byte [ ] bytes = byteString . toByteArray ( ) ; if ( bytes . length == <NUM_LIT:0> ) return null ; ByteArrayInputStream bin = new ByteArrayInputStream ( bytes ) ; ObjectInputStream oin = new ObjectInputStream ( bin ) ; return oin . readObject ( ) ; } catch ( Exception e ) { logger . error ( e . getMessage ( ) , e ) ; throw new ParseException ( e . getMessage ( ) ) ; } } public static ByteString serializeOut ( Object o ) throws ParseException { if ( o == null ) return null ; try { ByteArrayOutputStream bout = new ByteArrayOutputStream ( ) ; ObjectOutputStream oout = new ObjectOutputStream ( bout ) ; oout . writeObject ( o ) ; oout . flush ( ) ; byte [ ] data = bout . toByteArray ( ) ; return ByteString . copyFrom ( data ) ; } catch ( Exception e ) { logger . error ( e . getMessage ( ) , e ) ; throw new ParseException ( e . getMessage ( ) ) ; } } public static ByteString serializeData ( int [ ] data ) throws ParseException { if ( data == null ) return null ; try { return serializeOut ( data ) ; } catch ( Exception e ) { logger . error ( e . getMessage ( ) , e ) ; throw new ParseException ( e . getMessage ( ) ) ; } } public static ByteString serializeData ( boolean [ ] data ) throws ParseException { if ( data == null ) return null ; try { return serializeOut ( data ) ; } catch ( Exception e ) { logger . error ( e . getMessage ( ) , e ) ; throw new ParseException ( e . getMessage ( ) ) ; } } public static ByteString serializeData ( char [ ] data ) throws ParseException { if ( data == null ) return null ; try { return serializeOut ( data ) ; } catch ( Exception e ) { logger . error ( e . getMessage ( ) , e ) ; throw new ParseException ( e . getMessage ( ) ) ; } } public static ByteString serializeData ( long [ ] data ) throws ParseException { if ( data == null ) return null ; try { return serializeOut ( data ) ; } catch ( Exception e ) { logger . error ( e . getMessage ( ) , e ) ; throw new ParseException ( e . getMessage ( ) ) ; } } public static ByteString serializeData ( double [ ] data ) throws ParseException { if ( data == null ) return null ; try { return serializeOut ( data ) ; } catch ( Exception e ) { logger . error ( e . getMessage ( ) , e ) ; throw new ParseException ( e . getMessage ( ) ) ; } } public static int [ ] toIntArray ( ByteString byteString ) throws ParseException { if ( byteString == null ) return null ; try { return ( int [ ] ) serializeIn ( byteString ) ; } catch ( Exception e ) { logger . error ( e . getMessage ( ) , e ) ; throw new ParseException ( e . getMessage ( ) ) ; } } public static Set < Integer > toIntegerSet ( ByteString byteString ) throws ParseException { if ( byteString == null ) return null ; try { int [ ] data = ( int [ ] ) serializeIn ( byteString ) ; Set < Integer > intset = null ; if ( data != null ) { intset = new HashSet < Integer > ( data . length ) ; for ( int datum : data ) { intset . add ( datum ) ; } } return intset ; } catch ( Exception e ) { logger . error ( e . getMessage ( ) , e ) ; throw new ParseException ( e . getMessage ( ) ) ; } } public static char [ ] toCharArray ( ByteString byteString ) throws ParseException { if ( byteString == null ) return null ; try { return ( char [ ] ) serializeIn ( byteString ) ; } catch ( Exception e ) { logger . error ( e . getMessage ( ) , e ) ; throw new ParseException ( e . getMessage ( ) ) ; } } public static double [ ] toDoubleArray ( ByteString byteString ) throws ParseException { if ( byteString == null ) return null ; try { return ( double [ ] ) serializeIn ( byteString ) ; } catch ( Exception e ) { logger . error ( e . getMessage ( ) , e ) ; throw new ParseException ( e . getMessage ( ) ) ; } } public static long [ ] toLongArray ( ByteString byteString ) throws ParseException { if ( byteString == null ) return null ; try { return ( long [ ] ) serializeIn ( byteString ) ; } catch ( Exception e ) { logger . error ( e . getMessage ( ) , e ) ; throw new ParseException ( e . getMessage ( ) ) ; } } public static boolean [ ] toBooleanArray ( ByteString byteString ) throws ParseException { if ( byteString == null ) return null ; try { return ( boolean [ ] ) serializeIn ( byteString ) ; } catch ( Exception e ) { logger . error ( e . getMessage ( ) , e ) ; throw new ParseException ( e . getMessage ( ) ) ; } } private static byte [ ] intToByteArray ( int data ) { byte [ ] bytes = new byte [ <NUM_LIT:4> ] ; bytes [ <NUM_LIT:0> ] = ( byte ) ( data & <NUM_LIT> ) ; bytes [ <NUM_LIT:1> ] = ( byte ) ( ( data & <NUM_LIT> ) > > <NUM_LIT:8> ) ; bytes [ <NUM_LIT:2> ] = ( byte ) ( ( data & <NUM_LIT> ) > > <NUM_LIT:16> ) ; bytes [ <NUM_LIT:3> ] = ( byte ) ( ( data & <NUM_LIT> ) > > <NUM_LIT:24> ) ; return bytes ; } } </s>
<s> package com . sensei . search . req . protobuf ; import java . io . ByteArrayInputStream ; import java . io . ByteArrayOutputStream ; import java . io . IOException ; import java . io . ObjectInputStream ; import java . io . ObjectOutputStream ; import com . senseidb . search . req . SenseiRequest ; import com . senseidb . search . req . SenseiSystemInfo ; import org . apache . log4j . Logger ; import com . google . protobuf . ByteString ; public class SenseiSysRequestBPOConverter { private static Logger logger = Logger . getLogger ( SenseiSysRequestBPOConverter . class ) ; public static SenseiRequest convert ( SenseiSysRequestBPO . SysRequest req ) { try { ByteString value = req . getVal ( ) ; byte [ ] raw = value . toByteArray ( ) ; ByteArrayInputStream bais = new ByteArrayInputStream ( raw ) ; ObjectInputStream ois = new ObjectInputStream ( bais ) ; SenseiRequest ret = ( SenseiRequest ) ois . readObject ( ) ; return ret ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } return null ; } public static SenseiSysRequestBPO . SysRequest convert ( SenseiRequest req ) { SenseiSysRequestBPO . SysRequest . Builder builder = SenseiSysRequestBPO . SysRequest . newBuilder ( ) ; try { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; ObjectOutputStream oos ; oos = new ObjectOutputStream ( baos ) ; oos . writeObject ( req ) ; oos . close ( ) ; byte [ ] raw = baos . toByteArray ( ) ; builder . setVal ( ByteString . copyFrom ( raw ) ) ; return builder . build ( ) ; } catch ( IOException e ) { logger . error ( "<STR_LIT>" , e ) ; } return SenseiSysRequestBPO . SysRequest . getDefaultInstance ( ) ; } public static SenseiSystemInfo convert ( SenseiSysResultBPO . SysResult res ) { try { ByteString value = res . getVal ( ) ; byte [ ] raw = value . toByteArray ( ) ; ByteArrayInputStream bais = new ByteArrayInputStream ( raw ) ; ObjectInputStream ois = new ObjectInputStream ( bais ) ; SenseiSystemInfo ret = ( SenseiSystemInfo ) ois . readObject ( ) ; return ret ; } catch ( Exception e ) { logger . error ( "<STR_LIT>" , e ) ; } return null ; } public static SenseiSysResultBPO . SysResult convert ( SenseiSystemInfo res ) { SenseiSysResultBPO . SysResult . Builder builder = SenseiSysResultBPO . SysResult . newBuilder ( ) ; try { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; ObjectOutputStream oos ; oos = new ObjectOutputStream ( baos ) ; oos . writeObject ( res ) ; oos . close ( ) ; byte [ ] raw = baos . toByteArray ( ) ; builder . setVal ( ByteString . copyFrom ( raw ) ) ; return builder . build ( ) ; } catch ( IOException e ) { logger . error ( "<STR_LIT>" , e ) ; } return SenseiSysResultBPO . SysResult . getDefaultInstance ( ) ; } } </s>
<s> package com . senseidb . gateway . file ; import java . io . File ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; import java . util . LinkedList ; import java . util . List ; import java . util . Queue ; import java . util . concurrent . LinkedBlockingQueue ; import java . util . concurrent . SynchronousQueue ; import org . json . JSONException ; import org . json . JSONObject ; import proj . zoie . api . DataConsumer . DataEvent ; public class FileDataProviderWithMocks extends LinedJsonFileDataProvider { private LinkedBlockingQueue < JSONObject > queue ; public FileDataProviderWithMocks ( Comparator < String > versionComparator , File file , long startingOffset ) { super ( versionComparator , file , startingOffset ) ; queue = new LinkedBlockingQueue < JSONObject > ( <NUM_LIT> ) ; mockRequests . add ( queue ) ; instances . add ( this ) ; } public static List < FileDataProviderWithMocks > instances = new ArrayList < FileDataProviderWithMocks > ( ) ; private static List < Queue < JSONObject > > mockRequests = new ArrayList < Queue < JSONObject > > ( ) ; public static void resetOffset ( long newOffset ) { for ( FileDataProviderWithMocks instance : instances ) { instance . _offset = newOffset ; } } @ Override public DataEvent < JSONObject > next ( ) { JSONObject object = queue . poll ( ) ; if ( object != null ) { return new DataEvent < JSONObject > ( object , String . valueOf ( _offset ++ ) ) ; } return super . next ( ) ; } public static void add ( JSONObject obj ) { for ( Queue < JSONObject > it : mockRequests ) { it . add ( clone ( obj ) ) ; } } private static JSONObject clone ( JSONObject obj ) { JSONObject ret = new JSONObject ( ) ; for ( String key : JSONObject . getNames ( obj ) ) { try { ret . put ( key , obj . opt ( key ) ) ; } catch ( JSONException ex ) { throw new RuntimeException ( ex ) ; } } return ret ; } public long getOffset ( ) { return _offset ; } } </s>
<s> package com . senseidb . gateway . file ; import java . io . File ; import java . util . Comparator ; import java . util . Set ; import org . json . JSONObject ; import proj . zoie . impl . indexing . StreamDataProvider ; import proj . zoie . impl . indexing . ZoieConfig ; import com . senseidb . gateway . SenseiGateway ; import com . senseidb . indexing . DataSourceFilter ; import com . senseidb . indexing . ShardingStrategy ; public class LinedFileDataProviderMockBuilder extends SenseiGateway < String > { private Comparator < String > _versionComparator = ZoieConfig . DEFAULT_VERSION_COMPARATOR ; @ Override public StreamDataProvider < JSONObject > buildDataProvider ( DataSourceFilter < String > dataFilter , String oldSinceKey , ShardingStrategy shardingStrategy , Set < Integer > partitions ) throws Exception { String path = config . get ( "<STR_LIT>" ) ; long offset = oldSinceKey == null ? <NUM_LIT> : Long . parseLong ( oldSinceKey ) ; LinedJsonFileDataProvider provider = new FileDataProviderWithMocks ( _versionComparator , new File ( path ) , offset ) ; if ( dataFilter != null ) { provider . setFilter ( dataFilter ) ; } return provider ; } @ Override public Comparator < String > getVersionComparator ( ) { return _versionComparator ; } } </s>
<s> package com . senseidb . gateway . file ; import java . io . IOException ; import org . apache . lucene . index . IndexReader ; import org . apache . lucene . search . DocIdSet ; import org . apache . lucene . search . Filter ; import com . browseengine . bobo . docidset . BitsetDocSet ; public class BitSetPurgeFilter extends Filter { @ Override public DocIdSet getDocIdSet ( IndexReader reader ) throws IOException { BitsetDocSet bitsetDocSet = new BitsetDocSet ( ) ; bitsetDocSet . addDoc ( <NUM_LIT:0> ) ; return bitsetDocSet ; } } </s>
<s> package com . senseidb . indexing . activity ; import java . io . File ; import com . senseidb . indexing . activity . primitives . ActivityIntValues ; import com . senseidb . indexing . activity . primitives . ActivityPrimitiveValues ; import com . senseidb . test . SenseiStarter ; import junit . framework . TestCase ; public class ActivityIntValuesIntTest extends TestCase { private File dir ; public void setUp ( ) { String pathname = getDirPath ( ) ; SenseiStarter . rmrf ( new File ( "<STR_LIT>" ) ) ; dir = new File ( pathname ) ; dir . mkdirs ( ) ; } public static String getDirPath ( ) { return "<STR_LIT>" ; } @ Override protected void tearDown ( ) throws Exception { File file = new File ( "<STR_LIT>" ) ; file . deleteOnExit ( ) ; SenseiStarter . rmrf ( file ) ; } public void test1 ( ) { ActivityIntValues intValues = ( ActivityIntValues ) ActivityPrimitiveValues . createActivityPrimitiveValues ( ActivityPersistenceFactory . getInstance ( getDirPath ( ) , new ActivityConfig ( ) ) , int . class , "<STR_LIT>" , <NUM_LIT:0> ) ; long time = System . currentTimeMillis ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT> ; i ++ ) { boolean update = intValues . update ( i , "<STR_LIT>" ) ; if ( update ) { intValues . prepareFlush ( ) . run ( ) ; } if ( i % <NUM_LIT> == <NUM_LIT:0> ) { System . out . println ( i ) ; } } System . out . println ( "<STR_LIT>" + ( System . currentTimeMillis ( ) - time ) ) ; intValues . close ( ) ; } } </s>
<s> package com . senseidb . indexing . activity . time ; import java . io . File ; import java . util . Arrays ; import java . util . Collections ; import java . util . HashMap ; import java . util . Map ; import junit . framework . Assert ; import org . junit . After ; import org . junit . Before ; import org . junit . Ignore ; import org . junit . Test ; import proj . zoie . impl . indexing . ZoieConfig ; import com . senseidb . indexing . activity . ActivityPersistenceFactory ; import com . senseidb . indexing . activity . CompositeActivityManager ; import com . senseidb . indexing . activity . CompositeActivityValues ; import com . senseidb . test . SenseiStarter ; public class TimeAggregatedActivityPerfTest extends Assert { private File dir ; @ Before public void before ( ) { String pathname = getDirPath ( ) ; SenseiStarter . rmrf ( new File ( "<STR_LIT>" ) ) ; dir = new File ( pathname ) ; dir . mkdirs ( ) ; } public static String getDirPath ( ) { return "<STR_LIT>" ; } @ After public void tearDown ( ) throws Exception { File file = new File ( "<STR_LIT>" ) ; SenseiStarter . rmrf ( file ) ; Clock . setPredefinedTimeInMinutes ( <NUM_LIT:0> ) ; } @ Ignore @ Test public void test1Perf10mInsertsAndUpdateAfterwards ( ) throws Exception { Clock . setPredefinedTimeInMinutes ( <NUM_LIT:0> ) ; CompositeActivityValues activityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( getDirPath ( ) ) , Collections . EMPTY_LIST , Arrays . asList ( new CompositeActivityManager . TimeAggregateInfo ( "<STR_LIT>" , Arrays . asList ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ) , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; TimeAggregatedActivityValues timeAggregatedActivityValues = ( TimeAggregatedActivityValues ) activityValues . getActivityValuesMap ( ) . get ( "<STR_LIT>" ) ; timeAggregatedActivityValues . getAggregatesUpdateJob ( ) . stop ( ) ; long insertTime = System . currentTimeMillis ( ) ; Map < String , Object > jsonActivityUpdate = new HashMap < String , Object > ( ) ; jsonActivityUpdate . put ( "<STR_LIT>" , "<STR_LIT>" ) ; int recordsCount = <NUM_LIT> ; int numOfEvents = <NUM_LIT:10> ; for ( int i = <NUM_LIT:0> ; i < numOfEvents ; i ++ ) { Clock . setPredefinedTimeInMinutes ( i ) ; for ( int j = <NUM_LIT:0> ; j < recordsCount ; j ++ ) { activityValues . update ( ( long ) j , String . valueOf ( i * recordsCount + j ) , jsonActivityUpdate ) ; if ( j % <NUM_LIT> == <NUM_LIT:0> ) { System . out . println ( "<STR_LIT>" + j ) ; } } System . out . println ( "<STR_LIT>" + i ) ; } System . out . println ( "<STR_LIT>" + ( System . currentTimeMillis ( ) - insertTime ) ) ; activityValues . syncWithPersistentVersion ( String . valueOf ( ( numOfEvents - <NUM_LIT:1> ) * recordsCount + recordsCount - <NUM_LIT:1> ) ) ; System . out . println ( "<STR_LIT>" + ( System . currentTimeMillis ( ) - insertTime ) ) ; assertEquals ( numOfEvents , timeAggregatedActivityValues . getValuesMap ( ) . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT> ] ) ; assertEquals ( numOfEvents , timeAggregatedActivityValues . getValuesMap ( ) . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT> ] ) ; assertEquals ( numOfEvents , timeAggregatedActivityValues . getValuesMap ( ) . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT> ] ) ; long updateTime = System . currentTimeMillis ( ) ; timeAggregatedActivityValues . getAggregatesUpdateJob ( ) . run ( ) ; assertEquals ( <NUM_LIT:5> , timeAggregatedActivityValues . getValuesMap ( ) . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT> ] ) ; assertEquals ( <NUM_LIT:10> , timeAggregatedActivityValues . getValuesMap ( ) . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT> ] ) ; assertEquals ( <NUM_LIT:10> , timeAggregatedActivityValues . getValuesMap ( ) . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT> ] ) ; System . out . println ( "<STR_LIT>" + ( System . currentTimeMillis ( ) - updateTime ) ) ; activityValues . flush ( ) ; Thread . sleep ( <NUM_LIT> ) ; activityValues . close ( ) ; activityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( getDirPath ( ) ) , Collections . EMPTY_LIST , Arrays . asList ( new CompositeActivityManager . TimeAggregateInfo ( "<STR_LIT>" , Arrays . asList ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ) , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; timeAggregatedActivityValues = ( TimeAggregatedActivityValues ) activityValues . getActivityValuesMap ( ) . get ( "<STR_LIT>" ) ; timeAggregatedActivityValues . getAggregatesUpdateJob ( ) . stop ( ) ; assertEquals ( <NUM_LIT:5> , timeAggregatedActivityValues . getValuesMap ( ) . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT> ] ) ; assertEquals ( <NUM_LIT:10> , timeAggregatedActivityValues . getValuesMap ( ) . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT> ] ) ; assertEquals ( <NUM_LIT:10> , timeAggregatedActivityValues . getValuesMap ( ) . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT> ] ) ; } } </s>
<s> package com . senseidb . indexing . activity . time ; import static org . junit . Assert . * ; import org . junit . Test ; import scala . actors . threadpool . Arrays ; import com . senseidb . indexing . activity . primitives . ActivityIntValues ; import com . senseidb . indexing . activity . time . TimeAggregatedActivityValues . IntValueHolder ; import com . senseidb . indexing . activity . time . TimeAggregatedActivityValues . TimeHitsHolder ; public class TimeAggregatedActivityInitTest { @ Test public void test1MinutesMoreThanActivities ( ) { int capacity = <NUM_LIT:1> ; TimeHitsHolder timeHitsHolder = new TimeHitsHolder ( capacity ) ; IntValueHolder [ ] intValueHolders = new IntValueHolder [ <NUM_LIT:3> ] ; intValueHolders [ <NUM_LIT:0> ] = new IntValueHolder ( new ActivityIntValues ( capacity ) , "<STR_LIT>" , <NUM_LIT:10> ) ; intValueHolders [ <NUM_LIT:1> ] = new IntValueHolder ( new ActivityIntValues ( capacity ) , "<STR_LIT>" , <NUM_LIT:5> ) ; intValueHolders [ <NUM_LIT:2> ] = new IntValueHolder ( new ActivityIntValues ( capacity ) , "<STR_LIT>" , <NUM_LIT:2> ) ; intValueHolders [ <NUM_LIT:0> ] . activityIntValues . fieldValues [ <NUM_LIT:0> ] = <NUM_LIT:5> ; intValueHolders [ <NUM_LIT:1> ] . activityIntValues . fieldValues [ <NUM_LIT:0> ] = <NUM_LIT:3> ; intValueHolders [ <NUM_LIT:2> ] . activityIntValues . fieldValues [ <NUM_LIT:0> ] = <NUM_LIT:1> ; TimeAggregatedActivityValues . initTimeHits ( timeHitsHolder , intValueHolders , <NUM_LIT:1> , <NUM_LIT:10> ) ; assertTrue ( Arrays . equals ( new int [ ] { <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> } , timeHitsHolder . getActivities ( <NUM_LIT:0> ) . array ) ) ; assertTrue ( Arrays . equals ( new int [ ] { <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> } , timeHitsHolder . getTimes ( <NUM_LIT:0> ) . array ) ) ; } @ Test public void test2ActivitiesMoreThanMinutes ( ) { int capacity = <NUM_LIT:1> ; TimeHitsHolder timeHitsHolder = new TimeHitsHolder ( capacity ) ; IntValueHolder [ ] intValueHolders = new IntValueHolder [ <NUM_LIT:3> ] ; intValueHolders [ <NUM_LIT:0> ] = new IntValueHolder ( new ActivityIntValues ( capacity ) , "<STR_LIT>" , <NUM_LIT:10> ) ; intValueHolders [ <NUM_LIT:1> ] = new IntValueHolder ( new ActivityIntValues ( capacity ) , "<STR_LIT>" , <NUM_LIT:5> ) ; intValueHolders [ <NUM_LIT:2> ] = new IntValueHolder ( new ActivityIntValues ( capacity ) , "<STR_LIT>" , <NUM_LIT:2> ) ; intValueHolders [ <NUM_LIT:0> ] . activityIntValues . fieldValues [ <NUM_LIT:0> ] = <NUM_LIT> ; intValueHolders [ <NUM_LIT:1> ] . activityIntValues . fieldValues [ <NUM_LIT:0> ] = <NUM_LIT:10> ; intValueHolders [ <NUM_LIT:2> ] . activityIntValues . fieldValues [ <NUM_LIT:0> ] = <NUM_LIT:1> ; TimeAggregatedActivityValues . initTimeHits ( timeHitsHolder , intValueHolders , <NUM_LIT:1> , <NUM_LIT:10> ) ; assertTrue ( Arrays . equals ( new int [ ] { <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:0> } , timeHitsHolder . getActivities ( <NUM_LIT:0> ) . array ) ) ; assertTrue ( Arrays . equals ( new int [ ] { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:10> , <NUM_LIT:0> } , timeHitsHolder . getTimes ( <NUM_LIT:0> ) . array ) ) ; } @ Test public void test3SingleActivities ( ) { int capacity = <NUM_LIT:1> ; TimeHitsHolder timeHitsHolder = new TimeHitsHolder ( capacity ) ; IntValueHolder [ ] intValueHolders = new IntValueHolder [ <NUM_LIT:3> ] ; intValueHolders [ <NUM_LIT:0> ] = new IntValueHolder ( new ActivityIntValues ( capacity ) , "<STR_LIT>" , <NUM_LIT:1> ) ; intValueHolders [ <NUM_LIT:1> ] = new IntValueHolder ( new ActivityIntValues ( capacity ) , "<STR_LIT>" , <NUM_LIT:1> ) ; intValueHolders [ <NUM_LIT:2> ] = new IntValueHolder ( new ActivityIntValues ( capacity ) , "<STR_LIT>" , <NUM_LIT:1> ) ; intValueHolders [ <NUM_LIT:0> ] . activityIntValues . fieldValues [ <NUM_LIT:0> ] = <NUM_LIT> ; intValueHolders [ <NUM_LIT:1> ] . activityIntValues . fieldValues [ <NUM_LIT:0> ] = <NUM_LIT:10> ; intValueHolders [ <NUM_LIT:2> ] . activityIntValues . fieldValues [ <NUM_LIT:0> ] = <NUM_LIT:1> ; TimeAggregatedActivityValues . initTimeHits ( timeHitsHolder , intValueHolders , <NUM_LIT:1> , <NUM_LIT:10> ) ; assertTrue ( Arrays . toString ( timeHitsHolder . getActivities ( <NUM_LIT:0> ) . array ) , Arrays . equals ( new int [ ] { <NUM_LIT:1> } , timeHitsHolder . getActivities ( <NUM_LIT:0> ) . array ) ) ; assertTrue ( Arrays . toString ( timeHitsHolder . getTimes ( <NUM_LIT:0> ) . array ) , Arrays . equals ( new int [ ] { <NUM_LIT:10> } , timeHitsHolder . getTimes ( <NUM_LIT:0> ) . array ) ) ; } } </s>
<s> package com . senseidb . indexing . activity . time ; import static org . junit . Assert . assertEquals ; import junit . framework . TestCase ; import org . junit . Test ; public class IntContainerTest extends TestCase { public void test1 ( ) { IntContainer intContainer = new IntContainer ( ) ; assertEquals ( <NUM_LIT:0> , intContainer . getSize ( ) ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:100> ; i ++ ) { intContainer . add ( i ) ; } assertEquals ( <NUM_LIT:100> , intContainer . getSize ( ) ) ; assertEquals ( <NUM_LIT:0> , intContainer . peekFirst ( ) ) ; assertEquals ( <NUM_LIT:0> , intContainer . removeFirst ( ) ) ; assertEquals ( <NUM_LIT:1> , intContainer . peekFirst ( ) ) ; assertEquals ( <NUM_LIT> , intContainer . removeLast ( ) ) ; assertEquals ( <NUM_LIT> , intContainer . getSize ( ) ) ; intContainer . add ( <NUM_LIT> ) ; assertEquals ( <NUM_LIT> , intContainer . getSize ( ) ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT> ; i ++ ) { if ( i % <NUM_LIT:2> == <NUM_LIT:1> ) { intContainer . removeFirst ( ) ; } else { intContainer . removeLast ( ) ; } } for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:10> ; i ++ ) { intContainer . add ( i ) ; } assertEquals ( <NUM_LIT> , intContainer . getSize ( ) ) ; assertEquals ( <NUM_LIT:0> , intContainer . startIndex ) ; assertEquals ( <NUM_LIT> , intContainer . array . length ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT> ; i ++ ) { intContainer . removeFirst ( ) ; } assertEquals ( <NUM_LIT:1> , intContainer . getSize ( ) ) ; assertEquals ( <NUM_LIT:3> , intContainer . startIndex ) ; assertEquals ( <NUM_LIT:5> , intContainer . array . length ) ; } } </s>
<s> package com . senseidb . indexing . activity . time ; import com . senseidb . indexing . activity . facet . SynchronizedActivityRangeFacetHandler ; import com . senseidb . indexing . activity . primitives . ActivityIntValues ; import com . senseidb . indexing . activity . time . TimeAggregatedActivityValues ; import com . senseidb . indexing . activity . time . TimeAggregatedActivityValues . IntValueHolder ; public class ActivityIntValuesSynchronizedDecorator extends ActivityIntValues { private final ActivityIntValues decorated ; @ Override public void init ( int capacity ) { decorated . init ( capacity ) ; } public void init ( ) { decorated . init ( ) ; } @ Override public boolean update ( int index , Object value ) { synchronized ( SynchronizedActivityRangeFacetHandler . GLOBAL_ACTIVITY_TEST_LOCK ) { return decorated . update ( index , value ) ; } } public void delete ( int index ) { synchronized ( SynchronizedActivityRangeFacetHandler . GLOBAL_ACTIVITY_TEST_LOCK ) { decorated . delete ( index ) ; } } protected ActivityIntValuesSynchronizedDecorator ( ActivityIntValues decorated ) { this . decorated = decorated ; } public Runnable prepareFlush ( ) { return this . decorated . prepareFlush ( ) ; } public int getIntValue ( int index ) { synchronized ( SynchronizedActivityRangeFacetHandler . GLOBAL_ACTIVITY_TEST_LOCK ) { return this . decorated . getIntValue ( index ) ; } } public int [ ] getFieldValues ( ) { return decorated . getFieldValues ( ) ; } public void setFieldValues ( int [ ] fieldValues ) { decorated . setFieldValues ( fieldValues ) ; } @ Override public void close ( ) { decorated . close ( ) ; } @ Override public String getFieldName ( ) { return decorated . getFieldName ( ) ; } public static void decorate ( TimeAggregatedActivityValues timeAggregatedActivityValues ) { timeAggregatedActivityValues . defaultIntValues = new ActivityIntValuesSynchronizedDecorator ( timeAggregatedActivityValues . defaultIntValues ) ; for ( IntValueHolder intValueHolder : timeAggregatedActivityValues . intActivityValues ) { intValueHolder . activityIntValues = new ActivityIntValuesSynchronizedDecorator ( intValueHolder . activityIntValues ) ; } } } </s>
<s> package com . senseidb . indexing . activity . time ; import java . io . File ; import junit . framework . TestCase ; import scala . actors . threadpool . Arrays ; import com . senseidb . indexing . activity . ActivityPersistenceFactory ; import com . senseidb . test . SenseiStarter ; public class TimeAggregatedActivityValuesTest extends TestCase { private File dir ; private TimeAggregatedActivityValues timeAggregatedActivityValues ; public void setUp ( ) { String pathname = getDirPath ( ) ; SenseiStarter . rmrf ( new File ( "<STR_LIT>" ) ) ; dir = new File ( pathname ) ; dir . mkdirs ( ) ; } public static String getDirPath ( ) { return "<STR_LIT>" ; } public void tearDown ( ) throws Exception { File file = new File ( "<STR_LIT>" ) ; SenseiStarter . rmrf ( file ) ; Clock . setPredefinedTimeInMinutes ( <NUM_LIT:0> ) ; } public void test1 ( ) { Clock . setPredefinedTimeInMinutes ( <NUM_LIT:0> ) ; timeAggregatedActivityValues = TimeAggregatedActivityValues . createTimeAggregatedValues ( "<STR_LIT>" , java . util . Arrays . asList ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <NUM_LIT:0> , ActivityPersistenceFactory . getInstance ( getDirPath ( ) ) ) ; timeAggregatedActivityValues . init ( <NUM_LIT:0> ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:11> ; i ++ ) { Clock . setPredefinedTimeInMinutes ( i ) ; timeAggregatedActivityValues . update ( <NUM_LIT:0> , "<STR_LIT:1>" ) ; timeAggregatedActivityValues . update ( <NUM_LIT:1> , "<STR_LIT:1>" ) ; } assertTrue ( Arrays . toString ( timeAggregatedActivityValues . timeActivities . getActivities ( <NUM_LIT:0> ) . array ) , Arrays . equals ( new int [ ] { <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> } , timeAggregatedActivityValues . timeActivities . getActivities ( <NUM_LIT:0> ) . array ) ) ; assertTrue ( Arrays . toString ( timeAggregatedActivityValues . timeActivities . getTimes ( <NUM_LIT:0> ) . array ) , Arrays . equals ( new int [ ] { <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> } , timeAggregatedActivityValues . timeActivities . getTimes ( <NUM_LIT:0> ) . array ) ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:11> ) ; Clock . setPredefinedTimeInMinutes ( <NUM_LIT:10> ) ; AggregatesUpdateJob aggregatesUpdateJob = new AggregatesUpdateJob ( timeAggregatedActivityValues , ActivityPersistenceFactory . getInstance ( getDirPath ( ) ) . createAggregatesMetadata ( "<STR_LIT>" ) ) ; Clock . setPredefinedTimeInMinutes ( <NUM_LIT:11> ) ; aggregatesUpdateJob . run ( ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:9> ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:4> ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:1> ) ; assertEquals ( timeAggregatedActivityValues . timeActivities . getTimes ( <NUM_LIT:0> ) . getSize ( ) , <NUM_LIT:9> ) ; Clock . setPredefinedTimeInMinutes ( <NUM_LIT:12> ) ; aggregatesUpdateJob . run ( ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:8> ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:3> ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:0> ) ; assertEquals ( timeAggregatedActivityValues . timeActivities . getTimes ( <NUM_LIT:0> ) . getSize ( ) , <NUM_LIT:8> ) ; Clock . setPredefinedTimeInMinutes ( <NUM_LIT> ) ; aggregatesUpdateJob . run ( ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:0> ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:0> ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:0> ) ; } public void test2InMemory ( ) { Clock . setPredefinedTimeInMinutes ( <NUM_LIT:0> ) ; timeAggregatedActivityValues = TimeAggregatedActivityValues . createTimeAggregatedValues ( "<STR_LIT>" , java . util . Arrays . asList ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <NUM_LIT:0> , ActivityPersistenceFactory . getInstance ( getDirPath ( ) ) ) ; timeAggregatedActivityValues . init ( <NUM_LIT:0> ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:11> ; i ++ ) { Clock . setPredefinedTimeInMinutes ( i ) ; timeAggregatedActivityValues . update ( <NUM_LIT:0> , "<STR_LIT:1>" ) ; timeAggregatedActivityValues . update ( <NUM_LIT:1> , "<STR_LIT:1>" ) ; } assertTrue ( Arrays . toString ( timeAggregatedActivityValues . timeActivities . getActivities ( <NUM_LIT:0> ) . array ) , Arrays . equals ( new int [ ] { <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> } , timeAggregatedActivityValues . timeActivities . getActivities ( <NUM_LIT:0> ) . array ) ) ; assertTrue ( Arrays . toString ( timeAggregatedActivityValues . timeActivities . getTimes ( <NUM_LIT:0> ) . array ) , Arrays . equals ( new int [ ] { <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> } , timeAggregatedActivityValues . timeActivities . getTimes ( <NUM_LIT:0> ) . array ) ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:11> ) ; Clock . setPredefinedTimeInMinutes ( <NUM_LIT:10> ) ; AggregatesUpdateJob aggregatesUpdateJob = new AggregatesUpdateJob ( timeAggregatedActivityValues , ActivityPersistenceFactory . getInstance ( getDirPath ( ) ) . createAggregatesMetadata ( "<STR_LIT>" ) ) ; Clock . setPredefinedTimeInMinutes ( <NUM_LIT:11> ) ; aggregatesUpdateJob . run ( ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:9> ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:4> ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:1> ) ; assertEquals ( timeAggregatedActivityValues . timeActivities . getTimes ( <NUM_LIT:0> ) . getSize ( ) , <NUM_LIT:9> ) ; Clock . setPredefinedTimeInMinutes ( <NUM_LIT:12> ) ; aggregatesUpdateJob . run ( ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:8> ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:3> ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:0> ) ; assertEquals ( timeAggregatedActivityValues . timeActivities . getTimes ( <NUM_LIT:0> ) . getSize ( ) , <NUM_LIT:8> ) ; Clock . setPredefinedTimeInMinutes ( <NUM_LIT> ) ; aggregatesUpdateJob . run ( ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:0> ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:0> ) ; assertEquals ( timeAggregatedActivityValues . valuesMap . get ( "<STR_LIT>" ) . fieldValues [ <NUM_LIT:0> ] , <NUM_LIT:0> ) ; } } </s>
<s> package com . senseidb . indexing . activity ; import java . io . File ; import java . util . Arrays ; import java . util . Collections ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import java . util . concurrent . TimeUnit ; import junit . framework . TestCase ; import org . easymock . classextension . EasyMock ; import org . json . JSONObject ; import proj . zoie . api . IndexReaderFactory ; import proj . zoie . api . Zoie ; import proj . zoie . api . ZoieIndexReader ; import proj . zoie . api . impl . DocIDMapperImpl ; import proj . zoie . impl . indexing . ZoieConfig ; import com . browseengine . bobo . api . BoboIndexReader ; import com . senseidb . test . SenseiStarter ; public class PurgeUnusedActivitiesJobTest extends TestCase { private File dir ; private Set < IndexReaderFactory < ZoieIndexReader < BoboIndexReader > > > zoieSystems ; private CompositeActivityValues compositeActivityValues ; public void setUp ( ) throws Exception { String pathname = getDirPath ( ) ; SenseiStarter . rmrf ( new File ( "<STR_LIT>" ) ) ; dir = new File ( pathname ) ; dir . mkdirs ( ) ; zoieSystems = new HashSet < IndexReaderFactory < ZoieIndexReader < BoboIndexReader > > > ( ) ; ZoieIndexReader reader = EasyMock . createMock ( ZoieIndexReader . class ) ; EasyMock . expect ( reader . getDocIDMaper ( ) ) . andReturn ( new DocIDMapperImpl ( new long [ ] { <NUM_LIT> , <NUM_LIT> } ) ) . anyTimes ( ) ; Zoie zoie = org . easymock . EasyMock . createMock ( Zoie . class ) ; org . easymock . EasyMock . expect ( zoie . getIndexReaders ( ) ) . andReturn ( Arrays . asList ( reader ) ) . anyTimes ( ) ; zoie . returnIndexReaders ( org . easymock . EasyMock . < List > notNull ( ) ) ; org . easymock . EasyMock . expectLastCall ( ) . anyTimes ( ) ; org . easymock . EasyMock . replay ( zoie ) ; EasyMock . replay ( reader ) ; zoieSystems . add ( zoie ) ; } public static String getDirPath ( ) { return "<STR_LIT>" ; } @ Override protected void tearDown ( ) throws Exception { compositeActivityValues . close ( ) ; File file = new File ( "<STR_LIT>" ) ; file . deleteOnExit ( ) ; SenseiStarter . rmrf ( file ) ; } public void test1WriteValuesAndReadJustAfterThat ( ) throws Exception { compositeActivityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( getDirPath ( ) ) , java . util . Arrays . asList ( ActivityIntegrationTest . getLikesFieldDefinition ( ) ) , Collections . EMPTY_LIST , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; int valueCount = <NUM_LIT> ; for ( int i = <NUM_LIT:0> ; i < valueCount ; i ++ ) { compositeActivityValues . update ( i , String . format ( "<STR_LIT>" , i ) , ActivityPrimitiveValuesPersistenceTest . toMap ( new JSONObject ( ) . put ( "<STR_LIT>" , "<STR_LIT>" ) ) ) ; } compositeActivityValues . flush ( ) ; compositeActivityValues . syncWithPersistentVersion ( String . format ( "<STR_LIT>" , valueCount - <NUM_LIT:1> ) ) ; PurgeUnusedActivitiesJob purgeUnusedActivitiesJob = new PurgeUnusedActivitiesJob ( compositeActivityValues , zoieSystems , <NUM_LIT> * <NUM_LIT:1000> ) ; assertEquals ( <NUM_LIT> , purgeUnusedActivitiesJob . purgeUnusedActivityIndexes ( ) ) ; compositeActivityValues . recentlyAddedUids . clear ( ) ; assertEquals ( <NUM_LIT> , purgeUnusedActivitiesJob . purgeUnusedActivityIndexes ( ) ) ; assertEquals ( <NUM_LIT:0> , purgeUnusedActivitiesJob . purgeUnusedActivityIndexes ( ) ) ; compositeActivityValues . flushDeletes ( ) ; compositeActivityValues . executor . shutdown ( ) ; compositeActivityValues . executor . awaitTermination ( <NUM_LIT:10> , TimeUnit . SECONDS ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:10> ; i ++ ) { compositeActivityValues . update ( i , String . format ( "<STR_LIT>" , valueCount + i ) , ActivityPrimitiveValuesPersistenceTest . toMap ( new JSONObject ( ) . put ( "<STR_LIT>" , "<STR_LIT>" ) ) ) ; } assertEquals ( <NUM_LIT:12> , compositeActivityValues . uidToArrayIndex . size ( ) ) ; assertEquals ( <NUM_LIT> , compositeActivityValues . deletedIndexes . size ( ) ) ; } } </s>
<s> package com . senseidb . indexing . activity ; import junit . framework . Assert ; public class Wait { public static void until ( long timeToWait , String failureMessage , Condition condition ) { long time = System . currentTimeMillis ( ) ; while ( System . currentTimeMillis ( ) - time <= timeToWait ) { if ( condition . evaluate ( ) ) { return ; } try { Thread . sleep ( <NUM_LIT> ) ; } catch ( InterruptedException e ) { throw new IllegalStateException ( e ) ; } } Assert . assertTrue ( failureMessage , condition . evaluate ( ) ) ; } public static interface Condition { public boolean evaluate ( ) ; } } </s>
<s> package com . senseidb . indexing . activity ; import it . unimi . dsi . fastutil . longs . LongArrayList ; import it . unimi . dsi . fastutil . longs . LongList ; import java . io . File ; import java . io . RandomAccessFile ; import java . util . Collections ; import java . util . HashMap ; import java . util . Map ; import junit . framework . TestCase ; import org . json . JSONObject ; import proj . zoie . impl . indexing . ZoieConfig ; import com . senseidb . conf . SenseiSchema . FieldDefinition ; import com . senseidb . indexing . activity . primitives . ActivityFloatValues ; import com . senseidb . indexing . activity . primitives . ActivityIntValues ; import com . senseidb . test . SenseiStarter ; public class ActivityPrimitiveValuesPersistenceTest extends TestCase { private static final long UID_BASE = <NUM_LIT> ; private File dir ; private CompositeActivityValues compositeActivityValues ; public void setUp ( ) { String pathname = getDirPath ( ) ; SenseiStarter . rmrf ( new File ( "<STR_LIT>" ) ) ; dir = new File ( pathname ) ; dir . mkdirs ( ) ; } public static String getDirPath ( ) { return "<STR_LIT>" ; } @ Override protected void tearDown ( ) throws Exception { File file = new File ( "<STR_LIT>" ) ; if ( file . exists ( ) ) { file . deleteOnExit ( ) ; SenseiStarter . rmrf ( file ) ; } } public void test1WriteValuesAndReadJustAfterThatInMemmory ( ) throws Exception { compositeActivityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInMemoryInstance ( ) , java . util . Arrays . asList ( ActivityIntegrationTest . getLikesFieldDefinition ( ) ) , Collections . EMPTY_LIST , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; int valueCount = <NUM_LIT> ; for ( int i = <NUM_LIT:0> ; i < valueCount ; i ++ ) { compositeActivityValues . update ( <NUM_LIT> + i , String . format ( "<STR_LIT>" , i ) , toMap ( new JSONObject ( ) . put ( "<STR_LIT>" , "<STR_LIT>" ) ) ) ; } compositeActivityValues . flush ( ) ; compositeActivityValues . syncWithPersistentVersion ( String . format ( "<STR_LIT>" , valueCount - <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" + compositeActivityValues . uidToArrayIndex . size ( ) , valueCount , compositeActivityValues . uidToArrayIndex . size ( ) ) ; for ( int i = <NUM_LIT:0> ; i < valueCount ; i ++ ) { compositeActivityValues . update ( <NUM_LIT> + i , String . format ( "<STR_LIT>" , valueCount + i ) , toMap ( new JSONObject ( ) . put ( "<STR_LIT>" , "<STR_LIT:+>" + i ) ) ) ; } compositeActivityValues . flush ( ) ; compositeActivityValues . syncWithPersistentVersion ( String . format ( "<STR_LIT>" , valueCount * <NUM_LIT:2> - <NUM_LIT:1> ) ) ; compositeActivityValues . close ( ) ; assertEquals ( getFieldValues ( compositeActivityValues ) [ <NUM_LIT:0> ] , <NUM_LIT:1> ) ; assertEquals ( getFieldValues ( compositeActivityValues ) [ <NUM_LIT:3> ] , <NUM_LIT:4> ) ; } public void test1WriteValuesAndReadJustAfterThat ( ) throws Exception { compositeActivityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( getDirPath ( ) ) , java . util . Arrays . asList ( ActivityIntegrationTest . getLikesFieldDefinition ( ) ) , Collections . EMPTY_LIST , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; int valueCount = <NUM_LIT> ; for ( int i = <NUM_LIT:0> ; i < valueCount ; i ++ ) { compositeActivityValues . update ( <NUM_LIT> + i , String . format ( "<STR_LIT>" , i ) , toMap ( new JSONObject ( ) . put ( "<STR_LIT>" , "<STR_LIT>" ) ) ) ; } compositeActivityValues . flush ( ) ; compositeActivityValues . syncWithPersistentVersion ( String . format ( "<STR_LIT>" , valueCount - <NUM_LIT:1> ) ) ; compositeActivityValues . close ( ) ; compositeActivityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( getDirPath ( ) ) , java . util . Arrays . asList ( ActivityIntegrationTest . getLikesFieldDefinition ( ) ) , Collections . EMPTY_LIST , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; assertEquals ( "<STR_LIT>" + compositeActivityValues . uidToArrayIndex . size ( ) , valueCount , compositeActivityValues . uidToArrayIndex . size ( ) ) ; assertEquals ( ( int ) ( valueCount * <NUM_LIT> ) , getFieldValues ( compositeActivityValues ) . length ) ; for ( int i = <NUM_LIT:0> ; i < valueCount ; i ++ ) { compositeActivityValues . update ( <NUM_LIT> + i , String . format ( "<STR_LIT>" , valueCount + i ) , toMap ( new JSONObject ( ) . put ( "<STR_LIT>" , "<STR_LIT:+>" + i ) ) ) ; } compositeActivityValues . flush ( ) ; compositeActivityValues . syncWithPersistentVersion ( String . format ( "<STR_LIT>" , valueCount * <NUM_LIT:2> - <NUM_LIT:1> ) ) ; compositeActivityValues . close ( ) ; assertEquals ( getFieldValues ( compositeActivityValues ) [ <NUM_LIT:0> ] , <NUM_LIT:1> ) ; assertEquals ( getFieldValues ( compositeActivityValues ) [ <NUM_LIT:3> ] , <NUM_LIT:4> ) ; compositeActivityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( getDirPath ( ) ) , java . util . Arrays . asList ( ActivityIntegrationTest . getLikesFieldDefinition ( ) ) , Collections . EMPTY_LIST , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; assertEquals ( getFieldValues ( compositeActivityValues ) [ <NUM_LIT:0> ] , <NUM_LIT:1> ) ; assertEquals ( getFieldValues ( compositeActivityValues ) [ <NUM_LIT:3> ] , <NUM_LIT:4> ) ; compositeActivityValues . close ( ) ; } public void test1BWriteValuesAndReadJustAfterThatFloatValues ( ) throws Exception { String indexDirPath = getDirPath ( ) + <NUM_LIT> ; FieldDefinition fieldDefinition = new FieldDefinition ( ) ; fieldDefinition . name = "<STR_LIT>" ; fieldDefinition . type = float . class ; fieldDefinition . isActivity = true ; compositeActivityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( indexDirPath ) , java . util . Arrays . asList ( fieldDefinition ) , Collections . EMPTY_LIST , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; int valueCount = <NUM_LIT> ; for ( int i = <NUM_LIT:0> ; i < valueCount ; i ++ ) { compositeActivityValues . update ( <NUM_LIT> + i , String . format ( "<STR_LIT>" , i ) , toMap ( new JSONObject ( ) . put ( "<STR_LIT>" , "<STR_LIT>" ) ) ) ; } compositeActivityValues . flush ( ) ; compositeActivityValues . syncWithPersistentVersion ( String . format ( "<STR_LIT>" , valueCount - <NUM_LIT:1> ) ) ; compositeActivityValues . close ( ) ; compositeActivityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( indexDirPath ) , java . util . Arrays . asList ( fieldDefinition ) , Collections . EMPTY_LIST , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; assertEquals ( "<STR_LIT>" + compositeActivityValues . uidToArrayIndex . size ( ) , valueCount , compositeActivityValues . uidToArrayIndex . size ( ) ) ; assertEquals ( ( int ) ( valueCount * <NUM_LIT> ) , getFloatFieldValues ( compositeActivityValues ) . length ) ; for ( int i = <NUM_LIT:0> ; i < valueCount ; i ++ ) { compositeActivityValues . update ( <NUM_LIT> + i , String . format ( "<STR_LIT>" , valueCount + i ) , toMap ( new JSONObject ( ) . put ( "<STR_LIT>" , "<STR_LIT:+>" + ( <NUM_LIT:0.0> + i ) ) ) ) ; } compositeActivityValues . flush ( ) ; compositeActivityValues . syncWithPersistentVersion ( String . format ( "<STR_LIT>" , valueCount * <NUM_LIT:2> - <NUM_LIT:1> ) ) ; compositeActivityValues . close ( ) ; assertEquals ( getFloatFieldValues ( compositeActivityValues ) [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) ; assertEquals ( getFloatFieldValues ( compositeActivityValues ) [ <NUM_LIT:3> ] , <NUM_LIT> , <NUM_LIT> ) ; compositeActivityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( indexDirPath ) , java . util . Arrays . asList ( fieldDefinition ) , Collections . EMPTY_LIST , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; assertEquals ( getFloatFieldValues ( compositeActivityValues ) [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) ; assertEquals ( getFloatFieldValues ( compositeActivityValues ) [ <NUM_LIT:3> ] , <NUM_LIT> , <NUM_LIT> ) ; compositeActivityValues . close ( ) ; } public static Map < String , Object > toMap ( JSONObject jsonObject ) { Map < String , Object > ret = new HashMap < String , Object > ( ) ; java . util . Iterator < String > it = jsonObject . keys ( ) ; while ( it . hasNext ( ) ) { String key = it . next ( ) ; ret . put ( key , jsonObject . opt ( key ) ) ; } return ret ; } private int [ ] getFieldValues ( CompositeActivityValues compositeActivityValues ) { return ( ( ActivityIntValues ) compositeActivityValues . valuesMap . get ( "<STR_LIT>" ) ) . fieldValues ; } private float [ ] getFloatFieldValues ( CompositeActivityValues compositeActivityValues ) { return ( ( ActivityFloatValues ) compositeActivityValues . valuesMap . get ( "<STR_LIT>" ) ) . fieldValues ; } public void test2WriteDeleteWriteAgain ( ) throws Exception { String indexDirPath = getDirPath ( ) + <NUM_LIT:1> ; dir = new File ( indexDirPath ) ; dir . mkdirs ( ) ; dir . deleteOnExit ( ) ; compositeActivityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( getDirPath ( ) ) , java . util . Arrays . asList ( ActivityIntegrationTest . getLikesFieldDefinition ( ) ) , Collections . EMPTY_LIST , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; final int valueCount = <NUM_LIT> ; for ( int i = <NUM_LIT:0> ; i < valueCount ; i ++ ) { compositeActivityValues . update ( UID_BASE + i , String . format ( "<STR_LIT>" , valueCount + i ) , toMap ( new JSONObject ( ) . put ( "<STR_LIT>" , "<STR_LIT>" ) ) ) ; } compositeActivityValues . flush ( ) ; compositeActivityValues . syncWithPersistentVersion ( String . format ( "<STR_LIT>" , valueCount - <NUM_LIT:1> ) ) ; LongList uidsToDelete = new LongArrayList ( ) ; for ( int i = <NUM_LIT:0> ; i < valueCount ; i ++ ) { if ( i == <NUM_LIT:2> ) { continue ; } uidsToDelete . add ( UID_BASE + i ) ; if ( i % <NUM_LIT:1000> == <NUM_LIT:0> ) { compositeActivityValues . delete ( uidsToDelete . toLongArray ( ) ) ; uidsToDelete . clear ( ) ; } } compositeActivityValues . flush ( ) ; compositeActivityValues . delete ( uidsToDelete . toLongArray ( ) ) ; compositeActivityValues . flushDeletes ( ) ; int notDeletedIndex = compositeActivityValues . uidToArrayIndex . get ( UID_BASE + <NUM_LIT:2> ) ; final CompositeActivityValues testActivityData = compositeActivityValues ; Wait . until ( <NUM_LIT> , "<STR_LIT>" , new Wait . Condition ( ) { public boolean evaluate ( ) { synchronized ( testActivityData . deletedIndexes ) { return testActivityData . deletedIndexes . size ( ) == valueCount - <NUM_LIT:1> ; } } } ) ; assertEquals ( valueCount - <NUM_LIT:1> , compositeActivityValues . deletedIndexes . size ( ) ) ; assertEquals ( <NUM_LIT:1> , compositeActivityValues . uidToArrayIndex . size ( ) ) ; assertFalse ( compositeActivityValues . uidToArrayIndex . containsKey ( UID_BASE + <NUM_LIT:1> ) ) ; assertEquals ( Integer . MIN_VALUE , getFieldValues ( compositeActivityValues ) [ notDeletedIndex - <NUM_LIT:1> ] ) ; assertEquals ( <NUM_LIT:1> , getFieldValues ( compositeActivityValues ) [ notDeletedIndex ] ) ; assertEquals ( <NUM_LIT:1> , compositeActivityValues . getIntValueByUID ( UID_BASE + <NUM_LIT:2> , "<STR_LIT>" ) ) ; compositeActivityValues . flush ( ) ; Thread . sleep ( <NUM_LIT> ) ; compositeActivityValues . close ( ) ; compositeActivityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( getDirPath ( ) ) , java . util . Arrays . asList ( ActivityIntegrationTest . getLikesFieldDefinition ( ) ) , Collections . EMPTY_LIST , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; assertEquals ( "<STR_LIT>" + compositeActivityValues . metadata . count , valueCount , ( int ) compositeActivityValues . metadata . count ) ; assertEquals ( valueCount - <NUM_LIT:1> , compositeActivityValues . deletedIndexes . size ( ) ) ; assertEquals ( <NUM_LIT:1> , compositeActivityValues . uidToArrayIndex . size ( ) ) ; assertFalse ( compositeActivityValues . uidToArrayIndex . containsKey ( UID_BASE + <NUM_LIT:1> ) ) ; assertEquals ( <NUM_LIT:1> , getFieldValues ( compositeActivityValues ) [ notDeletedIndex ] ) ; assertEquals ( <NUM_LIT:1> , compositeActivityValues . getIntValueByUID ( UID_BASE + <NUM_LIT:2> , "<STR_LIT>" ) ) ; assertEquals ( ( int ) ( valueCount * <NUM_LIT> ) , getFieldValues ( compositeActivityValues ) . length ) ; for ( int i = <NUM_LIT:0> ; i < valueCount ; i ++ ) { compositeActivityValues . update ( UID_BASE + i , String . format ( "<STR_LIT>" , valueCount * <NUM_LIT:2> + i ) , toMap ( new JSONObject ( ) . put ( "<STR_LIT>" , "<STR_LIT:+>" + i ) ) ) ; } compositeActivityValues . flush ( ) ; compositeActivityValues . syncWithPersistentVersion ( String . format ( "<STR_LIT>" , valueCount * <NUM_LIT:3> - <NUM_LIT:1> ) ) ; assertEquals ( compositeActivityValues . getIntValueByUID ( UID_BASE + <NUM_LIT:0> , "<STR_LIT>" ) , <NUM_LIT:1> ) ; assertEquals ( compositeActivityValues . getIntValueByUID ( UID_BASE + <NUM_LIT:3> , "<STR_LIT>" ) , <NUM_LIT:4> ) ; compositeActivityValues . close ( ) ; } public void test3StartWithInconsistentIndexesAddExtraSpaceToCommentFile ( ) throws Exception { String indexDirPath = getDirPath ( ) + <NUM_LIT:2> ; dir = new File ( indexDirPath ) ; dir . mkdirs ( ) ; dir . deleteOnExit ( ) ; compositeActivityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( getDirPath ( ) ) , java . util . Arrays . asList ( ActivityIntegrationTest . getLikesFieldDefinition ( ) ) , Collections . EMPTY_LIST , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; final int valueCount = <NUM_LIT:100> ; for ( int i = <NUM_LIT:0> ; i < valueCount ; i ++ ) { compositeActivityValues . update ( UID_BASE + i , String . format ( "<STR_LIT>" , valueCount + i ) , toMap ( new JSONObject ( ) . put ( "<STR_LIT>" , "<STR_LIT>" ) ) ) ; } compositeActivityValues . flush ( ) ; compositeActivityValues . syncWithPersistentVersion ( String . format ( "<STR_LIT>" , <NUM_LIT:2> * valueCount - <NUM_LIT:1> ) ) ; compositeActivityValues . close ( ) ; new File ( dir , "<STR_LIT>" ) . createNewFile ( ) ; compositeActivityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( getDirPath ( ) ) , java . util . Arrays . asList ( ActivityIntegrationTest . getLikesFieldDefinition ( ) , ActivityIntegrationTest . getIntFieldDefinition ( "<STR_LIT>" ) ) , Collections . EMPTY_LIST , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; assertEquals ( <NUM_LIT:0> , compositeActivityValues . getIntValueByUID ( UID_BASE + valueCount / <NUM_LIT:2> , "<STR_LIT>" ) ) ; compositeActivityValues . close ( ) ; } public void test4TestForUninsertedValue ( ) throws Exception { String indexDirPath = getDirPath ( ) + <NUM_LIT:3> ; dir = new File ( indexDirPath ) ; dir . mkdirs ( ) ; dir . deleteOnExit ( ) ; compositeActivityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( getDirPath ( ) ) , java . util . Arrays . asList ( ActivityIntegrationTest . getLikesFieldDefinition ( ) , ActivityIntegrationTest . getIntFieldDefinition ( "<STR_LIT>" ) ) , Collections . EMPTY_LIST , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; final int valueCount = <NUM_LIT:100> ; for ( int i = <NUM_LIT:0> ; i < valueCount ; i ++ ) { compositeActivityValues . update ( UID_BASE + i , String . format ( "<STR_LIT>" , valueCount + i ) , toMap ( new JSONObject ( ) . put ( "<STR_LIT>" , "<STR_LIT>" ) ) ) ; } assertEquals ( <NUM_LIT:0> , compositeActivityValues . getIntValueByUID ( UID_BASE + valueCount / <NUM_LIT:2> , "<STR_LIT>" ) ) ; compositeActivityValues . flush ( ) ; compositeActivityValues . syncWithPersistentVersion ( String . format ( "<STR_LIT>" , <NUM_LIT:2> * valueCount - <NUM_LIT:1> ) ) ; compositeActivityValues . close ( ) ; } public void test5TrimMetadata ( ) throws Exception { String indexDirPath = getDirPath ( ) + <NUM_LIT:4> ; dir = new File ( indexDirPath ) ; dir . mkdirs ( ) ; dir . deleteOnExit ( ) ; compositeActivityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( indexDirPath ) , java . util . Arrays . asList ( ActivityIntegrationTest . getLikesFieldDefinition ( ) ) , Collections . EMPTY_LIST , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; final int valueCount = <NUM_LIT:100> ; for ( int i = <NUM_LIT:0> ; i < valueCount ; i ++ ) { compositeActivityValues . update ( UID_BASE + i , String . format ( "<STR_LIT>" , valueCount + i ) , toMap ( new JSONObject ( ) . put ( "<STR_LIT>" , "<STR_LIT>" ) ) ) ; } compositeActivityValues . flush ( ) ; compositeActivityValues . syncWithPersistentVersion ( String . format ( "<STR_LIT>" , <NUM_LIT:2> * valueCount - <NUM_LIT:1> ) ) ; compositeActivityValues . close ( ) ; RandomAccessFile randomAccessFile = new RandomAccessFile ( new File ( dir , "<STR_LIT>" ) , "<STR_LIT>" ) ; randomAccessFile . setLength ( <NUM_LIT:16> ) ; randomAccessFile . close ( ) ; compositeActivityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( indexDirPath ) , java . util . Arrays . asList ( ActivityIntegrationTest . getLikesFieldDefinition ( ) , ActivityIntegrationTest . getIntFieldDefinition ( "<STR_LIT>" ) ) , Collections . EMPTY_LIST , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; assertEquals ( <NUM_LIT:1> , compositeActivityValues . getIntValueByUID ( UID_BASE + <NUM_LIT:1> , "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:2> , compositeActivityValues . uidToArrayIndex . size ( ) ) ; assertEquals ( <NUM_LIT:0> , compositeActivityValues . deletedIndexes . size ( ) ) ; assertEquals ( <NUM_LIT:2> , compositeActivityValues . metadata . count ) ; for ( int i = <NUM_LIT:0> ; i < valueCount ; i ++ ) { compositeActivityValues . update ( UID_BASE + i , String . format ( "<STR_LIT>" , <NUM_LIT:2> * valueCount + i ) , toMap ( new JSONObject ( ) . put ( "<STR_LIT>" , "<STR_LIT>" ) ) ) ; } assertEquals ( <NUM_LIT:2> , compositeActivityValues . getIntValueByUID ( UID_BASE , "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:2> , compositeActivityValues . getIntValueByUID ( UID_BASE + <NUM_LIT:1> , "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:1> , compositeActivityValues . getIntValueByUID ( UID_BASE + valueCount / <NUM_LIT:2> , "<STR_LIT>" ) ) ; assertEquals ( valueCount , compositeActivityValues . uidToArrayIndex . size ( ) ) ; assertEquals ( <NUM_LIT:0> , compositeActivityValues . deletedIndexes . size ( ) ) ; compositeActivityValues . flush ( ) ; compositeActivityValues . syncWithPersistentVersion ( String . format ( "<STR_LIT>" , <NUM_LIT:3> * valueCount - <NUM_LIT:1> ) ) ; assertEquals ( valueCount , compositeActivityValues . metadata . count ) ; compositeActivityValues . close ( ) ; } } </s>
<s> package com . senseidb . indexing . activity ; import java . util . Collections ; import junit . framework . TestCase ; import org . apache . log4j . Logger ; import org . json . JSONArray ; import org . json . JSONObject ; import org . junit . Ignore ; import proj . zoie . impl . indexing . ZoieConfig ; import com . senseidb . conf . SenseiSchema ; import com . senseidb . conf . SenseiSchema . FieldDefinition ; import com . senseidb . gateway . file . FileDataProviderWithMocks ; import com . senseidb . indexing . activity . primitives . ActivityIntValues ; import com . senseidb . indexing . activity . time . ActivityIntValuesSynchronizedDecorator ; import com . senseidb . indexing . activity . time . Clock ; import com . senseidb . indexing . activity . time . TimeAggregatedActivityValues ; import com . senseidb . test . SenseiStarter ; import com . senseidb . test . TestSensei ; public class ActivityIntegrationTest extends TestCase { private static final Logger logger = Logger . getLogger ( ActivityIntegrationTest . class ) ; private static long initialVersion ; private static long expectedVersion ; private static CompositeActivityValues inMemoryColumnData1 ; private static CompositeActivityValues inMemoryColumnData2 ; static { SenseiStarter . start ( "<STR_LIT>" , "<STR_LIT>" ) ; inMemoryColumnData1 = CompositeActivityManager . cachedInstances . get ( <NUM_LIT:1> ) . activityValues ; inMemoryColumnData2 = CompositeActivityManager . cachedInstances . get ( <NUM_LIT:2> ) . activityValues ; ActivityIntValuesSynchronizedDecorator . decorate ( ( TimeAggregatedActivityValues ) inMemoryColumnData1 . getActivityValuesMap ( ) . get ( "<STR_LIT>" ) ) ; ActivityIntValuesSynchronizedDecorator . decorate ( ( TimeAggregatedActivityValues ) inMemoryColumnData2 . getActivityValuesMap ( ) . get ( "<STR_LIT>" ) ) ; initialVersion = FileDataProviderWithMocks . instances . get ( <NUM_LIT:0> ) . getOffset ( ) ; initialVersion = Math . max ( initialVersion , FileDataProviderWithMocks . instances . get ( <NUM_LIT:1> ) . getOffset ( ) ) ; initialVersion -- ; expectedVersion = initialVersion ; } public void test1SendUpdatesAndSort ( ) throws Exception { String req = "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:0> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:1> ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:10> ; i ++ ) { FileDataProviderWithMocks . add ( new JSONObject ( ) . put ( "<STR_LIT:id>" , <NUM_LIT> + i ) . put ( SenseiSchema . EVENT_TYPE_FIELD , SenseiSchema . EVENT_TYPE_UPDATE ) . put ( "<STR_LIT>" , "<STR_LIT:+>" + ( <NUM_LIT:10> + i ) ) ) ; expectedVersion ++ ; } syncWithVersion ( expectedVersion ) ; req = "<STR_LIT>" ; System . out . println ( "<STR_LIT>" ) ; res = TestSensei . search ( new JSONObject ( req ) ) ; hits = res . getJSONArray ( "<STR_LIT>" ) ; assertEquals ( CompositeActivityManager . cachedInstances . get ( <NUM_LIT:1> ) . activityValues . getIntValueByUID ( <NUM_LIT> , "<STR_LIT>" ) , <NUM_LIT:20> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:0> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:20> ) ; assertEquals ( CompositeActivityManager . cachedInstances . get ( <NUM_LIT:1> ) . activityValues . getIntValueByUID ( <NUM_LIT> , "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:1> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT> ) ; assertEquals ( CompositeActivityManager . cachedInstances . get ( <NUM_LIT:2> ) . activityValues . getIntValueByUID ( <NUM_LIT> , "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:2> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT> ) ; } public void test1bSendUpdatesAndSort ( ) throws Exception { String req = "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:0> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:20> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:1> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:2> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT> ) ; System . out . println ( "<STR_LIT>" + res . toString ( <NUM_LIT:1> ) ) ; } public void test1CSendUpdatesAndSortFloat ( ) throws Exception { String req = "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:0> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:0> ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:10> ; i ++ ) { FileDataProviderWithMocks . add ( new JSONObject ( ) . put ( "<STR_LIT:id>" , <NUM_LIT> + i ) . put ( SenseiSchema . EVENT_TYPE_FIELD , SenseiSchema . EVENT_TYPE_UPDATE ) . put ( "<STR_LIT>" , "<STR_LIT:+>" + ( <NUM_LIT> + i ) ) ) ; expectedVersion ++ ; } syncWithVersion ( expectedVersion ) ; req = "<STR_LIT>" ; System . out . println ( "<STR_LIT>" ) ; res = TestSensei . search ( new JSONObject ( req ) ) ; hits = res . getJSONArray ( "<STR_LIT>" ) ; assertEquals ( CompositeActivityManager . cachedInstances . get ( <NUM_LIT:1> ) . activityValues . getFloatValueByUID ( <NUM_LIT> , "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( Float . parseFloat ( hits . getJSONObject ( <NUM_LIT:0> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT> ) ; assertEquals ( CompositeActivityManager . cachedInstances . get ( <NUM_LIT:1> ) . activityValues . getFloatValueByUID ( <NUM_LIT> , "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( Float . parseFloat ( hits . getJSONObject ( <NUM_LIT:1> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT> ) ; } private static void syncWithVersion ( final long expectedVersion ) { final CompositeActivityValues inMemoryColumnData1 = CompositeActivityManager . cachedInstances . get ( <NUM_LIT:1> ) . activityValues ; final CompositeActivityValues inMemoryColumnData2 = CompositeActivityManager . cachedInstances . get ( <NUM_LIT:2> ) . activityValues ; Wait . until ( <NUM_LIT> , "<STR_LIT>" , new Wait . Condition ( ) { public boolean evaluate ( ) { long v1 = Long . parseLong ( inMemoryColumnData1 . getVersion ( ) ) ; long v2 = Long . parseLong ( inMemoryColumnData2 . getVersion ( ) ) ; return ( v1 == expectedVersion || v2 == expectedVersion ) && ( v1 >= expectedVersion - <NUM_LIT:1> && v2 >= expectedVersion - <NUM_LIT:1> ) ; } } ) ; } public void test2SendUpdateAndCheckIfItsPersisted ( ) throws Exception { for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:5> ; i ++ ) { FileDataProviderWithMocks . add ( new JSONObject ( ) . put ( "<STR_LIT:id>" , <NUM_LIT:1L> ) . put ( SenseiSchema . EVENT_TYPE_FIELD , SenseiSchema . EVENT_TYPE_UPDATE ) . put ( "<STR_LIT>" , "<STR_LIT>" ) ) ; expectedVersion ++ ; } final CompositeActivityValues inMemoryColumnData1 = CompositeActivityManager . cachedInstances . get ( <NUM_LIT:1> ) . activityValues ; final CompositeActivityValues inMemoryColumnData2 = CompositeActivityManager . cachedInstances . get ( <NUM_LIT:2> ) . activityValues ; Wait . until ( <NUM_LIT> , "<STR_LIT>" , new Wait . Condition ( ) { public boolean evaluate ( ) { return inMemoryColumnData1 . getIntValueByUID ( <NUM_LIT:1L> , "<STR_LIT>" ) == <NUM_LIT> || inMemoryColumnData2 . getIntValueByUID ( <NUM_LIT:1L> , "<STR_LIT>" ) == <NUM_LIT> ; } } ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:5> ; i ++ ) { FileDataProviderWithMocks . add ( new JSONObject ( ) . put ( "<STR_LIT:id>" , <NUM_LIT:1L> ) . put ( SenseiSchema . EVENT_TYPE_FIELD , SenseiSchema . EVENT_TYPE_UPDATE ) . put ( "<STR_LIT>" , "<STR_LIT>" ) ) ; expectedVersion ++ ; } Wait . until ( <NUM_LIT> , "<STR_LIT>" , new Wait . Condition ( ) { public boolean evaluate ( ) { return inMemoryColumnData1 . getIntValueByUID ( <NUM_LIT:1L> , "<STR_LIT>" ) == <NUM_LIT> || inMemoryColumnData2 . getIntValueByUID ( <NUM_LIT:1L> , "<STR_LIT>" ) == <NUM_LIT> ; } } ) ; } public void test3AggregatesIntegrationTest ( ) throws Exception { final CompositeActivityValues inMemoryColumnData1 = CompositeActivityManager . cachedInstances . get ( <NUM_LIT:1> ) . activityValues ; final CompositeActivityValues inMemoryColumnData2 = CompositeActivityManager . cachedInstances . get ( <NUM_LIT:2> ) . activityValues ; final TimeAggregatedActivityValues timeAggregatedActivityValues1 = clear ( inMemoryColumnData1 ) ; final TimeAggregatedActivityValues timeAggregatedActivityValues2 = clear ( inMemoryColumnData2 ) ; for ( ActivityIntValues activityIntValues : timeAggregatedActivityValues1 . getValuesMap ( ) . values ( ) ) { assertEquals ( <NUM_LIT:0> , activityIntValues . getIntValue ( <NUM_LIT:0> ) ) ; } for ( ActivityIntValues activityIntValues : timeAggregatedActivityValues2 . getValuesMap ( ) . values ( ) ) { for ( int i = <NUM_LIT:0> ; i < activityIntValues . getFieldValues ( ) . length ; i ++ ) { assertEquals ( "<STR_LIT>" + i , <NUM_LIT:0> , activityIntValues . getFieldValues ( ) [ i ] ) ; } } int initialTime = Clock . getCurrentTimeInMinutes ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:10> ; i ++ ) { final int uid = i ; Clock . setPredefinedTimeInMinutes ( Clock . getCurrentTimeInMinutes ( ) + <NUM_LIT:1> ) ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:10> - i ; j ++ ) { FileDataProviderWithMocks . add ( new JSONObject ( ) . put ( "<STR_LIT:id>" , j ) . put ( SenseiSchema . EVENT_TYPE_FIELD , SenseiSchema . EVENT_TYPE_UPDATE ) . put ( "<STR_LIT>" , "<STR_LIT>" ) ) ; expectedVersion ++ ; } syncWithVersion ( expectedVersion ) ; } String req = "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:0> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:10> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:1> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:9> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:2> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:8> ) ; Clock . setPredefinedTimeInMinutes ( initialTime + <NUM_LIT:11> ) ; timeAggregatedActivityValues1 . getAggregatesUpdateJob ( ) . run ( ) ; timeAggregatedActivityValues2 . getAggregatesUpdateJob ( ) . run ( ) ; req = "<STR_LIT>" ; res = TestSensei . search ( new JSONObject ( req ) ) ; hits = res . getJSONArray ( "<STR_LIT>" ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:0> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:4> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:1> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:3> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:2> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:2> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:0> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:10> ) ; Clock . setPredefinedTimeInMinutes ( initialTime + <NUM_LIT:20> ) ; timeAggregatedActivityValues1 . getAggregatesUpdateJob ( ) . run ( ) ; timeAggregatedActivityValues2 . getAggregatesUpdateJob ( ) . run ( ) ; req = "<STR_LIT>" ; res = TestSensei . search ( new JSONObject ( req ) ) ; hits = res . getJSONArray ( "<STR_LIT>" ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:0> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:0> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:0> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:5> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:1> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:4> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:2> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:3> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:3> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:2> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:4> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:1> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:5> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:0> ) ; inMemoryColumnData1 . delete ( <NUM_LIT> ) ; inMemoryColumnData2 . delete ( <NUM_LIT> ) ; req = "<STR_LIT>" ; res = TestSensei . search ( new JSONObject ( req ) ) ; hits = res . getJSONArray ( "<STR_LIT>" ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:0> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:4> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:1> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:3> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:2> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:2> ) ; } public void test6AddDeleteAddAgainAndQuery ( ) throws Exception { final CompositeActivityValues inMemoryColumnData1 = CompositeActivityManager . cachedInstances . get ( <NUM_LIT:1> ) . activityValues ; final CompositeActivityValues inMemoryColumnData2 = CompositeActivityManager . cachedInstances . get ( <NUM_LIT:2> ) . activityValues ; final TimeAggregatedActivityValues timeAggregatedActivityValues1 = clear ( inMemoryColumnData1 ) ; final TimeAggregatedActivityValues timeAggregatedActivityValues2 = clear ( inMemoryColumnData2 ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:10> ; i ++ ) { FileDataProviderWithMocks . add ( new JSONObject ( ) . put ( "<STR_LIT:id>" , i ) . put ( SenseiSchema . EVENT_TYPE_FIELD , SenseiSchema . EVENT_TYPE_UPDATE ) . put ( "<STR_LIT>" , "<STR_LIT:+>" + i ) ) ; expectedVersion ++ ; } inMemoryColumnData1 . syncWithVersion ( String . valueOf ( expectedVersion ) ) ; String req = "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:0> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:9> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:0> ) . getString ( "<STR_LIT>" ) ) , <NUM_LIT:9> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:1> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:8> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:1> ) . getString ( "<STR_LIT>" ) ) , <NUM_LIT:8> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:2> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:7> ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:2> ) . getString ( "<STR_LIT>" ) ) , <NUM_LIT:7> ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:10> ; i ++ ) { inMemoryColumnData1 . delete ( i ) ; inMemoryColumnData2 . delete ( i ) ; } req = "<STR_LIT>" ; res = TestSensei . search ( new JSONObject ( req ) ) ; hits = res . getJSONArray ( "<STR_LIT>" ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:0> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:0> ) ; inMemoryColumnData1 . flushDeletes ( ) ; inMemoryColumnData2 . flushDeletes ( ) ; Thread . sleep ( <NUM_LIT:1000> ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:10> ; i ++ ) { FileDataProviderWithMocks . add ( new JSONObject ( ) . put ( "<STR_LIT:id>" , i ) . put ( SenseiSchema . EVENT_TYPE_FIELD , SenseiSchema . EVENT_TYPE_UPDATE ) . put ( "<STR_LIT>" , "<STR_LIT:+>" + i ) ) ; expectedVersion ++ ; } inMemoryColumnData1 . syncWithVersion ( String . valueOf ( expectedVersion ) ) ; req = "<STR_LIT>" ; ; res = TestSensei . search ( new JSONObject ( req ) ) ; System . out . println ( res . toString ( <NUM_LIT:1> ) ) ; hits = res . getJSONArray ( "<STR_LIT>" ) ; assertTrue ( hits . length ( ) > <NUM_LIT:0> ) ; } public void test5bIncreaseNonExistingActivityValue ( ) throws Exception { final CompositeActivityManager inMemoryColumnData1 = CompositeActivityManager . cachedInstances . get ( <NUM_LIT:1> ) ; final CompositeActivityManager inMemoryColumnData2 = CompositeActivityManager . cachedInstances . get ( <NUM_LIT:2> ) ; String req = "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; FileDataProviderWithMocks . add ( new JSONObject ( ) . put ( "<STR_LIT:id>" , <NUM_LIT> ) . put ( SenseiSchema . EVENT_TYPE_FIELD , SenseiSchema . EVENT_TYPE_UPDATE ) . put ( "<STR_LIT>" , "<STR_LIT:+>" + <NUM_LIT:100> ) ) ; expectedVersion ++ ; inMemoryColumnData2 . getActivityValues ( ) . syncWithVersion ( String . valueOf ( expectedVersion ) ) ; req = "<STR_LIT>" ; res = TestSensei . search ( new JSONObject ( req ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:0> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:100> ) ; req = "<STR_LIT>" ; res = TestSensei . search ( new JSONObject ( req ) ) ; hits = res . getJSONArray ( "<STR_LIT>" ) ; assertEquals ( Integer . parseInt ( hits . getJSONObject ( <NUM_LIT:0> ) . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ) , <NUM_LIT:100> ) ; } public void ntest7RelevanceActivity ( ) throws Exception { FileDataProviderWithMocks . add ( new JSONObject ( ) . put ( "<STR_LIT:id>" , <NUM_LIT> ) . put ( SenseiSchema . EVENT_TYPE_FIELD , SenseiSchema . EVENT_TYPE_UPDATE ) . put ( "<STR_LIT>" , <NUM_LIT> ) ) ; expectedVersion ++ ; syncWithVersion ( expectedVersion ) ; { String req = "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } { String req = "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; double secondScore = secondHit . getDouble ( "<STR_LIT>" ) ; double delta1 = firstScore - <NUM_LIT> ; double delta2 = secondScore - <NUM_LIT> ; assertEquals ( "<STR_LIT>" + delta1 , true , Math . abs ( delta1 ) < <NUM_LIT> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( delta2 ) < <NUM_LIT:1> ) ; int first_aggregated_likes_2w = firstHit . getJSONArray ( "<STR_LIT>" ) . getInt ( <NUM_LIT:0> ) ; int first_aggregated_likes_12h = firstHit . getJSONArray ( "<STR_LIT>" ) . getInt ( <NUM_LIT:0> ) ; int second_aggregated_likes_2w = secondHit . getJSONArray ( "<STR_LIT>" ) . getInt ( <NUM_LIT:0> ) ; int second_aggregated_likes_12h = secondHit . getJSONArray ( "<STR_LIT>" ) . getInt ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , true , first_aggregated_likes_2w == <NUM_LIT> ) ; assertEquals ( "<STR_LIT>" , true , first_aggregated_likes_12h == <NUM_LIT> ) ; } } public void test5PurgeUnusedActivities ( ) throws Exception { final CompositeActivityManager inMemoryColumnData1 = CompositeActivityManager . cachedInstances . get ( <NUM_LIT:1> ) ; final CompositeActivityManager inMemoryColumnData2 = CompositeActivityManager . cachedInstances . get ( <NUM_LIT:2> ) ; int count1 = inMemoryColumnData1 . getPurgeUnusedActivitiesJob ( ) . purgeUnusedActivityIndexes ( ) ; int count2 = inMemoryColumnData2 . getPurgeUnusedActivitiesJob ( ) . purgeUnusedActivityIndexes ( ) ; assertEquals ( <NUM_LIT:0> , count1 + count2 ) ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:10> ; j ++ ) { inMemoryColumnData1 . acceptEvent ( new JSONObject ( ) . put ( "<STR_LIT:id>" , j + <NUM_LIT> ) . put ( SenseiSchema . EVENT_TYPE_FIELD , SenseiSchema . EVENT_TYPE_UPDATE ) . put ( "<STR_LIT>" , "<STR_LIT:+>" + <NUM_LIT:1> ) , String . valueOf ( expectedVersion + <NUM_LIT:1> ) ) ; inMemoryColumnData2 . acceptEvent ( new JSONObject ( ) . put ( "<STR_LIT:id>" , j + <NUM_LIT> ) . put ( SenseiSchema . EVENT_TYPE_FIELD , SenseiSchema . EVENT_TYPE_UPDATE ) . put ( "<STR_LIT>" , "<STR_LIT:+>" + <NUM_LIT:1> ) , String . valueOf ( expectedVersion + <NUM_LIT:1> ) ) ; expectedVersion ++ ; } FileDataProviderWithMocks . resetOffset ( expectedVersion ) ; inMemoryColumnData1 . getActivityValues ( ) . syncWithVersion ( String . valueOf ( expectedVersion ) ) ; count1 = inMemoryColumnData1 . getPurgeUnusedActivitiesJob ( ) . purgeUnusedActivityIndexes ( ) ; count2 = inMemoryColumnData2 . getPurgeUnusedActivitiesJob ( ) . purgeUnusedActivityIndexes ( ) ; assertEquals ( <NUM_LIT:0> , count1 + count2 ) ; inMemoryColumnData1 . activityValues . recentlyAddedUids . clear ( ) ; inMemoryColumnData2 . activityValues . recentlyAddedUids . clear ( ) ; count1 = inMemoryColumnData1 . getPurgeUnusedActivitiesJob ( ) . purgeUnusedActivityIndexes ( ) ; count2 = inMemoryColumnData2 . getPurgeUnusedActivitiesJob ( ) . purgeUnusedActivityIndexes ( ) ; assertEquals ( <NUM_LIT:20> , count1 + count2 ) ; } public void test6OpeningTheNewActivityFieldValues ( ) throws Exception { final CompositeActivityValues inMemoryColumnData1 = CompositeActivityManager . cachedInstances . get ( <NUM_LIT:1> ) . activityValues ; inMemoryColumnData1 . flush ( ) ; inMemoryColumnData1 . syncWithPersistentVersion ( String . valueOf ( expectedVersion - <NUM_LIT:1> ) ) ; inMemoryColumnData2 . flush ( ) ; inMemoryColumnData2 . syncWithPersistentVersion ( String . valueOf ( expectedVersion - <NUM_LIT:1> ) ) ; String absolutePath = SenseiStarter . IndexDir + "<STR_LIT>" + "<STR_LIT>" ; FieldDefinition fieldDefinition = getLikesFieldDefinition ( ) ; CompositeActivityValues compositeActivityValues = CompositeActivityValues . createCompositeValues ( ActivityPersistenceFactory . getInstance ( absolutePath , new ActivityConfig ( ) ) , java . util . Arrays . asList ( fieldDefinition ) , Collections . EMPTY_LIST , ZoieConfig . DEFAULT_VERSION_COMPARATOR ) ; assertEquals ( <NUM_LIT:1> , compositeActivityValues . getIntValueByUID ( <NUM_LIT:1L> , "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:1> , inMemoryColumnData1 . getIntValueByUID ( <NUM_LIT:1L> , "<STR_LIT>" ) ) ; } public static FieldDefinition getLikesFieldDefinition ( ) { return getIntFieldDefinition ( "<STR_LIT>" ) ; } public static FieldDefinition getIntFieldDefinition ( String name ) { FieldDefinition fieldDefinition = new FieldDefinition ( ) ; fieldDefinition . name = name ; fieldDefinition . type = int . class ; fieldDefinition . isActivity = true ; return fieldDefinition ; } private synchronized TimeAggregatedActivityValues clear ( final CompositeActivityValues inMemoryColumnData1 ) throws Exception { final TimeAggregatedActivityValues timeAggregatedActivityValues = ( TimeAggregatedActivityValues ) inMemoryColumnData1 . getActivityValuesMap ( ) . get ( "<STR_LIT>" ) ; timeAggregatedActivityValues . getAggregatesUpdateJob ( ) . stop ( ) ; timeAggregatedActivityValues . getAggregatesUpdateJob ( ) . awaitTermination ( ) ; Thread . sleep ( <NUM_LIT:1000> ) ; for ( int i = <NUM_LIT:0> ; i <= timeAggregatedActivityValues . maxIndex ; i ++ ) { timeAggregatedActivityValues . getDefaultIntValues ( ) . getFieldValues ( ) [ i ] = <NUM_LIT:0> ; timeAggregatedActivityValues . getTimeActivities ( ) . reset ( i ) ; for ( ActivityIntValues activityIntValues : timeAggregatedActivityValues . getValuesMap ( ) . values ( ) ) { activityIntValues . getFieldValues ( ) [ i ] = <NUM_LIT:0> ; } } return timeAggregatedActivityValues ; } } </s>
<s> package com . senseidb . test ; import java . io . File ; import proj . zoie . api . DirectoryManager . DIRECTORY_MODE ; import proj . zoie . api . indexing . ZoieIndexableInterpreter ; import proj . zoie . impl . indexing . ZoieConfig ; import proj . zoie . impl . indexing . ZoieSystem ; import com . browseengine . bobo . api . BoboIndexReader ; import com . senseidb . search . node . SenseiIndexReaderDecorator ; import com . senseidb . search . node . SenseiZoieSystemFactory ; public class ZoieTestFactory < T > extends SenseiZoieSystemFactory < T > { public ZoieTestFactory ( File idxDir , ZoieIndexableInterpreter < T > interpreter , SenseiIndexReaderDecorator indexReaderDecorator , ZoieConfig zoieConfig ) { super ( idxDir , DIRECTORY_MODE . SIMPLE , interpreter , indexReaderDecorator , zoieConfig ) ; } @ Override public ZoieSystem < BoboIndexReader , T > getZoieInstance ( int nodeId , int partitionId ) { File partDir = getPath ( nodeId , partitionId ) ; if ( ! partDir . exists ( ) ) { partDir . mkdirs ( ) ; } return new ZoieSystem < BoboIndexReader , T > ( partDir , _interpreter , _indexReaderDecorator , _zoieConfig ) ; } @ Override public File getPath ( int nodeId , int partitionId ) { return _idxDir ; } } </s>
<s> package com . senseidb . test ; import org . apache . log4j . Logger ; import com . linkedin . norbert . javacompat . network . RequestHandler ; import com . senseidb . search . req . SenseiGenericRequest ; import com . senseidb . search . req . SenseiGenericResult ; public class GenericMessageHandler implements RequestHandler < SenseiGenericRequest , SenseiGenericResult > { private final static Logger logger = Logger . getLogger ( GenericMessageHandler . class ) ; @ Override public SenseiGenericResult handleRequest ( SenseiGenericRequest request ) throws Exception { SenseiGenericResult result = new SenseiGenericResult ( ) ; result . setClassname ( "<STR_LIT>" ) ; result . setResult ( "<STR_LIT>" + request . getClassname ( ) + request . getRequest ( ) ) ; return result ; } } </s>
<s> package com . senseidb . test ; import org . junit . Ignore ; import junit . framework . Test ; import junit . framework . TestSuite ; import junit . textui . TestRunner ; @ Ignore public class SenseiTestSuite extends TestSuite { public static Test suite ( ) { TestSuite suite = new TestSuite ( ) ; suite . addTestSuite ( TestSensei . class ) ; suite . addTestSuite ( TestIndexingAPI . class ) ; suite . addTestSuite ( TestRestServer . class ) ; return suite ; } public static void main ( String [ ] args ) { TestRunner . run ( suite ( ) ) ; } } </s>
<s> package com . senseidb . test ; import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . InputStreamReader ; import java . io . OutputStreamWriter ; import java . net . URL ; import java . net . URLConnection ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; import junit . framework . TestCase ; import org . apache . log4j . Logger ; import org . json . JSONArray ; import org . json . JSONException ; import org . json . JSONObject ; import com . browseengine . bobo . api . BrowseFacet ; import com . browseengine . bobo . api . BrowseSelection ; import com . browseengine . bobo . api . FacetAccessible ; import com . browseengine . bobo . api . FacetSpec ; import com . browseengine . bobo . api . FacetSpec . FacetSortSpec ; import com . browseengine . bobo . facets . DefaultFacetHandlerInitializerParam ; import com . senseidb . search . node . SenseiBroker ; import com . senseidb . search . req . SenseiHit ; import com . senseidb . search . req . SenseiRequest ; import com . senseidb . search . req . SenseiResult ; import com . senseidb . svc . api . SenseiService ; public class TestSensei extends TestCase { private static final Logger logger = Logger . getLogger ( TestSensei . class ) ; private static SenseiBroker broker ; private static SenseiService httpRestSenseiService ; static { SenseiStarter . start ( "<STR_LIT>" , "<STR_LIT>" ) ; broker = SenseiStarter . broker ; httpRestSenseiService = SenseiStarter . httpRestSenseiService ; } public void testTotalCount ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; SenseiRequest req = new SenseiRequest ( ) ; SenseiResult res = broker . browse ( req ) ; assertEquals ( "<STR_LIT>" + req + res , <NUM_LIT> , res . getNumHits ( ) ) ; logger . info ( "<STR_LIT>" + req + "<STR_LIT>" + res ) ; } public void testTotalCountWithFacetSpec ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; SenseiRequest req = new SenseiRequest ( ) ; FacetSpec facetSpecall = new FacetSpec ( ) ; facetSpecall . setMaxCount ( <NUM_LIT> ) ; facetSpecall . setExpandSelection ( true ) ; facetSpecall . setMinHitCount ( <NUM_LIT:0> ) ; facetSpecall . setOrderBy ( FacetSortSpec . OrderHitsDesc ) ; FacetSpec facetSpec = new FacetSpec ( ) ; facetSpec . setMaxCount ( <NUM_LIT:5> ) ; setspec ( req , facetSpec ) ; req . setCount ( <NUM_LIT:5> ) ; setspec ( req , facetSpecall ) ; SenseiResult res = broker . browse ( req ) ; logger . info ( "<STR_LIT>" + req + "<STR_LIT>" + res ) ; verifyFacetCount ( res , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> ) ; } public void testSelection ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; FacetSpec facetSpecall = new FacetSpec ( ) ; facetSpecall . setMaxCount ( <NUM_LIT> ) ; facetSpecall . setExpandSelection ( true ) ; facetSpecall . setMinHitCount ( <NUM_LIT:0> ) ; facetSpecall . setOrderBy ( FacetSortSpec . OrderHitsDesc ) ; FacetSpec facetSpec = new FacetSpec ( ) ; facetSpec . setMaxCount ( <NUM_LIT:5> ) ; SenseiRequest req = new SenseiRequest ( ) ; req . setCount ( <NUM_LIT:3> ) ; facetSpecall . setMaxCount ( <NUM_LIT:3> ) ; setspec ( req , facetSpecall ) ; BrowseSelection sel = new BrowseSelection ( "<STR_LIT>" ) ; String selVal = "<STR_LIT>" ; sel . addValue ( selVal ) ; req . addSelection ( sel ) ; SenseiResult res = broker . browse ( req ) ; logger . info ( "<STR_LIT>" + req + "<STR_LIT>" + res ) ; assertEquals ( <NUM_LIT> , res . getNumHits ( ) ) ; String selName = "<STR_LIT>" ; verifyFacetCount ( res , selName , selVal , <NUM_LIT> ) ; verifyFacetCount ( res , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> ) ; } public void testSelectionDynamicTimeRange ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; SenseiRequest req = new SenseiRequest ( ) ; DefaultFacetHandlerInitializerParam initParam = new DefaultFacetHandlerInitializerParam ( ) ; initParam . putLongParam ( "<STR_LIT>" , new long [ ] { <NUM_LIT> } ) ; req . setFacetHandlerInitializerParam ( "<STR_LIT>" , initParam ) ; req . setCount ( <NUM_LIT:3> ) ; BrowseSelection sel = new BrowseSelection ( "<STR_LIT>" ) ; String selVal = "<STR_LIT>" ; sel . addValue ( selVal ) ; req . addSelection ( sel ) ; SenseiResult res = broker . browse ( req ) ; logger . info ( "<STR_LIT>" + req + "<STR_LIT>" + res ) ; assertEquals ( <NUM_LIT> , res . getNumHits ( ) ) ; } public void testSelectionNot ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; FacetSpec facetSpecall = new FacetSpec ( ) ; facetSpecall . setMaxCount ( <NUM_LIT> ) ; facetSpecall . setExpandSelection ( true ) ; facetSpecall . setMinHitCount ( <NUM_LIT:0> ) ; facetSpecall . setOrderBy ( FacetSortSpec . OrderHitsDesc ) ; FacetSpec facetSpec = new FacetSpec ( ) ; facetSpec . setMaxCount ( <NUM_LIT:5> ) ; SenseiRequest req = new SenseiRequest ( ) ; req . setCount ( <NUM_LIT:3> ) ; facetSpecall . setMaxCount ( <NUM_LIT:3> ) ; setspec ( req , facetSpecall ) ; BrowseSelection sel = new BrowseSelection ( "<STR_LIT>" ) ; sel . addNotValue ( "<STR_LIT>" ) ; req . addSelection ( sel ) ; SenseiResult res = broker . browse ( req ) ; logger . info ( "<STR_LIT>" + req + "<STR_LIT>" + res ) ; assertEquals ( <NUM_LIT> , res . getNumHits ( ) ) ; verifyFacetCount ( res , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> ) ; } public void testGroupBy ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; SenseiRequest req = new SenseiRequest ( ) ; req . setCount ( <NUM_LIT:1> ) ; req . setGroupBy ( new String [ ] { "<STR_LIT>" } ) ; SenseiResult res = broker . browse ( req ) ; logger . info ( "<STR_LIT>" + req + "<STR_LIT>" + res ) ; SenseiHit hit = res . getSenseiHits ( ) [ <NUM_LIT:0> ] ; assertTrue ( hit . getGroupHitsCount ( ) > <NUM_LIT:0> ) ; } public void testGroupByWithGroupedHits ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; SenseiRequest req = new SenseiRequest ( ) ; req . setCount ( <NUM_LIT:1> ) ; req . setGroupBy ( new String [ ] { "<STR_LIT>" } ) ; req . setMaxPerGroup ( <NUM_LIT:8> ) ; SenseiResult res = broker . browse ( req ) ; logger . info ( "<STR_LIT>" + req + "<STR_LIT>" + res ) ; SenseiHit hit = res . getSenseiHits ( ) [ <NUM_LIT:0> ] ; assertTrue ( hit . getGroupHitsCount ( ) > <NUM_LIT:0> ) ; assertTrue ( hit . getSenseiGroupHits ( ) . length > <NUM_LIT:0> ) ; res = httpRestSenseiService . doQuery ( req ) ; logger . info ( "<STR_LIT>" + req + "<STR_LIT>" + res ) ; hit = res . getSenseiHits ( ) [ <NUM_LIT:0> ] ; assertTrue ( hit . getGroupHitsCount ( ) > <NUM_LIT:0> ) ; assertTrue ( hit . getSenseiGroupHits ( ) . length > <NUM_LIT:0> ) ; } public void testGroupByVirtual ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; SenseiRequest req = new SenseiRequest ( ) ; req . setCount ( <NUM_LIT:1> ) ; req . setGroupBy ( new String [ ] { "<STR_LIT>" } ) ; SenseiResult res = broker . browse ( req ) ; logger . info ( "<STR_LIT>" + req + "<STR_LIT>" + res ) ; SenseiHit hit = res . getSenseiHits ( ) [ <NUM_LIT:0> ] ; assertTrue ( hit . getGroupHitsCount ( ) > <NUM_LIT:0> ) ; } public void testGroupByVirtualWithGroupedHits ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; SenseiRequest req = new SenseiRequest ( ) ; req . setCount ( <NUM_LIT:1> ) ; req . setGroupBy ( new String [ ] { "<STR_LIT>" } ) ; req . setMaxPerGroup ( <NUM_LIT:8> ) ; SenseiResult res = broker . browse ( req ) ; logger . info ( "<STR_LIT>" + req + "<STR_LIT>" + res ) ; SenseiHit hit = res . getSenseiHits ( ) [ <NUM_LIT:0> ] ; assertTrue ( hit . getGroupHitsCount ( ) > <NUM_LIT:0> ) ; assertTrue ( hit . getSenseiGroupHits ( ) . length > <NUM_LIT:0> ) ; } public void testGroupByFixedLengthLongArray ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; SenseiRequest req = new SenseiRequest ( ) ; req . setCount ( <NUM_LIT:1> ) ; req . setGroupBy ( new String [ ] { "<STR_LIT>" } ) ; SenseiResult res = broker . browse ( req ) ; logger . info ( "<STR_LIT>" + req + "<STR_LIT>" + res ) ; SenseiHit hit = res . getSenseiHits ( ) [ <NUM_LIT:0> ] ; assertTrue ( hit . getGroupHitsCount ( ) > <NUM_LIT:0> ) ; } public void testGroupByFixedLengthLongArrayWithGroupedHits ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; SenseiRequest req = new SenseiRequest ( ) ; req . setCount ( <NUM_LIT:1> ) ; req . setGroupBy ( new String [ ] { "<STR_LIT>" } ) ; req . setMaxPerGroup ( <NUM_LIT:8> ) ; SenseiResult res = broker . browse ( req ) ; logger . info ( "<STR_LIT>" + req + "<STR_LIT>" + res ) ; SenseiHit hit = res . getSenseiHits ( ) [ <NUM_LIT:0> ] ; assertTrue ( hit . getGroupHitsCount ( ) > <NUM_LIT:0> ) ; assertTrue ( hit . getSenseiGroupHits ( ) . length > <NUM_LIT:0> ) ; } public void testBQL1 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testBQL2 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testBqlExtraFilter ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testBqlRelevance1 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; String firstYear = firstHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String secondYear = secondHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , true , firstYear . contains ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , true , secondYear . contains ( "<STR_LIT>" ) ) ; } public void testSelectionTerm ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testSelectionTerms ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testSelectionDynamicTimeRangeJson ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; System . out . println ( req ) ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testSelectionDynamicTimeRangeJson2 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; System . out . println ( req ) ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testSelectionRange ( ) throws Exception { { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } } public void testMatchAllWithBoostQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testQueryStringQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testMatchAllQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testUIDQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:4> , res . getInt ( "<STR_LIT>" ) ) ; Set < Integer > expectedIds = new HashSet ( Arrays . asList ( new Integer [ ] { <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:6> } ) ) ; for ( int i = <NUM_LIT:0> ; i < res . getInt ( "<STR_LIT>" ) ; ++ i ) { int uid = res . getJSONArray ( "<STR_LIT>" ) . getJSONObject ( i ) . getInt ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" + uid + "<STR_LIT>" , expectedIds . contains ( uid ) ) ; } } public void testTextQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testTermQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testTermsQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testBooleanQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testDistMaxQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testPathQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testPrefixQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testWildcardQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testRangeQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testRangeQuery2 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testFilteredQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testSpanTermQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testSpanOrQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testSpanNotQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testSpanNearQuery1 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testSpanNearQuery2 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testSpanFirstQuery ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testNullMultiFilter ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testNullFilterOnSimpleColumn ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , res . getInt ( "<STR_LIT>" ) ) ; } public void testUIDFilter ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:2> , res . getInt ( "<STR_LIT>" ) ) ; Set < Integer > expectedIds = new HashSet ( Arrays . asList ( new Integer [ ] { <NUM_LIT:1> , <NUM_LIT:3> } ) ) ; for ( int i = <NUM_LIT:0> ; i < res . getInt ( "<STR_LIT>" ) ; ++ i ) { int uid = res . getJSONArray ( "<STR_LIT>" ) . getJSONObject ( i ) . getInt ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" + uid + "<STR_LIT>" , expectedIds . contains ( uid ) ) ; } } public void testAndFilter ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testOrFilter ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testOrFilter2 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testOrFilter3 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testBooleanFilter ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testQueryFilter ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testAndFilter1 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testQueryFilter1 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testAndFilter2 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testOrFilter4 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testTermFilter ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testTermsFilter ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testRangeFilter ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testRangeFilter2 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testRangeFilter3 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertTrue ( "<STR_LIT>" , res . getInt ( "<STR_LIT>" ) > <NUM_LIT:10> ) ; } public void testFallbackGroupBy ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; assertTrue ( "<STR_LIT>" , "<STR_LIT>" . equals ( firstHit . getString ( "<STR_LIT>" ) ) || "<STR_LIT>" . equals ( firstHit . getString ( "<STR_LIT>" ) ) ) ; assertTrue ( "<STR_LIT>" , firstHit . getJSONArray ( "<STR_LIT>" ) != null ) ; } public void testGetStoreRequest ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = searchGet ( new JSONArray ( req ) ) ; assertTrue ( "<STR_LIT>" , res . length ( ) == <NUM_LIT:4> ) ; assertNotNull ( "<STR_LIT>" , res . get ( String . valueOf ( <NUM_LIT:1> ) ) ) ; } public void testRelevanceMatchAll ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testRelevanceHashSet ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; String firstYear = firstHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String secondYear = secondHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , true , firstYear . contains ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , true , secondYear . contains ( "<STR_LIT>" ) ) ; } public void testRelevanceMath ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; double secondScore = secondHit . getDouble ( "<STR_LIT>" ) ; double delta1 = firstScore - Math . exp ( <NUM_LIT> ) ; double delta2 = secondScore - Math . exp ( <NUM_LIT> ) ; assertEquals ( "<STR_LIT>" + delta1 , true , Math . abs ( delta1 ) < <NUM_LIT> ) ; assertEquals ( "<STR_LIT>" + delta2 , true , Math . abs ( delta2 ) < <NUM_LIT> ) ; } public void testRelevanceInnerScore ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; double secondScore = secondHit . getDouble ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , true , firstScore == <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , secondScore == <NUM_LIT:1> ) ; } public void testRelevanceNOW ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" + System . currentTimeMillis ( ) + "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; double secondScore = secondHit . getDouble ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , true , firstScore == <NUM_LIT> ) ; assertEquals ( "<STR_LIT>" , true , secondScore == <NUM_LIT> ) ; } public void testRelevanceHashMapInt2Float ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; double secondScore = secondHit . getDouble ( "<STR_LIT>" ) ; String firstMileage = firstHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String secondMileage = secondHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( firstScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( secondScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , Integer . parseInt ( firstMileage ) == <NUM_LIT> ) ; assertEquals ( "<STR_LIT>" , true , Integer . parseInt ( secondMileage ) == <NUM_LIT> ) ; } public void testRelevanceHashMapInt2String ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; double secondScore = secondHit . getDouble ( "<STR_LIT>" ) ; String firstYear = firstHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String secondYear = secondHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String firstColor = firstHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String secondColor = secondHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( firstScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( secondScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , Integer . parseInt ( firstYear ) == <NUM_LIT> ) ; assertEquals ( "<STR_LIT>" , true , Integer . parseInt ( secondYear ) == <NUM_LIT> ) ; assertEquals ( "<STR_LIT>" , true , firstColor . equals ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , true , secondColor . equals ( "<STR_LIT>" ) ) ; } public void testRelevanceHashMapString2Float ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; double secondScore = secondHit . getDouble ( "<STR_LIT>" ) ; String firstColor = firstHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String secondColor = secondHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( firstScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( secondScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , firstColor . equals ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , true , secondColor . equals ( "<STR_LIT>" ) ) ; } public void testRelevanceHashMapString2String ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; double secondScore = secondHit . getDouble ( "<STR_LIT>" ) ; String firstCategory = firstHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String secondCategory = secondHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String firstColor = firstHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String secondColor = secondHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( firstScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( secondScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , firstCategory . equals ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , true , secondCategory . equals ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , true , firstColor . equals ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , true , secondColor . equals ( "<STR_LIT>" ) ) ; } public void testRelevanceHashMapInt2FloatArrayWay ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; double secondScore = secondHit . getDouble ( "<STR_LIT>" ) ; String firstMileage = firstHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String secondMileage = secondHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( firstScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( secondScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , Integer . parseInt ( firstMileage ) == <NUM_LIT> ) ; assertEquals ( "<STR_LIT>" , true , Integer . parseInt ( secondMileage ) == <NUM_LIT> ) ; } public void testRelevanceHashMapInt2StringArrayWay ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; double secondScore = secondHit . getDouble ( "<STR_LIT>" ) ; String firstYear = firstHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String secondYear = secondHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String firstColor = firstHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String secondColor = secondHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( firstScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( secondScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , Integer . parseInt ( firstYear ) == <NUM_LIT> ) ; assertEquals ( "<STR_LIT>" , true , Integer . parseInt ( secondYear ) == <NUM_LIT> ) ; assertEquals ( "<STR_LIT>" , true , firstColor . equals ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , true , secondColor . equals ( "<STR_LIT>" ) ) ; } public void testRelevanceHashMapString2FloatArrayWay ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; double secondScore = secondHit . getDouble ( "<STR_LIT>" ) ; String firstColor = firstHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String secondColor = secondHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( firstScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( secondScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , firstColor . equals ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , true , secondColor . equals ( "<STR_LIT>" ) ) ; } public void testRelevanceHashMapString2StringArrayWay ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; double secondScore = secondHit . getDouble ( "<STR_LIT>" ) ; String firstCategory = firstHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String secondCategory = secondHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String firstColor = firstHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; String secondColor = secondHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( firstScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( secondScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , firstCategory . equals ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , true , secondCategory . equals ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , true , firstColor . equals ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , true , secondColor . equals ( "<STR_LIT>" ) ) ; } public void testRelevanceMultiContains ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testRelevanceMultiContainsAny ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; double secondScore = secondHit . getDouble ( "<STR_LIT>" ) ; JSONArray firstTags = firstHit . getJSONArray ( "<STR_LIT>" ) ; JSONArray secondTags = secondHit . getJSONArray ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( firstScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( secondScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , containsString ( firstTags , "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , true , containsString ( secondTags , "<STR_LIT>" ) ) ; } public void testRelevanceModelStorageInMemory ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; { String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; double secondScore = secondHit . getDouble ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( firstScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( secondScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; } { String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; JSONObject secondHit = hits . getJSONObject ( <NUM_LIT:1> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; double secondScore = secondHit . getDouble ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( firstScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( secondScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; } } public void testRelevanceExternalObject ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; String color = firstHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , true , color . equals ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( firstScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; } public void testRelevanceExternalObjectSenseiPlugin ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; JSONArray hits = res . getJSONArray ( "<STR_LIT>" ) ; JSONObject firstHit = hits . getJSONObject ( <NUM_LIT:0> ) ; double firstScore = firstHit . getDouble ( "<STR_LIT>" ) ; String color = firstHit . getJSONArray ( "<STR_LIT>" ) . getString ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , true , color . equals ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , true , Math . abs ( firstScore - <NUM_LIT> ) < <NUM_LIT:1> ) ; } private boolean containsString ( JSONArray array , String target ) throws JSONException { for ( int i = <NUM_LIT:0> ; i < array . length ( ) ; i ++ ) { String item = array . getString ( i ) ; if ( item . equals ( target ) ) return true ; } return false ; } public static JSONObject search ( JSONObject req ) throws Exception { return search ( SenseiStarter . SenseiUrl , req . toString ( ) ) ; } public static JSONObject searchGet ( JSONArray req ) throws Exception { return search ( new URL ( SenseiStarter . SenseiUrl . toString ( ) + "<STR_LIT>" ) , req . toString ( ) ) ; } public static JSONObject search ( URL url , String req ) throws Exception { URLConnection conn = url . openConnection ( ) ; conn . setDoOutput ( true ) ; BufferedWriter writer = new BufferedWriter ( new OutputStreamWriter ( conn . getOutputStream ( ) , "<STR_LIT:UTF-8>" ) ) ; String reqStr = req ; System . out . println ( "<STR_LIT>" + reqStr ) ; writer . write ( reqStr , <NUM_LIT:0> , reqStr . length ( ) ) ; writer . flush ( ) ; BufferedReader reader = new BufferedReader ( new InputStreamReader ( conn . getInputStream ( ) , "<STR_LIT:UTF-8>" ) ) ; StringBuilder sb = new StringBuilder ( ) ; String line = null ; while ( ( line = reader . readLine ( ) ) != null ) sb . append ( line ) ; String res = sb . toString ( ) ; JSONObject ret = new JSONObject ( res ) ; if ( ret . opt ( "<STR_LIT>" ) != null ) { } return ret ; } private void setspec ( SenseiRequest req , FacetSpec spec ) { req . setFacetSpec ( "<STR_LIT>" , spec ) ; req . setFacetSpec ( "<STR_LIT>" , spec ) ; req . setFacetSpec ( "<STR_LIT>" , spec ) ; req . setFacetSpec ( "<STR_LIT>" , spec ) ; req . setFacetSpec ( "<STR_LIT>" , spec ) ; req . setFacetSpec ( "<STR_LIT>" , spec ) ; req . setFacetSpec ( "<STR_LIT>" , spec ) ; req . setFacetSpec ( "<STR_LIT>" , spec ) ; } private void checkColorOrder ( ArrayList < String > arColors ) { assertTrue ( "<STR_LIT>" + arColors . size ( ) , arColors . size ( ) == <NUM_LIT> ) ; for ( int i = <NUM_LIT:0> ; i < arColors . size ( ) - <NUM_LIT:1> ; i ++ ) { String first = arColors . get ( i ) ; String next = arColors . get ( i + <NUM_LIT:1> ) ; int comp = first . compareTo ( next ) ; assertTrue ( "<STR_LIT>" + first + "<STR_LIT>" + next + "<STR_LIT:)>" , comp >= <NUM_LIT:0> ) ; } } public void testSortByDesc ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; JSONArray jhits = res . optJSONArray ( "<STR_LIT>" ) ; ArrayList < String > arColors = new ArrayList < String > ( ) ; ArrayList < String > arCategories = new ArrayList < String > ( ) ; for ( int i = <NUM_LIT:0> ; i < jhits . length ( ) ; i ++ ) { JSONObject jhit = jhits . getJSONObject ( i ) ; JSONArray jcolor = jhit . optJSONArray ( "<STR_LIT>" ) ; if ( jcolor != null ) { String color = jcolor . optString ( <NUM_LIT:0> ) ; if ( color != null ) arColors . add ( color ) ; } JSONArray jcategory = jhit . optJSONArray ( "<STR_LIT>" ) ; if ( jcategory != null ) { String category = jcategory . optString ( <NUM_LIT:0> ) ; if ( category != null ) { arCategories . add ( category ) ; } } } checkOrder ( arColors , arCategories , true , false ) ; } public void testSortByAsc ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = search ( new JSONObject ( req ) ) ; JSONArray jhits = res . optJSONArray ( "<STR_LIT>" ) ; ArrayList < String > arColors = new ArrayList < String > ( ) ; ArrayList < String > arCategories = new ArrayList < String > ( ) ; for ( int i = <NUM_LIT:0> ; i < jhits . length ( ) ; i ++ ) { JSONObject jhit = jhits . getJSONObject ( i ) ; JSONArray jcolor = jhit . optJSONArray ( "<STR_LIT>" ) ; if ( jcolor != null ) { String color = jcolor . optString ( <NUM_LIT:0> ) ; if ( color != null ) arColors . add ( color ) ; } JSONArray jcategory = jhit . optJSONArray ( "<STR_LIT>" ) ; if ( jcategory != null ) { String category = jcategory . optString ( <NUM_LIT:0> ) ; if ( category != null ) { arCategories . add ( category ) ; } } } checkOrder ( arColors , arCategories , false , true ) ; } private void checkOrder ( ArrayList < String > arColors , ArrayList < String > arCategories , boolean colorDesc , boolean categoryDesc ) { assertEquals ( "<STR_LIT>" , arColors . size ( ) , arCategories . size ( ) ) ; assertTrue ( "<STR_LIT>" + arColors . size ( ) , arColors . size ( ) == <NUM_LIT> ) ; for ( int i = <NUM_LIT:0> ; i < arColors . size ( ) - <NUM_LIT:1> ; i ++ ) { String first = arColors . get ( i ) ; String next = arColors . get ( i + <NUM_LIT:1> ) ; String firstCategory = arCategories . get ( i ) ; String nextCategory = arCategories . get ( i + <NUM_LIT:1> ) ; int comp = first . compareTo ( next ) ; if ( colorDesc ) { assertTrue ( "<STR_LIT>" + first + "<STR_LIT>" + next + "<STR_LIT:)>" , comp >= <NUM_LIT:0> ) ; } else { assertTrue ( "<STR_LIT>" + first + "<STR_LIT>" + next + "<STR_LIT:)>" , comp <= <NUM_LIT:0> ) ; } if ( comp == <NUM_LIT:0> ) { int compCategory = firstCategory . compareTo ( nextCategory ) ; if ( categoryDesc ) { assertTrue ( "<STR_LIT>" + firstCategory + "<STR_LIT>" + nextCategory + "<STR_LIT:)>" , compCategory >= <NUM_LIT:0> ) ; } else { assertTrue ( "<STR_LIT>" + firstCategory + "<STR_LIT>" + nextCategory + "<STR_LIT:)>" , compCategory <= <NUM_LIT:0> ) ; } } } } private void verifyFacetCount ( SenseiResult res , String selName , String selVal , int count ) { FacetAccessible year = res . getFacetAccessor ( selName ) ; List < BrowseFacet > browsefacets = year . getFacets ( ) ; int index = indexOfFacet ( selVal , browsefacets ) ; if ( count > <NUM_LIT:0> ) { assertTrue ( "<STR_LIT>" + selVal , index >= <NUM_LIT:0> ) ; BrowseFacet bf = browsefacets . get ( index ) ; assertEquals ( selVal + "<STR_LIT>" , count , bf . getFacetValueHitCount ( ) ) ; } else if ( count == <NUM_LIT:0> ) { if ( index >= <NUM_LIT:0> ) { BrowseFacet bf = browsefacets . get ( index ) ; assertEquals ( selVal + "<STR_LIT>" , count , bf . getFacetValueHitCount ( ) ) ; } } else { assertTrue ( "<STR_LIT>" + selVal , index < <NUM_LIT:0> ) ; } } private int indexOfFacet ( String selVal , List < BrowseFacet > browsefacets ) { for ( int i = <NUM_LIT:0> ; i < browsefacets . size ( ) ; i ++ ) { if ( browsefacets . get ( i ) . getValue ( ) . equals ( selVal ) ) return i ; } return - <NUM_LIT:1> ; } } </s>
<s> package com . senseidb . test ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . UnsupportedEncodingException ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Enumeration ; import java . util . HashMap ; import java . util . Iterator ; import java . util . List ; import java . util . Locale ; import java . util . Map ; import javax . servlet . RequestDispatcher ; import javax . servlet . ServletInputStream ; import javax . servlet . ServletRequest ; import org . apache . http . NameValuePair ; public class MockServletRequest implements ServletRequest { Map < String , List < String > > _map ; public MockServletRequest ( Map < String , List < String > > map ) { _map = map ; } public static MockServletRequest create ( List < NameValuePair > list ) { Map < String , List < String > > map = new HashMap < String , List < String > > ( ) ; for ( NameValuePair pair : list ) { String name = pair . getName ( ) ; if ( ! map . containsKey ( name ) ) { map . put ( name , new ArrayList < String > ( ) ) ; } for ( String value : pair . getValue ( ) . split ( "<STR_LIT:U+002C>" ) ) { map . get ( name ) . add ( value ) ; } } return new MockServletRequest ( map ) ; } @ Override public Object getAttribute ( String s ) { throw new UnsupportedOperationException ( ) ; } @ Override public Enumeration getAttributeNames ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public String getCharacterEncoding ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public void setCharacterEncoding ( String s ) throws UnsupportedEncodingException { throw new UnsupportedOperationException ( ) ; } @ Override public int getContentLength ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public String getContentType ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public ServletInputStream getInputStream ( ) throws IOException { throw new UnsupportedOperationException ( ) ; } @ Override public String getParameter ( String s ) { throw new UnsupportedOperationException ( ) ; } @ Override public Enumeration getParameterNames ( ) { return new EnumerationWrapper ( _map . keySet ( ) . iterator ( ) ) ; } public class EnumerationWrapper implements Enumeration { Iterator _iterator ; public EnumerationWrapper ( Iterator iter ) { _iterator = iter ; } @ Override public boolean hasMoreElements ( ) { return _iterator . hasNext ( ) ; } @ Override public Object nextElement ( ) { return _iterator . next ( ) ; } } ; @ Override public String [ ] getParameterValues ( String s ) { List < String > value = _map . get ( s ) ; if ( value == null ) return new String [ <NUM_LIT:0> ] ; return value . toArray ( new String [ value . size ( ) ] ) ; } @ Override public Map getParameterMap ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public String getProtocol ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public String getScheme ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public String getServerName ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public int getServerPort ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public BufferedReader getReader ( ) throws IOException { throw new UnsupportedOperationException ( ) ; } @ Override public String getRemoteAddr ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public String getRemoteHost ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public void setAttribute ( String s , Object o ) { throw new UnsupportedOperationException ( ) ; } @ Override public void removeAttribute ( String s ) { throw new UnsupportedOperationException ( ) ; } @ Override public Locale getLocale ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public Enumeration getLocales ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public boolean isSecure ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public RequestDispatcher getRequestDispatcher ( String s ) { throw new UnsupportedOperationException ( ) ; } @ Override public String getRealPath ( String s ) { throw new UnsupportedOperationException ( ) ; } @ Override public int getRemotePort ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public String getLocalName ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public String getLocalAddr ( ) { throw new UnsupportedOperationException ( ) ; } @ Override public int getLocalPort ( ) { throw new UnsupportedOperationException ( ) ; } } </s>
<s> package com . senseidb . test ; import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . InputStreamReader ; import java . io . OutputStreamWriter ; import java . net . URL ; import java . net . URLConnection ; import java . util . ArrayList ; import java . util . List ; import junit . framework . TestCase ; import org . apache . log4j . Logger ; import org . json . JSONObject ; import com . browseengine . bobo . api . BrowseFacet ; import com . browseengine . bobo . api . FacetSpec ; import com . browseengine . bobo . api . FacetSpec . FacetSortSpec ; import com . browseengine . bobo . facets . attribute . AttributesFacetHandler ; import com . senseidb . search . node . SenseiBroker ; import com . senseidb . search . req . SenseiRequest ; import com . senseidb . search . req . SenseiResult ; import com . senseidb . svc . api . SenseiService ; public class TestSenseiAttributesHandler extends TestCase { private static final Logger logger = Logger . getLogger ( TestSenseiAttributesHandler . class ) ; private static SenseiBroker broker ; private static SenseiService httpRestSenseiService ; static { SenseiStarter . start ( "<STR_LIT>" , "<STR_LIT>" ) ; broker = SenseiStarter . broker ; httpRestSenseiService = SenseiStarter . httpRestSenseiService ; } public void test1aMultiRangeHandler ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" + "<STR_LIT:}>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:3> , res . getInt ( "<STR_LIT>" ) ) ; } public void test1bMultiRangeHandler ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:1> , res . getInt ( "<STR_LIT>" ) ) ; } public void test1AttributesFacetHandlerTwoOrTerms ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" + "<STR_LIT:}>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void test2AttributesFacetHandlerTwoAndTerms ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" + "<STR_LIT:}>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void test3AttributesFacetHandlerTwoAndTermsAndFacets ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; JSONObject res = search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; assertTrue ( res . optJSONObject ( "<STR_LIT>" ) . optJSONArray ( "<STR_LIT>" ) . length ( ) < <NUM_LIT:10> ) ; req = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:}>" ; res = search ( new JSONObject ( req ) ) ; System . out . println ( res . toString ( <NUM_LIT:1> ) ) ; assertTrue ( res . optJSONObject ( "<STR_LIT>" ) . optJSONArray ( "<STR_LIT>" ) . length ( ) > <NUM_LIT:10> ) ; } public void test4TotalCountWithFacetSpecLimitMaxFacetsPerKey ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; SenseiRequest req = new SenseiRequest ( ) ; FacetSpec facetSpec = new FacetSpec ( ) ; facetSpec . setMaxCount ( <NUM_LIT:20> ) ; facetSpec . setOrderBy ( FacetSortSpec . OrderHitsDesc ) ; facetSpec . getProperties ( ) . put ( AttributesFacetHandler . MAX_FACETS_PER_KEY_PROP_NAME , "<STR_LIT:1>" ) ; setspec ( req , facetSpec ) ; req . setCount ( <NUM_LIT:5> ) ; req . setFacetSpec ( "<STR_LIT>" , facetSpec ) ; SenseiResult res = broker . browse ( req ) ; List < BrowseFacet > facets = res . getFacetAccessor ( "<STR_LIT>" ) . getFacets ( ) ; assertTrue ( facets . toString ( ) , facets . size ( ) > <NUM_LIT:8> ) ; assertTrue ( facets . toString ( ) , facets . size ( ) <= <NUM_LIT:20> ) ; } public void test5FacetsAll ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; SenseiRequest req = new SenseiRequest ( ) ; FacetSpec facetSpec = new FacetSpec ( ) ; facetSpec . setMaxCount ( <NUM_LIT> ) ; facetSpec . setOrderBy ( FacetSortSpec . OrderHitsDesc ) ; facetSpec . getProperties ( ) . put ( AttributesFacetHandler . MAX_FACETS_PER_KEY_PROP_NAME , "<STR_LIT>" ) ; setspec ( req , facetSpec ) ; req . setCount ( <NUM_LIT> ) ; req . setFacetSpec ( "<STR_LIT>" , facetSpec ) ; SenseiResult res = broker . browse ( req ) ; List < BrowseFacet > facets = res . getFacetMap ( ) . get ( "<STR_LIT>" ) . getFacets ( ) ; assertEquals ( "<STR_LIT>" + facets . size ( ) , <NUM_LIT:100> , facets . size ( ) ) ; } private JSONObject search ( JSONObject req ) throws Exception { return search ( SenseiStarter . SenseiUrl , req . toString ( ) ) ; } private JSONObject search ( URL url , String req ) throws Exception { URLConnection conn = url . openConnection ( ) ; conn . setDoOutput ( true ) ; BufferedWriter writer = new BufferedWriter ( new OutputStreamWriter ( conn . getOutputStream ( ) , "<STR_LIT:UTF-8>" ) ) ; String reqStr = req ; System . out . println ( "<STR_LIT>" + reqStr ) ; writer . write ( reqStr , <NUM_LIT:0> , reqStr . length ( ) ) ; writer . flush ( ) ; BufferedReader reader = new BufferedReader ( new InputStreamReader ( conn . getInputStream ( ) , "<STR_LIT:UTF-8>" ) ) ; StringBuilder sb = new StringBuilder ( ) ; String line = null ; while ( ( line = reader . readLine ( ) ) != null ) sb . append ( line ) ; String res = sb . toString ( ) ; System . out . println ( "<STR_LIT>" + res ) ; return new JSONObject ( res ) ; } private void setspec ( SenseiRequest req , FacetSpec spec ) { req . setFacetSpec ( "<STR_LIT>" , spec ) ; } private void checkColorOrder ( ArrayList < String > arColors ) { assertTrue ( "<STR_LIT>" + arColors . size ( ) , arColors . size ( ) == <NUM_LIT> ) ; for ( int i = <NUM_LIT:0> ; i < arColors . size ( ) - <NUM_LIT:1> ; i ++ ) { String first = arColors . get ( i ) ; String next = arColors . get ( i + <NUM_LIT:1> ) ; int comp = first . compareTo ( next ) ; assertTrue ( "<STR_LIT>" + first + "<STR_LIT>" + next + "<STR_LIT:)>" , comp >= <NUM_LIT:0> ) ; } } } </s>
<s> package com . senseidb . test ; import java . io . Serializable ; import java . util . ArrayList ; import java . util . List ; import junit . framework . TestCase ; import org . apache . log4j . Logger ; import org . json . JSONException ; import org . json . JSONObject ; import org . junit . Ignore ; import com . senseidb . search . req . ErrorType ; import com . senseidb . search . req . mapred . CombinerStage ; import com . senseidb . search . req . mapred . FacetCountAccessor ; import com . senseidb . search . req . mapred . FieldAccessor ; import com . senseidb . search . req . mapred . SenseiMapReduce ; import com . senseidb . search . req . mapred . TestMapReduce ; import com . senseidb . svc . api . SenseiService ; public class ErrorHandlingTest extends TestCase { private static final Logger logger = Logger . getLogger ( TestMapReduce . class ) ; public static class MapReduceAdapter implements SenseiMapReduce < Serializable , Serializable > { public void init ( JSONObject params ) { } public Serializable map ( int [ ] docIds , int docIdCount , long [ ] uids , FieldAccessor accessor , FacetCountAccessor facetCountAccessor ) { return new ArrayList ( ) ; } public List < Serializable > combine ( List < Serializable > mapResults , CombinerStage combinerStage ) { return new ArrayList ( ) ; } public Serializable reduce ( List < Serializable > combineResults ) { return new ArrayList ( ) ; } public JSONObject render ( Serializable reduceResult ) { return new JSONObject ( ) ; } } public static class test1JsonError extends MapReduceAdapter { @ Override public void init ( JSONObject params ) { throw new RuntimeException ( "<STR_LIT>" , new JSONException ( "<STR_LIT>" ) ) ; } } public static class test2BoboError extends MapReduceAdapter { @ Override public Serializable map ( int [ ] docIds , int docIdCount , long [ ] uids , FieldAccessor accessor , FacetCountAccessor facetCountAccessor ) { throw new RuntimeException ( "<STR_LIT>" ) ; } } public static class test3PartitionLevelError extends MapReduceAdapter { @ Override public List < Serializable > combine ( List < Serializable > mapResults , CombinerStage combinerStage ) { if ( combinerStage == CombinerStage . partitionLevel ) { throw new RuntimeException ( "<STR_LIT>" ) ; } return super . combine ( mapResults , combinerStage ) ; } } public static class test4NodeLevelError extends MapReduceAdapter { @ Override public List < Serializable > combine ( List < Serializable > mapResults , CombinerStage combinerStage ) { if ( combinerStage == CombinerStage . nodeLevel ) { throw new RuntimeException ( "<STR_LIT>" ) ; } return super . combine ( mapResults , combinerStage ) ; } } public static class test5BrokerLevelError extends MapReduceAdapter { @ Override public Serializable reduce ( List < Serializable > combineResults ) { throw new RuntimeException ( "<STR_LIT>" ) ; } } public static class test6NonSerializableError extends MapReduceAdapter { public static class NonSerializable implements Serializable { private Object obj = new Object ( ) ; } @ Override public List < Serializable > combine ( List < Serializable > mapResults , CombinerStage combinerStage ) { return new ArrayList ( java . util . Arrays . asList ( new NonSerializable ( ) ) ) ; } } public static class test7ResponseJsonError extends MapReduceAdapter { @ Override public JSONObject render ( Serializable reduceResult ) { throw new RuntimeException ( new JSONException ( "<STR_LIT>" ) ) ; } } private static SenseiService httpRestSenseiService ; static { SenseiStarter . start ( "<STR_LIT>" , "<STR_LIT>" ) ; httpRestSenseiService = SenseiStarter . httpRestSenseiService ; } public void test1ExceptionOInitLevel ( ) throws Exception { String req = "<STR_LIT>" + test1JsonError . class . getName ( ) + "<STR_LIT>" ; JSONObject reqJson = new JSONObject ( req ) ; System . out . println ( reqJson . toString ( <NUM_LIT:1> ) ) ; JSONObject res = TestSensei . search ( reqJson ) ; assertEquals ( ErrorType . JsonParsingError . getDefaultErrorCode ( ) , res . getInt ( "<STR_LIT>" ) ) ; assertResponseContainsErrors ( res , ErrorType . JsonParsingError ) ; } public void test2BoboError ( ) throws Exception { String req = "<STR_LIT>" + test2BoboError . class . getName ( ) + "<STR_LIT>" ; JSONObject reqJson = new JSONObject ( req ) ; System . out . println ( reqJson . toString ( <NUM_LIT:1> ) ) ; JSONObject res = TestSensei . search ( reqJson ) ; assertEquals ( ErrorType . BoboExecutionError . getDefaultErrorCode ( ) , res . getInt ( "<STR_LIT>" ) ) ; assertResponseContainsErrors ( res , ErrorType . BoboExecutionError , ErrorType . BoboExecutionError , ErrorType . BoboExecutionError ) ; } public void test3PartitionLevelError ( ) throws Exception { String req = "<STR_LIT>" + test3PartitionLevelError . class . getName ( ) + "<STR_LIT>" ; JSONObject reqJson = new JSONObject ( req ) ; System . out . println ( reqJson . toString ( <NUM_LIT:1> ) ) ; JSONObject res = TestSensei . search ( reqJson ) ; assertEquals ( ErrorType . BoboExecutionError . getDefaultErrorCode ( ) , res . getInt ( "<STR_LIT>" ) ) ; assertResponseContainsErrors ( res , ErrorType . BoboExecutionError , ErrorType . BoboExecutionError , ErrorType . BoboExecutionError ) ; } public void test4NodeLevelError ( ) throws Exception { String req = "<STR_LIT>" + test4NodeLevelError . class . getName ( ) + "<STR_LIT>" ; JSONObject reqJson = new JSONObject ( req ) ; System . out . println ( reqJson . toString ( <NUM_LIT:1> ) ) ; JSONObject res = TestSensei . search ( reqJson ) ; assertEquals ( ErrorType . MergePartitionError . getDefaultErrorCode ( ) , res . getInt ( "<STR_LIT>" ) ) ; assertResponseContainsErrors ( res , ErrorType . MergePartitionError , ErrorType . MergePartitionError ) ; } public void test5BrokerLevelError ( ) throws Exception { String req = "<STR_LIT>" + test5BrokerLevelError . class . getName ( ) + "<STR_LIT>" ; JSONObject reqJson = new JSONObject ( req ) ; System . out . println ( reqJson . toString ( <NUM_LIT:1> ) ) ; JSONObject res = TestSensei . search ( reqJson ) ; assertEquals ( ErrorType . BrokerGatherError . getDefaultErrorCode ( ) , res . getInt ( "<STR_LIT>" ) ) ; assertResponseContainsErrors ( res , ErrorType . BrokerGatherError ) ; } @ Ignore public void ntest6NonSerializableError ( ) throws Exception { String req = "<STR_LIT>" + test6NonSerializableError . class . getName ( ) + "<STR_LIT>" ; JSONObject reqJson = new JSONObject ( req ) ; System . out . println ( reqJson . toString ( <NUM_LIT:1> ) ) ; JSONObject res = TestSensei . search ( reqJson ) ; assertEquals ( ErrorType . BrokerGatherError . getDefaultErrorCode ( ) , res . getInt ( "<STR_LIT>" ) ) ; assertResponseContainsErrors ( res , ErrorType . BrokerGatherError ) ; } public void test7ResponseJsonError ( ) throws Exception { String req = "<STR_LIT>" + test7ResponseJsonError . class . getName ( ) + "<STR_LIT>" ; JSONObject reqJson = new JSONObject ( req ) ; System . out . println ( reqJson . toString ( <NUM_LIT:1> ) ) ; JSONObject res = TestSensei . search ( reqJson ) ; assertEquals ( ErrorType . JsonParsingError . getDefaultErrorCode ( ) , res . getInt ( "<STR_LIT>" ) ) ; assertResponseContainsErrors ( res , ErrorType . JsonParsingError ) ; } public void test8BQLError ( ) throws Exception { String req = "<STR_LIT>" ; JSONObject reqJson = new JSONObject ( req ) ; System . out . println ( reqJson . toString ( <NUM_LIT:1> ) ) ; JSONObject res = TestSensei . search ( reqJson ) ; assertEquals ( ErrorType . BQLParsingError . getDefaultErrorCode ( ) , res . getInt ( "<STR_LIT>" ) ) ; assertResponseContainsErrors ( res , ErrorType . BQLParsingError ) ; } private void assertResponseContainsErrors ( JSONObject res , ErrorType ... jsonParsingErrors ) throws JSONException { for ( int i = <NUM_LIT:0> ; i < jsonParsingErrors . length ; i ++ ) { assertEquals ( jsonParsingErrors [ i ] . name ( ) , res . getJSONArray ( "<STR_LIT>" ) . getJSONObject ( i ) . get ( "<STR_LIT>" ) ) ; } assertEquals ( jsonParsingErrors . length , res . getJSONArray ( "<STR_LIT>" ) . length ( ) ) ; } } </s>
<s> package com . senseidb . test . bql . parsers ; import java . util . Map ; import java . util . HashMap ; import junit . framework . TestCase ; import org . antlr . runtime . * ; import org . junit . Test ; import org . json . JSONArray ; import org . json . JSONObject ; import org . json . JSONException ; import com . senseidb . bql . parsers . BQLCompiler ; import com . senseidb . util . JsonTemplateProcessor ; import java . text . ParseException ; import java . text . SimpleDateFormat ; public class TestBQL extends TestCase { private BQLCompiler _compiler ; private JsonComparator _comp = new JsonComparator ( <NUM_LIT:1> ) ; public TestBQL ( ) { super ( ) ; Map < String , String [ ] > facetInfoMap = new HashMap < String , String [ ] > ( ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT:string>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT:string>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT:float>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT:int>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT:string>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT:int>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT:path>" , "<STR_LIT:string>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT:path>" , "<STR_LIT:string>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT:long>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT>" } ) ; _compiler = new BQLCompiler ( facetInfoMap ) ; } @ Test public void testBasic1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testBasic2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testOrderBy ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testOrderBy2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testOrderByRelevance ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testLimit1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testLimit2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testGroupBy1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testGroupBy2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testGroupByOrColumns ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testEqualPredInteger ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testEqualPredFloat ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testEqualPredString ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testInPred1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testInPred2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testInPred3 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; int result = <NUM_LIT:0> ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { result = <NUM_LIT:1> ; } assertEquals ( result , <NUM_LIT:1> ) ; } @ Test public void testNotInPred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testContainsAll ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testPathPred1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testPathPred2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; int result = <NUM_LIT:0> ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { result = <NUM_LIT:1> ; } assertEquals ( result , <NUM_LIT:1> ) ; } @ Test public void testNotEqualPred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testNotEqualForRange ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; long now = System . currentTimeMillis ( ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testQueryIs ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testQueryAndSelection1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testQueryAndSelection2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testBrowseBy1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testBrowseBy2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testBetweenPred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testFetchingStored1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testFetchingStored2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testNotBetweenPred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRangePred1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRangePred2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRangePred3 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRangePred4 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRangePred5 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; int result = <NUM_LIT:0> ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { result = <NUM_LIT:1> ; } assertEquals ( result , <NUM_LIT:1> ) ; } @ Test public void testOrPred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testAndPred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testAndOrPred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testSelectionAndFilter ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testMultipleQueries ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testMatchPred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testNotMatchPred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testLikePredicate1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testLikePredicate2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testLikePredicate3 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; int result = <NUM_LIT:0> ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { result = <NUM_LIT:1> ; } assertEquals ( result , <NUM_LIT:1> ) ; } @ Test public void testNotLikePredicate ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testQueryAndLike ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testColumnType1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; int result = <NUM_LIT:0> ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { result = <NUM_LIT:1> ; } assertEquals ( result , <NUM_LIT:1> ) ; } @ Test public void testColumnType2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; int result = <NUM_LIT:0> ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { result = <NUM_LIT:1> ; } assertEquals ( result , <NUM_LIT:1> ) ; } @ Test public void testColumnType3 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; int result = <NUM_LIT:0> ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { result = <NUM_LIT:1> ; } assertEquals ( result , <NUM_LIT:1> ) ; } @ Test public void testColumnType4 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; int result = <NUM_LIT:0> ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { result = <NUM_LIT:1> ; } assertEquals ( result , <NUM_LIT:1> ) ; } @ Test public void testGivenClause1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testGivenClause2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testGivenClause3 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testGivenClauseVariable ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; JsonTemplateProcessor jsonProc = new JsonTemplateProcessor ( ) ; json . put ( JsonTemplateProcessor . TEMPLATE_MAPPING_PARAM , new JSONObject ( ) . put ( "<STR_LIT>" , new JSONArray ( ) . put ( <NUM_LIT> ) ) ) ; JSONObject newJson = jsonProc . substituteTemplates ( json ) ; JSONObject expected2 = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( newJson , expected2 ) ) ; } @ Test public void testTimePred1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; long now = System . currentTimeMillis ( ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; long timeStamp = Long . parseLong ( json . getJSONObject ( "<STR_LIT>" ) . getJSONObject ( "<STR_LIT>" ) . getJSONObject ( "<STR_LIT>" ) . getString ( "<STR_LIT>" ) ) ; long timeSpan = <NUM_LIT:1> * ( <NUM_LIT:7> * <NUM_LIT:24> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) + <NUM_LIT:2> * ( <NUM_LIT:24> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) + <NUM_LIT:3> * ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) + <NUM_LIT:4> * ( <NUM_LIT> * <NUM_LIT> ) + <NUM_LIT:5> * <NUM_LIT> + <NUM_LIT:6> ; assertTrue ( now - timeStamp - timeSpan < <NUM_LIT:2> ) ; } @ Test public void testTimePred2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; long now = System . currentTimeMillis ( ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; long timeStamp = Long . parseLong ( json . getJSONObject ( "<STR_LIT>" ) . getJSONObject ( "<STR_LIT>" ) . getJSONObject ( "<STR_LIT>" ) . getString ( "<STR_LIT>" ) ) ; long timeSpan = <NUM_LIT:2> * ( <NUM_LIT:24> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) + <NUM_LIT:3> * ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) + <NUM_LIT:4> * ( <NUM_LIT> * <NUM_LIT> ) + <NUM_LIT:6> ; assertTrue ( now - timeStamp - timeSpan < <NUM_LIT:2> ) ; } @ Test public void testTimePred3 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; long now = System . currentTimeMillis ( ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; long timeStamp = Long . parseLong ( json . getJSONObject ( "<STR_LIT>" ) . getJSONObject ( "<STR_LIT>" ) . getJSONObject ( "<STR_LIT>" ) . getString ( "<STR_LIT>" ) ) ; long timeSpan = <NUM_LIT:3> * ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) + <NUM_LIT:4> * ( <NUM_LIT> * <NUM_LIT> ) ; assertTrue ( now - timeStamp - timeSpan < <NUM_LIT:2> ) ; } @ Test public void testNotTimePred1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; long now = System . currentTimeMillis ( ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; long timeStamp = Long . parseLong ( json . getJSONObject ( "<STR_LIT>" ) . getJSONObject ( "<STR_LIT>" ) . getJSONObject ( "<STR_LIT>" ) . getString ( "<STR_LIT>" ) ) ; long timeSpan = <NUM_LIT:3> * ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) + <NUM_LIT:4> * ( <NUM_LIT> * <NUM_LIT> ) ; assertTrue ( now - timeStamp - timeSpan < <NUM_LIT:2> ) ; } @ Test public void testDateTime1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; long now = System . currentTimeMillis ( ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; long timeStamp = Long . parseLong ( json . getJSONObject ( "<STR_LIT>" ) . getJSONObject ( "<STR_LIT>" ) . getJSONObject ( "<STR_LIT>" ) . getString ( "<STR_LIT>" ) ) ; long expected = new SimpleDateFormat ( "<STR_LIT>" ) . parse ( "<STR_LIT>" ) . getTime ( ) ; assertEquals ( timeStamp , expected ) ; } @ Test public void testDateTime2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; long now = System . currentTimeMillis ( ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; long timeStamp = Long . parseLong ( json . getJSONObject ( "<STR_LIT>" ) . getJSONObject ( "<STR_LIT>" ) . getJSONObject ( "<STR_LIT>" ) . getString ( "<STR_LIT>" ) ) ; long expected = new SimpleDateFormat ( "<STR_LIT>" ) . parse ( "<STR_LIT>" ) . getTime ( ) ; assertEquals ( timeStamp , expected ) ; } @ Test public void testDateTime3 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; long now = System . currentTimeMillis ( ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject timeRange = json . getJSONObject ( "<STR_LIT>" ) . getJSONObject ( "<STR_LIT>" ) ; long fromTime = Long . parseLong ( timeRange . getJSONObject ( "<STR_LIT>" ) . getString ( "<STR_LIT>" ) ) ; long expectedFromTime = new SimpleDateFormat ( "<STR_LIT>" ) . parse ( "<STR_LIT>" ) . getTime ( ) ; assertEquals ( fromTime , expectedFromTime ) ; assertFalse ( timeRange . getJSONObject ( "<STR_LIT>" ) . getBoolean ( "<STR_LIT>" ) ) ; long toTime = Long . parseLong ( timeRange . getJSONObject ( "<STR_LIT>" ) . getString ( "<STR_LIT>" ) ) ; long expectedToTime = new SimpleDateFormat ( "<STR_LIT>" ) . parse ( "<STR_LIT>" ) . getTime ( ) ; assertEquals ( fromTime , expectedFromTime ) ; assertTrue ( timeRange . getJSONObject ( "<STR_LIT>" ) . getBoolean ( "<STR_LIT>" ) ) ; } @ Test public void testUID ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; long now = System . currentTimeMillis ( ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testLongValue ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testCorrectStatement ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } @ Test public void testNullPred1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testNullPred2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRouteBy ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testStringColumnName ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testSubColumnName ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRelevanceModel1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRelevanceModelIfStmt ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRelevanceModelFloatLiteral ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRelevanceModelDataTypes ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRelevanceModelWhileStmt ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRelevanceModelDoWhile ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRelevanceModelForLoop ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRelevanceModelSwitchStmt ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRelevanceModelExpressions ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRelevanceModelParameters ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRelevanceModelExample1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRelevanceModelExample2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRelevanceModelVariableScopes ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } @ Test public void testRelevanceModelMapValue ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; JSONObject expected = new JSONObject ( "<STR_LIT>" ) ; assertTrue ( _comp . isEquals ( json , expected ) ) ; } } </s>
<s> package com . senseidb . test . bql . parsers ; import org . json . JSONArray ; import org . json . JSONException ; import org . json . JSONObject ; import java . lang . Math ; import java . util . Iterator ; public class JsonComparator { public static final int STRICT = <NUM_LIT:1> ; public static final int SIMPLE = <NUM_LIT:2> ; private final int policy ; public JsonComparator ( int policy ) { this . policy = policy ; } public boolean isEquals ( Object a , Object b ) { if ( a instanceof JSONObject ) { if ( b instanceof JSONObject ) { return isEqualsJsonObject ( ( JSONObject ) a , ( JSONObject ) b ) ; } else { return false ; } } if ( a instanceof JSONArray ) { if ( b instanceof JSONArray ) { return isEqualsJsonArray ( ( JSONArray ) a , ( JSONArray ) b ) ; } else { return false ; } } if ( a instanceof Long ) { if ( b instanceof Long ) { return isEqualsLong ( ( Long ) a , ( Long ) b ) ; } else if ( b instanceof Integer ) { return isEqualsLong ( ( Long ) a , new Long ( ( long ) ( ( Integer ) b ) . intValue ( ) ) ) ; } else { return false ; } } if ( a instanceof Integer ) { if ( b instanceof Integer ) { return isEqualsInteger ( ( Integer ) a , ( Integer ) b ) ; } else if ( b instanceof Long ) { return isEqualsInteger ( ( Integer ) a , new Integer ( ( int ) ( ( Long ) b ) . longValue ( ) ) ) ; } else { return false ; } } if ( a instanceof String ) { if ( b instanceof String ) { return isEqualsString ( ( String ) a , ( String ) b ) ; } else { return false ; } } if ( a instanceof Boolean ) { if ( b instanceof Boolean ) { return isEqualsBoolean ( ( Boolean ) a , ( Boolean ) b ) ; } else { return false ; } } if ( a instanceof Float || a instanceof Double ) { double val1 = ( a instanceof Float ) ? ( ( Float ) a ) . doubleValue ( ) : ( ( Double ) a ) . doubleValue ( ) ; if ( b instanceof Float || b instanceof Double ) { double val2 = ( b instanceof Float ) ? ( ( Float ) b ) . doubleValue ( ) : ( ( Double ) b ) . doubleValue ( ) ; return ( Math . abs ( val1 - val2 ) < <NUM_LIT> ) ; } else { return false ; } } if ( a == null && b == null ) { return true ; } if ( a != null && b != null ) { return a . equals ( b ) ; } return false ; } private boolean isEqualsBoolean ( Boolean a , Boolean b ) { if ( a == null ^ b == null ) { return false ; } else if ( a == null && b == null ) { return true ; } return a . equals ( b ) ; } private boolean isEqualsString ( String a , String b ) { if ( a == null ^ b == null ) { return false ; } else if ( a == null && b == null ) { return true ; } return a . equals ( b ) ; } private boolean isEqualsLong ( Long a , Long b ) { if ( a == null ^ b == null ) { return false ; } else if ( a == null && b == null ) { return true ; } return a . equals ( b ) ; } private boolean isEqualsInteger ( Integer a , Integer b ) { if ( a == null ^ b == null ) { return false ; } else if ( a == null && b == null ) { return true ; } return a . equals ( b ) ; } private boolean isEqualsJsonArray ( JSONArray a , JSONArray b ) { if ( policy == STRICT ) { if ( a . length ( ) != b . length ( ) ) { return false ; } } if ( policy == SIMPLE ) { if ( a . length ( ) > b . length ( ) ) { return false ; } } boolean [ ] am = new boolean [ a . length ( ) ] ; boolean [ ] bm = new boolean [ b . length ( ) ] ; for ( int i = <NUM_LIT:0> ; i < a . length ( ) ; ++ i ) if ( am [ i ] == false ) { for ( int j = <NUM_LIT:0> ; j < b . length ( ) ; ++ j ) if ( bm [ j ] == false ) { try { if ( isEquals ( a . get ( i ) , b . get ( j ) ) ) { am [ i ] = true ; bm [ j ] = true ; break ; } } catch ( JSONException e ) { e . printStackTrace ( ) ; } } } for ( int i = <NUM_LIT:0> ; i < am . length ; ++ i ) if ( ! am [ i ] ) { return false ; } if ( policy == STRICT ) { for ( int j = <NUM_LIT:0> ; j < bm . length ; ++ j ) if ( ! bm [ j ] ) { return false ; } } return true ; } private boolean isEqualsJsonObject ( JSONObject a , JSONObject b ) { if ( policy == STRICT ) { if ( a . length ( ) != b . length ( ) ) { return false ; } } if ( policy == SIMPLE ) { if ( a . length ( ) > b . length ( ) ) { return false ; } } Iterator keys = a . keys ( ) ; while ( keys . hasNext ( ) ) { String key = ( String ) keys . next ( ) ; if ( ! b . has ( key ) ) { return false ; } try { if ( ! isEquals ( a . get ( key ) , b . get ( key ) ) ) { return false ; } } catch ( JSONException e ) { return false ; } } return true ; } } </s>
<s> package com . senseidb . test . bql . parsers ; import java . util . Map ; import java . util . HashMap ; import junit . framework . TestCase ; import org . antlr . runtime . * ; import org . junit . Test ; import org . json . JSONArray ; import org . json . JSONObject ; import org . json . JSONException ; import com . senseidb . bql . parsers . BQLCompiler ; import java . text . ParseException ; import java . text . SimpleDateFormat ; public class TestErrorHandling extends TestCase { private BQLCompiler _compiler ; private JsonComparator _comp = new JsonComparator ( <NUM_LIT:1> ) ; public TestErrorHandling ( ) { super ( ) ; Map < String , String [ ] > facetInfoMap = new HashMap < String , String [ ] > ( ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT:string>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT:string>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT:float>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT:int>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT:string>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT:int>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT:path>" , "<STR_LIT:string>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT:path>" , "<STR_LIT:string>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT:long>" } ) ; facetInfoMap . put ( "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT>" } ) ; _compiler = new BQLCompiler ( facetInfoMap ) ; } @ Test public void testBasicError1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testInconsistentRanges ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testInvalidInPred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testInvalidInPredValues ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testInvalidInPredExceptValues ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testInvalidContainsAllPred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testInvalidContainsAllPredValues ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testInvalidContainsAllPredExceptValues ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testBadDataInEqualPred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testExpectingCOLON ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testUnsupportedProp ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testBadDataInNotEqualPred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testNotEqualOnPath ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testBadBetweenPred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testBadDataInBetweenPred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testBadRangePred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testBadDataInRangePred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testBadDatetime1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testBadDatetime2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testBadMatchPred ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testEOF ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testBadSelectList ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testOrderByOnce ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testLimitOnce ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testBadGroupBy ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testBadGroupBy2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testBadTimePredicate ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testOverflowInteger ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testRouteByOnce ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testSrcdataFetchStoredError1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testSrcdataFetchStoredError2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testUsingRelevanceOnce ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testRelevanceVarRedefined ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testRelevanceUndefinedVar1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testRelevanceUndefinedVar2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testRelevanceUndefinedVar3 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testRelevanceVarDeclError1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testRelevanceVarDeclError2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testRelevanceVarDeclError3 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testRelevanceModelParamError1 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testRelevanceModelParamError2 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } @ Test public void testRelevanceModelParamError3 ( ) throws Exception { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; boolean caughtException = false ; try { JSONObject json = _compiler . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; } catch ( RecognitionException err ) { assertEquals ( "<STR_LIT>" , _compiler . getErrorMessage ( err ) ) ; caughtException = true ; } finally { assertTrue ( caughtException ) ; } } } </s>
<s> package com . senseidb . test ; import static org . junit . Assert . assertTrue ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileReader ; import java . util . ArrayList ; import java . util . List ; import java . util . Map ; import org . apache . commons . codec . binary . Base64 ; import org . apache . lucene . search . SortField ; import org . json . JSONArray ; import org . json . JSONObject ; import org . junit . BeforeClass ; import org . junit . Test ; import com . browseengine . bobo . api . FacetSpec . FacetSortSpec ; import com . browseengine . bobo . facets . FacetHandlerInitializerParam ; import com . senseidb . search . req . SenseiRequest ; import com . senseidb . util . RequestConverter2 ; public class TestRequestConverter2 { static JSONObject senseiRequestJson = null ; static JSONObject queryJson = null ; static JSONArray selectionsJson = null ; static JSONObject filtersJson = null ; public static JSONObject readJSONFromFile ( String fileName ) throws Exception { File file = new File ( fileName ) ; BufferedReader br = new BufferedReader ( new FileReader ( file ) ) ; StringBuffer sb = new StringBuffer ( ) ; String line = br . readLine ( ) ; while ( line != null ) { if ( ! line . trim ( ) . startsWith ( "<STR_LIT>" ) ) { if ( line . indexOf ( "<STR_LIT>" ) > <NUM_LIT:0> ) line = line . substring ( <NUM_LIT:0> , line . indexOf ( "<STR_LIT>" ) ) ; sb . append ( line . trim ( ) ) ; } line = br . readLine ( ) ; } return new JSONObject ( sb . toString ( ) ) ; } public static JSONArray readJSONArrayFromFile ( String fileName ) throws Exception { File file = new File ( fileName ) ; BufferedReader br = new BufferedReader ( new FileReader ( file ) ) ; StringBuffer sb = new StringBuffer ( ) ; String line = br . readLine ( ) ; while ( line != null ) { if ( ! line . trim ( ) . startsWith ( "<STR_LIT>" ) ) { if ( line . indexOf ( "<STR_LIT>" ) > <NUM_LIT:0> ) line = line . substring ( <NUM_LIT:0> , line . indexOf ( "<STR_LIT>" ) ) ; sb . append ( line . trim ( ) ) ; } line = br . readLine ( ) ; } return new JSONArray ( sb . toString ( ) ) ; } @ BeforeClass public static void setUpBeforeClass ( ) throws Exception { senseiRequestJson = readJSONFromFile ( "<STR_LIT>" ) ; selectionsJson = readJSONArrayFromFile ( "<STR_LIT>" ) ; queryJson = readJSONFromFile ( "<STR_LIT>" ) ; filtersJson = readJSONFromFile ( "<STR_LIT>" ) ; senseiRequestJson . remove ( "<STR_LIT>" ) ; senseiRequestJson . remove ( "<STR_LIT:query>" ) ; senseiRequestJson . putOpt ( "<STR_LIT>" , selectionsJson ) ; senseiRequestJson . putOpt ( "<STR_LIT:query>" , queryJson ) ; } @ Test public void test ( ) throws Exception { SenseiRequest req = RequestConverter2 . fromJSON ( senseiRequestJson , null ) ; assertTrue ( "<STR_LIT>" , req . getOffset ( ) == <NUM_LIT:0> ) ; assertTrue ( "<STR_LIT>" , req . getCount ( ) == <NUM_LIT:10> ) ; assertTrue ( "<STR_LIT>" , req . getGroupBy ( ) [ <NUM_LIT:0> ] . equals ( "<STR_LIT>" ) ) ; assertTrue ( "<STR_LIT>" , req . getMaxPerGroup ( ) == <NUM_LIT:3> ) ; assertTrue ( "<STR_LIT>" , req . getFacetSpecCount ( ) == <NUM_LIT:1> ) ; assertTrue ( "<STR_LIT>" , req . getFacetSpec ( "<STR_LIT>" ) . getMaxCount ( ) == <NUM_LIT:10> ) ; assertTrue ( "<STR_LIT>" , req . getFacetSpec ( "<STR_LIT>" ) . getMinHitCount ( ) == <NUM_LIT:1> ) ; assertTrue ( "<STR_LIT>" , req . getFacetSpec ( "<STR_LIT>" ) . isExpandSelection ( ) == false ) ; assertTrue ( "<STR_LIT>" , req . getFacetSpec ( "<STR_LIT>" ) . getOrderBy ( ) == FacetSortSpec . OrderHitsDesc ) ; Map < String , FacetHandlerInitializerParam > mapParams = req . getFacetHandlerInitParamMap ( ) ; assertTrue ( "<STR_LIT>" , mapParams . size ( ) == <NUM_LIT:1> ) ; FacetHandlerInitializerParam param = mapParams . get ( "<STR_LIT>" ) ; boolean [ ] coldstart = param . getBooleanParam ( "<STR_LIT>" ) ; evaluateBool ( coldstart , new boolean [ ] { true } ) ; List < String > names = param . getStringParam ( "<STR_LIT>" ) ; ArrayList < String > ar = new ArrayList < String > ( ) ; ar . add ( "<STR_LIT:a>" ) ; ar . add ( "<STR_LIT:b>" ) ; ar . add ( "<STR_LIT:c>" ) ; evaluateListString ( names , ar ) ; double [ ] timeout = param . getDoubleParam ( "<STR_LIT>" ) ; evaluateDouble ( timeout , new double [ ] { <NUM_LIT> } ) ; int [ ] srcId = param . getIntParam ( "<STR_LIT>" ) ; evaluateInt ( srcId , new int [ ] { <NUM_LIT> } ) ; long [ ] longId = param . getLongParam ( "<STR_LIT>" ) ; evaluateLong ( longId , new long [ ] { <NUM_LIT> , <NUM_LIT> } ) ; byte [ ] base64 = param . getByteArrayParam ( "<STR_LIT>" ) ; evaluateBytes ( base64 , ( new String ( "<STR_LIT>" ) ) . getBytes ( ) ) ; assertTrue ( "<STR_LIT>" , req . getSort ( ) [ <NUM_LIT:0> ] . getField ( ) . equals ( "<STR_LIT>" ) ) ; assertTrue ( "<STR_LIT>" , req . getSort ( ) [ <NUM_LIT:0> ] . getReverse ( ) == true ) ; assertTrue ( "<STR_LIT>" , req . getSort ( ) [ <NUM_LIT:1> ] == SortField . FIELD_SCORE ) ; assertTrue ( "<STR_LIT>" , req . isFetchStoredFields ( ) == false ) ; assertTrue ( "<STR_LIT>" , req . isFetchStoredValue ( ) == false ) ; assertTrue ( "<STR_LIT>" , req . getPartitions ( ) . contains ( <NUM_LIT:1> ) ) ; assertTrue ( "<STR_LIT>" , req . getPartitions ( ) . contains ( <NUM_LIT:2> ) ) ; assertTrue ( "<STR_LIT>" , req . getPartitions ( ) . size ( ) == <NUM_LIT:2> ) ; assertTrue ( "<STR_LIT>" , req . isShowExplanation ( ) == false ) ; assertTrue ( "<STR_LIT>" , req . getRouteParam ( ) != null ) ; } private void evaluateBytes ( byte [ ] result , byte [ ] sample ) { assertTrue ( "<STR_LIT>" , result . length == sample . length ) ; for ( int i = <NUM_LIT:0> ; i < result . length ; i ++ ) { assertTrue ( "<STR_LIT>" , result [ i ] == sample [ i ] ) ; } } private void evaluateLong ( long [ ] result , long [ ] sample ) { assertTrue ( "<STR_LIT>" , result . length == sample . length ) ; for ( int i = <NUM_LIT:0> ; i < result . length ; i ++ ) { assertTrue ( "<STR_LIT>" , result [ i ] == sample [ i ] ) ; } } private void evaluateInt ( int [ ] result , int [ ] sample ) { assertTrue ( "<STR_LIT>" , result . length == sample . length ) ; for ( int i = <NUM_LIT:0> ; i < result . length ; i ++ ) { assertTrue ( "<STR_LIT>" , result [ i ] == sample [ i ] ) ; } } private void evaluateDouble ( double [ ] result , double [ ] sample ) { assertTrue ( "<STR_LIT>" , result . length == sample . length ) ; for ( int i = <NUM_LIT:0> ; i < result . length ; i ++ ) { assertTrue ( "<STR_LIT>" , result [ i ] == sample [ i ] ) ; } } private void evaluateListString ( List < String > result , ArrayList < String > sample ) { assertTrue ( "<STR_LIT>" , result . size ( ) == sample . size ( ) ) ; for ( int i = <NUM_LIT:0> ; i < result . size ( ) ; i ++ ) { assertTrue ( "<STR_LIT>" , result . get ( i ) . equals ( sample . get ( i ) ) ) ; } } private void evaluateBool ( boolean [ ] result , boolean [ ] sample ) { assertTrue ( "<STR_LIT>" , result . length == sample . length ) ; for ( int i = <NUM_LIT:0> ; i < result . length ; i ++ ) { assertTrue ( "<STR_LIT>" , result [ i ] == sample [ i ] ) ; } } @ Test public void testBase64 ( ) throws Exception { try { String clearText = "<STR_LIT>" ; String encodedText ; encodedText = new String ( Base64 . encodeBase64 ( clearText . getBytes ( ) ) ) ; byte [ ] encodedbytes = encodedText . getBytes ( ) ; assertTrue ( "<STR_LIT>" . equals ( new String ( Base64 . decodeBase64 ( encodedbytes ) ) ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } } </s>
<s> package com . senseidb . test ; import java . util . List ; import junit . framework . TestCase ; import org . apache . log4j . Logger ; import org . apache . lucene . search . SortField ; import scala . actors . threadpool . Arrays ; import com . browseengine . bobo . api . BrowseFacet ; import com . browseengine . bobo . api . BrowseSelection ; import com . browseengine . bobo . api . BrowseSelection . ValueOperation ; import com . browseengine . bobo . api . FacetSpec ; import com . browseengine . bobo . api . FacetSpec . FacetSortSpec ; import com . senseidb . search . node . SenseiBroker ; import com . senseidb . search . req . SenseiRequest ; import com . senseidb . search . req . SenseiResult ; import com . senseidb . svc . api . SenseiService ; public class TestNegativeNumbers extends TestCase { private static final Logger logger = Logger . getLogger ( TestSensei . class ) ; private static SenseiBroker broker ; private static SenseiService httpRestSenseiService ; static { SenseiStarter . start ( "<STR_LIT>" , "<STR_LIT>" ) ; broker = SenseiStarter . broker ; httpRestSenseiService = SenseiStarter . httpRestSenseiService ; } public void testSortByAsc ( ) throws Exception { SenseiRequest req = new SenseiRequest ( ) ; String field = "<STR_LIT>" ; req . setCount ( <NUM_LIT:11> ) ; req . addSortField ( new SortField ( "<STR_LIT>" , SortField . LONG , false ) ) ; SenseiResult res = broker . browse ( req ) ; long [ ] groupdIDs = extractFieldValues ( field , res ) ; assertTrue ( Arrays . toString ( groupdIDs ) + "<STR_LIT>" , Arrays . equals ( new long [ ] { - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } , groupdIDs ) ) ; } public void test2SortDesc ( ) throws Exception { SenseiRequest req = new SenseiRequest ( ) ; String field = "<STR_LIT>" ; req . setCount ( <NUM_LIT:20> ) ; req . setOffset ( <NUM_LIT> ) ; req . addSortField ( new SortField ( "<STR_LIT>" , SortField . LONG , true ) ) ; SenseiResult res = broker . browse ( req ) ; long [ ] groupdIDs = extractFieldValues ( field , res ) ; assertTrue ( Arrays . toString ( groupdIDs ) + "<STR_LIT>" , Arrays . equals ( new long [ ] { <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> } , groupdIDs ) ) ; } public void test3SortDescWithTerms ( ) throws Exception { SenseiRequest req = new SenseiRequest ( ) ; String field = "<STR_LIT>" ; req . setCount ( <NUM_LIT:4> ) ; req . addSortField ( new SortField ( "<STR_LIT>" , SortField . LONG , false ) ) ; req . addSelection ( new BrowseSelection ( "<STR_LIT>" ) . addValue ( "<STR_LIT:10>" ) . addValue ( "<STR_LIT:0>" ) . addValue ( "<STR_LIT>" ) . addValue ( "<STR_LIT>" ) . setSelectionOperation ( ValueOperation . ValueOperationOr ) ) ; req . setFacetSpec ( "<STR_LIT>" , new FacetSpec ( ) . setMaxCount ( <NUM_LIT> ) . setMinHitCount ( <NUM_LIT:1> ) ) ; SenseiResult res = broker . browse ( req ) ; System . out . println ( res ) ; long [ ] groupdIDs = extractFieldValues ( field , res ) ; assertTrue ( Arrays . toString ( groupdIDs ) + "<STR_LIT>" , Arrays . equals ( new long [ ] { - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } , groupdIDs ) ) ; } public void test4Facets ( ) throws Exception { SenseiRequest req = new SenseiRequest ( ) ; FacetSpec fs = new FacetSpec ( ) ; fs . setMinHitCount ( <NUM_LIT:1> ) ; fs . setOrderBy ( FacetSortSpec . OrderValueAsc ) ; req . setFacetSpec ( "<STR_LIT>" , fs ) ; SenseiResult res = broker . browse ( req ) ; List < BrowseFacet > facets = res . getFacetAccessor ( "<STR_LIT>" ) . getFacets ( ) ; assertEquals ( "<STR_LIT>" , facets . get ( <NUM_LIT:0> ) . getValue ( ) ) ; assertEquals ( <NUM_LIT:1> , facets . get ( <NUM_LIT:0> ) . getFacetValueHitCount ( ) ) ; assertEquals ( "<STR_LIT>" , facets . get ( <NUM_LIT:9> ) . getValue ( ) ) ; assertEquals ( <NUM_LIT:1> , facets . get ( <NUM_LIT:9> ) . getFacetValueHitCount ( ) ) ; assertEquals ( "<STR_LIT>" , facets . get ( <NUM_LIT:10> ) . getValue ( ) ) ; assertEquals ( <NUM_LIT:10> , facets . get ( <NUM_LIT:10> ) . getFacetValueHitCount ( ) ) ; for ( BrowseFacet facet : facets ) { if ( ! facet . getValue ( ) . startsWith ( "<STR_LIT>" ) && ! facet . getValue ( ) . startsWith ( "<STR_LIT>" ) ) { fail ( facet . getValue ( ) + "<STR_LIT>" ) ; } } } public void test5Range ( ) throws Exception { SenseiRequest req = new SenseiRequest ( ) ; BrowseSelection sel = new BrowseSelection ( "<STR_LIT>" ) ; String selVal = "<STR_LIT>" ; sel . addValue ( selVal ) ; req . addSelection ( sel ) ; String field = "<STR_LIT>" ; FacetSpec fs = new FacetSpec ( ) ; fs . setMinHitCount ( <NUM_LIT:1> ) ; fs . setOrderBy ( FacetSortSpec . OrderValueAsc ) ; req . setFacetSpec ( field , fs ) ; req . setCount ( <NUM_LIT:11> ) ; req . setOffset ( <NUM_LIT:0> ) ; req . addSortField ( new SortField ( "<STR_LIT>" , SortField . LONG , false ) ) ; SenseiResult res = broker . browse ( req ) ; System . out . println ( res ) ; long [ ] groupdIDs = extractFieldValues ( field , res ) ; assertTrue ( Arrays . toString ( groupdIDs ) + "<STR_LIT>" , Arrays . equals ( new long [ ] { - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } , groupdIDs ) ) ; } public void test6RangeFacets ( ) throws Exception { SenseiRequest req = new SenseiRequest ( ) ; BrowseSelection sel = new BrowseSelection ( "<STR_LIT>" ) ; String selVal = "<STR_LIT>" ; sel . addValue ( selVal ) ; req . addSelection ( sel ) ; String field = "<STR_LIT>" ; FacetSpec fs = new FacetSpec ( ) ; fs . setMinHitCount ( <NUM_LIT:1> ) ; fs . setOrderBy ( FacetSortSpec . OrderValueAsc ) ; req . setFacetSpec ( field , fs ) ; req . setCount ( <NUM_LIT:11> ) ; req . setOffset ( <NUM_LIT:0> ) ; req . addSortField ( new SortField ( "<STR_LIT>" , SortField . LONG , false ) ) ; SenseiResult res = broker . browse ( req ) ; System . out . println ( res ) ; List < BrowseFacet > facets = res . getFacetAccessor ( field ) . getFacets ( ) ; assertEquals ( "<STR_LIT>" , facets . get ( <NUM_LIT:0> ) . getValue ( ) ) ; assertEquals ( <NUM_LIT:4> , facets . get ( <NUM_LIT:0> ) . getFacetValueHitCount ( ) ) ; assertEquals ( "<STR_LIT>" , facets . get ( <NUM_LIT:1> ) . getValue ( ) ) ; assertEquals ( <NUM_LIT:20> , facets . get ( <NUM_LIT:1> ) . getFacetValueHitCount ( ) ) ; } public void test7MultiFacets ( ) throws Exception { SenseiRequest req = new SenseiRequest ( ) ; FacetSpec fs = new FacetSpec ( ) ; fs . setMinHitCount ( <NUM_LIT:1> ) ; fs . setMaxCount ( <NUM_LIT:20> ) ; fs . setOrderBy ( FacetSortSpec . OrderValueAsc ) ; req . setFacetSpec ( "<STR_LIT>" , fs ) ; SenseiResult res = broker . browse ( req ) ; System . out . println ( res ) ; List < BrowseFacet > facets = res . getFacetAccessor ( "<STR_LIT>" ) . getFacets ( ) ; assertEquals ( "<STR_LIT>" , facets . get ( <NUM_LIT:0> ) . getValue ( ) ) ; assertEquals ( <NUM_LIT:2> , facets . get ( <NUM_LIT:0> ) . getFacetValueHitCount ( ) ) ; assertEquals ( "<STR_LIT>" , facets . get ( <NUM_LIT:1> ) . getValue ( ) ) ; assertEquals ( <NUM_LIT:2> , facets . get ( <NUM_LIT:1> ) . getFacetValueHitCount ( ) ) ; assertEquals ( "<STR_LIT>" , facets . get ( <NUM_LIT:2> ) . getValue ( ) ) ; assertEquals ( <NUM_LIT:3> , facets . get ( <NUM_LIT:2> ) . getFacetValueHitCount ( ) ) ; assertEquals ( "<STR_LIT>" , facets . get ( <NUM_LIT:3> ) . getValue ( ) ) ; assertEquals ( <NUM_LIT:2> , facets . get ( <NUM_LIT:3> ) . getFacetValueHitCount ( ) ) ; assertEquals ( "<STR_LIT>" , facets . get ( <NUM_LIT:4> ) . getValue ( ) ) ; assertEquals ( <NUM_LIT:1> , facets . get ( <NUM_LIT:4> ) . getFacetValueHitCount ( ) ) ; assertEquals ( "<STR_LIT>" , facets . get ( <NUM_LIT:5> ) . getValue ( ) ) ; assertEquals ( <NUM_LIT:1> , facets . get ( <NUM_LIT:5> ) . getFacetValueHitCount ( ) ) ; } public void test8MultiTerm ( ) throws Exception { SenseiRequest req = new SenseiRequest ( ) ; req . setCount ( <NUM_LIT:100> ) ; String fieldName = "<STR_LIT>" ; req . addSelection ( new BrowseSelection ( fieldName ) . addValue ( "<STR_LIT:-1>" ) . addValue ( "<STR_LIT:1>" ) . addNotValue ( "<STR_LIT>" ) . setSelectionOperation ( ValueOperation . ValueOperationOr ) ) ; req . addSortField ( new SortField ( fieldName , SortField . LONG , false ) ) ; req . setFacetSpec ( fieldName , new FacetSpec ( ) . setMaxCount ( <NUM_LIT> ) . setMinHitCount ( <NUM_LIT:1> ) . setOrderBy ( FacetSortSpec . OrderValueAsc ) ) ; SenseiResult res = broker . browse ( req ) ; assertEquals ( <NUM_LIT:1> , res . getNumHits ( ) ) ; } private long [ ] extractFieldValues ( String field , SenseiResult res ) { long [ ] groupdIDs = new long [ res . getSenseiHits ( ) . length ] ; for ( int i = <NUM_LIT:0> ; i < res . getSenseiHits ( ) . length ; i ++ ) { groupdIDs [ i ] = Long . parseLong ( res . getSenseiHits ( ) [ i ] . getFieldValues ( ) . get ( field ) [ <NUM_LIT:0> ] ) ; } return groupdIDs ; } } </s>
<s> package com . senseidb . test ; import java . io . UnsupportedEncodingException ; import java . net . MalformedURLException ; import java . net . URI ; import java . net . URISyntaxException ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . Set ; import junit . framework . TestCase ; import org . apache . commons . configuration . DataConfiguration ; import org . apache . commons . configuration . web . ServletRequestConfiguration ; import org . apache . http . NameValuePair ; import org . apache . http . client . utils . URLEncodedUtils ; import org . apache . lucene . document . Document ; import org . apache . lucene . document . Field ; import org . apache . lucene . search . Explanation ; import org . apache . lucene . search . SortField ; import org . json . JSONException ; import org . json . JSONObject ; import com . browseengine . bobo . api . BrowseFacet ; import com . browseengine . bobo . api . BrowseSelection ; import com . browseengine . bobo . api . FacetAccessible ; import com . browseengine . bobo . api . FacetSpec ; import com . browseengine . bobo . api . MappedFacetAccessible ; import com . browseengine . bobo . facets . DefaultFacetHandlerInitializerParam ; import com . browseengine . bobo . facets . FacetHandlerInitializerParam ; import com . senseidb . search . req . SenseiHit ; import com . senseidb . search . req . SenseiJSONQuery ; import com . senseidb . search . req . SenseiQuery ; import com . senseidb . search . req . SenseiRequest ; import com . senseidb . search . req . SenseiResult ; import com . senseidb . servlet . DefaultSenseiJSONServlet ; import com . senseidb . svc . api . SenseiException ; import com . senseidb . svc . impl . HttpRestSenseiServiceImpl ; public class TestHttpRestSenseiServiceImpl extends TestCase { private static final int EXPECTED_COUNT = <NUM_LIT> ; private static final int EXPECTED_OFFSET = <NUM_LIT> ; private static final boolean EXPECTED_FETCH_STORED_FIELDS = true ; private static final boolean EXPECTED_SHOW_EXPLANATION = true ; public TestHttpRestSenseiServiceImpl ( String name ) { super ( name ) ; } public void testSenseiResultParsing ( ) throws Exception { SenseiRequest aRequest = createNonRandomSenseiRequest ( ) ; SenseiResult aResult = createMockResultFromRequest ( aRequest ) ; JSONObject resultJSONObj = DefaultSenseiJSONServlet . buildJSONResult ( aRequest , aResult ) ; SenseiResult bResult = HttpRestSenseiServiceImpl . buildSenseiResult ( resultJSONObj ) ; assertEquals ( aResult , bResult ) ; } private SenseiResult createMockResultFromRequest ( SenseiRequest request ) { SenseiResult result = new SenseiResult ( ) ; result . setParsedQuery ( "<STR_LIT>" ) ; result . setTime ( Long . MAX_VALUE / <NUM_LIT:2> ) ; result . setNumHits ( Integer . MAX_VALUE / <NUM_LIT:2> ) ; result . setTid ( <NUM_LIT:1> ) ; result . setTotalDocs ( <NUM_LIT> ) ; result . setHits ( createSenseiHits ( <NUM_LIT:10> ) ) ; result . addAll ( createFacetAccessibleMap ( request ) ) ; return result ; } private SenseiHit [ ] createSenseiHits ( int count ) { List < SenseiHit > hits = new ArrayList < SenseiHit > ( ) ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { SenseiHit sh = new SenseiHit ( ) ; sh . setUID ( i ) ; sh . setDocid ( <NUM_LIT:100> + i ) ; sh . setExplanation ( createExplanation ( i , i ) ) ; sh . setFieldValues ( i % <NUM_LIT:2> == <NUM_LIT:0> ? createFieldValues ( i ) : null ) ; sh . setRawFieldValues ( i % <NUM_LIT:2> == <NUM_LIT:0> ? createRawFieldValues ( i ) : null ) ; sh . setStoredFields ( createSenseiHitDocument ( ) ) ; hits . add ( sh ) ; } return hits . toArray ( new SenseiHit [ hits . size ( ) ] ) ; } private Document createSenseiHitDocument ( ) { Document doc = new Document ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:10> ; i ++ ) { doc . add ( new org . apache . lucene . document . Field ( "<STR_LIT:name>" + i , "<STR_LIT:value>" + i , Field . Store . YES , Field . Index . ANALYZED ) ) ; } return doc ; } private Map < String , String [ ] > createFieldValues ( int uid ) { Map < String , String [ ] > map = new HashMap < String , String [ ] > ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:10> ; i ++ ) { map . put ( String . format ( "<STR_LIT>" , uid , i ) , new String [ ] { "<STR_LIT:hello>" + i , "<STR_LIT>" + i } ) ; } return map ; } private Map < String , Object [ ] > createRawFieldValues ( int uid ) { Map < String , Object [ ] > map = new HashMap < String , Object [ ] > ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:10> ; i ++ ) { map . put ( String . format ( "<STR_LIT>" , uid , i ) , new String [ ] { "<STR_LIT:hello>" + i , "<STR_LIT>" + i } ) ; } return map ; } private Explanation createExplanation ( int facetIndex , int descCount ) { Explanation expl = new Explanation ( ) ; expl . setDescription ( String . format ( "<STR_LIT>" , facetIndex ) ) ; expl . setValue ( facetIndex ) ; for ( int i = <NUM_LIT:0> ; i < descCount ; i ++ ) { expl . addDetail ( createExplanation ( ( <NUM_LIT:1000> * facetIndex ) + i , <NUM_LIT:0> ) ) ; } return expl ; } private Map < String , FacetAccessible > createFacetAccessibleMap ( SenseiRequest request ) { Map < String , FacetAccessible > facetAccessibleMap = new HashMap < String , FacetAccessible > ( ) ; for ( int i = <NUM_LIT:10> ; i < <NUM_LIT:20> ; i ++ ) { String fieldName = "<STR_LIT>" + i ; List < BrowseFacet > bfList = new ArrayList < BrowseFacet > ( ) ; Map < String , FacetSpec > facetSpecs = request . getFacetSpecs ( ) ; for ( String facetName : facetSpecs . keySet ( ) ) { BrowseFacet bf = new BrowseFacet ( ) ; bf . setFacetValueHitCount ( i ) ; bf . setValue ( String . format ( "<STR_LIT>" , fieldName , facetName ) ) ; bfList . add ( bf ) ; } MappedFacetAccessible mfa = new MappedFacetAccessible ( bfList . toArray ( new BrowseFacet [ bfList . size ( ) ] ) ) ; facetAccessibleMap . put ( fieldName , mfa ) ; } return facetAccessibleMap ; } public void testURIBuilding ( ) throws JSONException , SenseiException , UnsupportedEncodingException , URISyntaxException , MalformedURLException { SenseiRequest aRequest = createNonRandomSenseiRequest ( ) ; List < NameValuePair > queryParams = HttpRestSenseiServiceImpl . convertRequestToQueryParams ( aRequest ) ; HttpRestSenseiServiceImpl senseiService = createSenseiService ( ) ; URI requestURI = senseiService . buildRequestURI ( queryParams ) ; assertTrue ( requestURI . toURL ( ) . toString ( ) . length ( ) > <NUM_LIT:0> ) ; List < NameValuePair > parsedParams = URLEncodedUtils . parse ( requestURI , "<STR_LIT:UTF-8>" ) ; MockServletRequest mockServletRequest = MockServletRequest . create ( parsedParams ) ; DataConfiguration params = new DataConfiguration ( new ServletRequestConfiguration ( mockServletRequest ) ) ; SenseiRequest bRequest = DefaultSenseiJSONServlet . convertSenseiRequest ( params ) ; assertEquals ( aRequest , bRequest ) ; } public void testConvertSenseiRequest ( ) throws SenseiException , UnsupportedEncodingException , JSONException { SenseiRequest testRequest = createNonRandomSenseiRequest ( ) ; List < NameValuePair > list = HttpRestSenseiServiceImpl . convertRequestToQueryParams ( testRequest ) ; MockServletRequest mockServletRequest = MockServletRequest . create ( list ) ; DataConfiguration params = new DataConfiguration ( new ServletRequestConfiguration ( mockServletRequest ) ) ; SenseiRequest resultRequest = DefaultSenseiJSONServlet . convertSenseiRequest ( params ) ; assertEquals ( testRequest , resultRequest ) ; } public void testConvertScalarValues ( ) throws SenseiException , UnsupportedEncodingException , JSONException { SenseiRequest aRequest = new SenseiRequest ( ) ; aRequest . setCount ( EXPECTED_COUNT ) ; aRequest . setOffset ( EXPECTED_OFFSET ) ; aRequest . setFetchStoredFields ( EXPECTED_FETCH_STORED_FIELDS ) ; aRequest . setShowExplanation ( EXPECTED_SHOW_EXPLANATION ) ; SenseiRequest bRequest = new SenseiRequest ( ) ; List < NameValuePair > list = HttpRestSenseiServiceImpl . convertRequestToQueryParams ( aRequest ) ; MockServletRequest mockServletRequest = MockServletRequest . create ( list ) ; DataConfiguration params = new DataConfiguration ( new ServletRequestConfiguration ( mockServletRequest ) ) ; DefaultSenseiJSONServlet . convertScalarParams ( bRequest , params ) ; assertEquals ( aRequest , bRequest ) ; } public void testInitParams ( ) throws UnsupportedEncodingException { SenseiRequest aRequest = new SenseiRequest ( ) ; Map < String , FacetHandlerInitializerParam > initParams = createInitParams ( ) ; aRequest . putAllFacetHandlerInitializerParams ( initParams ) ; SenseiRequest bRequest = new SenseiRequest ( ) ; List < NameValuePair > qparams = new ArrayList < NameValuePair > ( ) ; HttpRestSenseiServiceImpl . convertFacetInitParams ( qparams , initParams ) ; MockServletRequest mockServletRequest = MockServletRequest . create ( qparams ) ; DataConfiguration params = new DataConfiguration ( new ServletRequestConfiguration ( mockServletRequest ) ) ; DefaultSenseiJSONServlet . convertInitParams ( bRequest , params ) ; assertEquals ( aRequest , bRequest ) ; } public void testFacetSpecs ( ) { SenseiRequest aRequest = new SenseiRequest ( ) ; Map < String , FacetSpec > facetSpecMap = createFacetSpecMap ( ) ; aRequest . setFacetSpecs ( facetSpecMap ) ; SenseiRequest bRequest = new SenseiRequest ( ) ; List < NameValuePair > list = new ArrayList < NameValuePair > ( ) ; HttpRestSenseiServiceImpl . convertFacetSpecs ( list , facetSpecMap ) ; MockServletRequest mockServletRequest = MockServletRequest . create ( list ) ; DataConfiguration params = new DataConfiguration ( new ServletRequestConfiguration ( mockServletRequest ) ) ; DefaultSenseiJSONServlet . convertFacetParam ( bRequest , params ) ; assertEquals ( aRequest , bRequest ) ; } public void testSortFields ( ) { SenseiRequest aRequest = new SenseiRequest ( ) ; final SortField [ ] sortFields = createSortFields ( ) ; aRequest . addSortFields ( sortFields ) ; SenseiRequest bRequest = new SenseiRequest ( ) ; List < NameValuePair > list = new ArrayList < NameValuePair > ( ) ; HttpRestSenseiServiceImpl . convertSortFieldParams ( list , sortFields ) ; MockServletRequest mockServletRequest = MockServletRequest . create ( list ) ; DataConfiguration params = new DataConfiguration ( new ServletRequestConfiguration ( mockServletRequest ) ) ; DefaultSenseiJSONServlet . convertSortParam ( bRequest , params ) ; assertEquals ( aRequest , bRequest ) ; } public void testSenseiQuery ( ) throws SenseiException , JSONException { SenseiRequest aRequest = new SenseiRequest ( ) ; SenseiQuery senseiQuery = createSenseiQuery ( ) ; aRequest . setQuery ( senseiQuery ) ; SenseiRequest bRequest = new SenseiRequest ( ) ; List < NameValuePair > list = new ArrayList < NameValuePair > ( ) ; HttpRestSenseiServiceImpl . convertSenseiQuery ( list , senseiQuery ) ; MockServletRequest mockServletRequest = MockServletRequest . create ( list ) ; DataConfiguration params = new DataConfiguration ( new ServletRequestConfiguration ( mockServletRequest ) ) ; DefaultSenseiJSONServlet . convertSenseiQuery ( bRequest , params ) ; assertEquals ( aRequest , bRequest ) ; } public void testNullSenseiQuery ( ) throws SenseiException { List < NameValuePair > list = new ArrayList < NameValuePair > ( ) ; HttpRestSenseiServiceImpl . convertSenseiQuery ( list , null ) ; assertTrue ( list . size ( ) == <NUM_LIT:0> ) ; } public void testPartitions ( ) throws SenseiException , JSONException { SenseiRequest aRequest = new SenseiRequest ( ) ; Set < Integer > partitions = createPartitions ( ) ; aRequest . setPartitions ( partitions ) ; SenseiRequest bRequest = new SenseiRequest ( ) ; List < NameValuePair > list = new ArrayList < NameValuePair > ( ) ; HttpRestSenseiServiceImpl . convertPartitionParams ( list , partitions ) ; MockServletRequest mockServletRequest = MockServletRequest . create ( list ) ; DataConfiguration params = new DataConfiguration ( new ServletRequestConfiguration ( mockServletRequest ) ) ; DefaultSenseiJSONServlet . convertPartitionParams ( bRequest , params ) ; assertEquals ( aRequest , bRequest ) ; } public void testNullPartitions ( ) { List < NameValuePair > list = new ArrayList < NameValuePair > ( ) ; HttpRestSenseiServiceImpl . convertPartitionParams ( list , null ) ; assertTrue ( list . size ( ) == <NUM_LIT:0> ) ; } public void testBrowseSelections ( ) throws JSONException { SenseiRequest aRequest = new SenseiRequest ( ) ; BrowseSelection [ ] selections = createBrowseSelections ( ) ; aRequest . addSelections ( selections ) ; SenseiRequest bRequest = new SenseiRequest ( ) ; bRequest . addSelections ( selections ) ; List < NameValuePair > list = new ArrayList < NameValuePair > ( ) ; HttpRestSenseiServiceImpl . convertSelectionNames ( list , bRequest ) ; MockServletRequest mockServletRequest = MockServletRequest . create ( list ) ; DataConfiguration params = new DataConfiguration ( new ServletRequestConfiguration ( mockServletRequest ) ) ; DefaultSenseiJSONServlet . convertSelectParam ( bRequest , params ) ; assertEquals ( aRequest , bRequest ) ; } private HttpRestSenseiServiceImpl createSenseiService ( ) { return new HttpRestSenseiServiceImpl ( "<STR_LIT:http>" , "<STR_LIT:localhost>" , <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT:5> , null ) ; } private SenseiRequest createNonRandomSenseiRequest ( ) throws JSONException { SenseiRequest req = new SenseiRequest ( ) ; createScalarValues ( req ) ; req . setFacetHandlerInitParamMap ( createInitParams ( ) ) ; req . setFacetSpecs ( createFacetSpecMap ( ) ) ; req . setSort ( createSortFields ( ) ) ; req . setQuery ( createSenseiQuery ( ) ) ; req . addSelections ( createBrowseSelections ( ) ) ; req . setPartitions ( createPartitions ( ) ) ; return req ; } void createScalarValues ( SenseiRequest req ) { req . setCount ( EXPECTED_COUNT ) ; req . setOffset ( EXPECTED_OFFSET ) ; req . setFetchStoredFields ( EXPECTED_FETCH_STORED_FIELDS ) ; req . setShowExplanation ( EXPECTED_SHOW_EXPLANATION ) ; } Set < Integer > createPartitions ( ) { HashSet < Integer > partitions = new HashSet < Integer > ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:10> ; i ++ ) { partitions . add ( i * i ) ; } return partitions ; } BrowseSelection [ ] createBrowseSelections ( ) { List < BrowseSelection > list = new ArrayList < BrowseSelection > ( ) ; BrowseSelection selection ; selection = new BrowseSelection ( "<STR_LIT>" ) ; selection . addNotValue ( "<STR_LIT>" ) ; selection . addValue ( "<STR_LIT>" ) ; selection . setSelectionOperation ( BrowseSelection . ValueOperation . ValueOperationAnd ) ; list . add ( selection ) ; return list . toArray ( new BrowseSelection [ list . size ( ) ] ) ; } SenseiQuery createSenseiQuery ( ) throws JSONException { JSONObject obj = new JSONObject ( ) ; obj . put ( "<STR_LIT:query>" , "<STR_LIT>" ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:10> ; i ++ ) { obj . put ( "<STR_LIT:key>" + i , "<STR_LIT>" + i ) ; } SenseiQuery query = new SenseiJSONQuery ( obj ) ; return query ; } SortField [ ] createSortFields ( ) { List < SortField > list = new ArrayList < SortField > ( ) ; list . add ( new SortField ( null , SortField . DOC ) ) ; list . add ( new SortField ( null , SortField . DOC , true ) ) ; list . add ( new SortField ( null , SortField . SCORE ) ) ; list . add ( new SortField ( null , SortField . SCORE , true ) ) ; list . add ( new SortField ( "<STR_LIT>" , SortField . CUSTOM , false ) ) ; list . add ( new SortField ( "<STR_LIT>" , SortField . CUSTOM , true ) ) ; return list . toArray ( new SortField [ list . size ( ) ] ) ; } Map < String , FacetSpec > createFacetSpecMap ( ) { Map < String , FacetSpec > map = new HashMap < String , FacetSpec > ( ) ; FacetSpec spec = new FacetSpec ( ) ; spec . setExpandSelection ( false ) ; spec . setMaxCount ( <NUM_LIT:10> ) ; spec . setMinHitCount ( <NUM_LIT:2> ) ; spec . setOrderBy ( FacetSpec . FacetSortSpec . OrderHitsDesc ) ; map . put ( "<STR_LIT>" , spec ) ; spec = new FacetSpec ( ) ; spec . setExpandSelection ( true ) ; spec . setMaxCount ( <NUM_LIT:5> ) ; spec . setMinHitCount ( <NUM_LIT:10> ) ; spec . setOrderBy ( FacetSpec . FacetSortSpec . OrderValueAsc ) ; map . put ( "<STR_LIT>" , spec ) ; for ( int i = <NUM_LIT:3> ; i < <NUM_LIT:10> ; i ++ ) { spec = new FacetSpec ( ) ; spec . setExpandSelection ( i % <NUM_LIT:2> == <NUM_LIT:0> ) ; spec . setMaxCount ( i * <NUM_LIT:5> ) ; spec . setMinHitCount ( i ) ; spec . setOrderBy ( i % <NUM_LIT:2> == <NUM_LIT:0> ? FacetSpec . FacetSortSpec . OrderValueAsc : FacetSpec . FacetSortSpec . OrderHitsDesc ) ; map . put ( "<STR_LIT>" + i , spec ) ; } return map ; } Map < String , FacetHandlerInitializerParam > createInitParams ( ) { Map < String , FacetHandlerInitializerParam > map = new HashMap < String , FacetHandlerInitializerParam > ( ) ; DefaultFacetHandlerInitializerParam param ; param = new DefaultFacetHandlerInitializerParam ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:2> ; i ++ ) { param . putBooleanParam ( "<STR_LIT>" + i , new boolean [ ] { false } ) ; map . put ( "<STR_LIT>" + i , param ) ; } param = new DefaultFacetHandlerInitializerParam ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:2> ; i ++ ) { param . putIntParam ( "<STR_LIT>" + i , new int [ ] { <NUM_LIT> } ) ; map . put ( "<STR_LIT>" + i , param ) ; } param = new DefaultFacetHandlerInitializerParam ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:2> ; i ++ ) { param . putStringParam ( "<STR_LIT>" + i , new ArrayList < String > ( ) { { add ( "<STR_LIT>" ) ; } } ) ; map . put ( "<STR_LIT>" + i , param ) ; } param = new DefaultFacetHandlerInitializerParam ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:2> ; i ++ ) { param . putDoubleParam ( "<STR_LIT>" + i , new double [ ] { <NUM_LIT> } ) ; map . put ( "<STR_LIT>" + i , param ) ; } param = new DefaultFacetHandlerInitializerParam ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:2> ; i ++ ) { param . putLongParam ( "<STR_LIT>" + i , new long [ ] { <NUM_LIT> , <NUM_LIT> } ) ; map . put ( "<STR_LIT>" + i , param ) ; } return map ; } } </s>
<s> package com . senseidb . test ; import java . io . File ; import java . net . URL ; import javax . management . InstanceAlreadyExistsException ; import com . senseidb . indexing . activity . facet . ActivityRangeFacetHandler ; import org . apache . log4j . Logger ; import org . mortbay . jetty . Server ; import org . springframework . context . ApplicationContext ; import org . springframework . context . support . ClassPathXmlApplicationContext ; import com . linkedin . norbert . NorbertException ; import com . linkedin . norbert . javacompat . cluster . ClusterClient ; import com . linkedin . norbert . javacompat . network . NetworkServer ; import com . senseidb . cluster . client . SenseiNetworkClient ; import com . senseidb . conf . SenseiServerBuilder ; import com . senseidb . jmx . JmxSenseiMBeanServer ; import com . senseidb . search . node . SenseiBroker ; import com . senseidb . search . node . SenseiRequestScatterRewriter ; import com . senseidb . search . node . SenseiServer ; import com . senseidb . search . node . SenseiZoieFactory ; import com . senseidb . search . req . SenseiRequest ; import com . senseidb . search . req . SenseiResult ; import com . senseidb . svc . api . SenseiService ; import com . senseidb . svc . impl . HttpRestSenseiServiceImpl ; public class SenseiStarter { private static final Logger logger = Logger . getLogger ( SenseiStarter . class ) ; public static File ConfDir1 = null ; public static File ConfDir2 = null ; public static File IndexDir = new File ( "<STR_LIT>" ) ; public static URL SenseiUrl = null ; public static SenseiBroker broker = null ; public static SenseiService httpRestSenseiService = null ; public static SenseiServer node1 ; public static SenseiServer node2 ; public static Server httpServer1 ; public static Server httpServer2 ; public static SenseiNetworkClient networkClient ; public static ClusterClient clusterClient ; public static SenseiRequestScatterRewriter requestRewriter ; public static NetworkServer networkServer1 ; public static NetworkServer networkServer2 ; public static final String SENSEI_TEST_CONF_FILE = "<STR_LIT>" ; public static SenseiZoieFactory < ? > _zoieFactory ; public static boolean started = false ; public static URL federatedBrokerUrl ; public static synchronized void start ( String confDir1 , String confDir2 ) { ActivityRangeFacetHandler . isSynchronized = true ; if ( started ) { logger . warn ( "<STR_LIT>" ) ; return ; } try { JmxSenseiMBeanServer . registerCustomMBeanServer ( ) ; ConfDir1 = new File ( SenseiStarter . class . getClassLoader ( ) . getResource ( confDir1 ) . toURI ( ) ) ; ConfDir2 = new File ( SenseiStarter . class . getClassLoader ( ) . getResource ( confDir2 ) . toURI ( ) ) ; org . apache . log4j . PropertyConfigurator . configure ( "<STR_LIT>" ) ; loadFromSpringContext ( ) ; boolean removeSuccessful = rmrf ( IndexDir ) ; if ( ! removeSuccessful ) { throw new IllegalStateException ( "<STR_LIT>" + IndexDir + "<STR_LIT>" ) ; } SenseiServerBuilder senseiServerBuilder1 = null ; senseiServerBuilder1 = new SenseiServerBuilder ( ConfDir1 , null ) ; node1 = senseiServerBuilder1 . buildServer ( ) ; httpServer1 = senseiServerBuilder1 . buildHttpRestServer ( ) ; logger . info ( "<STR_LIT>" ) ; SenseiServerBuilder senseiServerBuilder2 = null ; senseiServerBuilder2 = new SenseiServerBuilder ( ConfDir2 , null ) ; node2 = senseiServerBuilder2 . buildServer ( ) ; httpServer2 = senseiServerBuilder2 . buildHttpRestServer ( ) ; logger . info ( "<STR_LIT>" ) ; broker = null ; try { broker = new SenseiBroker ( networkClient , clusterClient , true ) ; } catch ( NorbertException ne ) { logger . info ( "<STR_LIT>" , ne ) ; clusterClient . shutdown ( ) ; throw ne ; } httpRestSenseiService = new HttpRestSenseiServiceImpl ( "<STR_LIT:http>" , "<STR_LIT:localhost>" , <NUM_LIT> , "<STR_LIT>" ) ; logger . info ( "<STR_LIT>" ) ; Runtime . getRuntime ( ) . addShutdownHook ( new Thread ( ) { @ Override public void run ( ) { shutdownSensei ( ) ; } } ) ; node1 . start ( true ) ; httpServer1 . start ( ) ; logger . info ( "<STR_LIT>" ) ; node2 . start ( true ) ; httpServer2 . start ( ) ; logger . info ( "<STR_LIT>" ) ; SenseiUrl = new URL ( "<STR_LIT>" ) ; federatedBrokerUrl = new URL ( "<STR_LIT>" ) ; waitTillServerStarts ( ) ; } catch ( Throwable ex ) { logger . error ( "<STR_LIT>" , ex ) ; throw new RuntimeException ( ex ) ; } finally { started = true ; } } private static void waitTillServerStarts ( ) throws Exception { SenseiRequest req = new SenseiRequest ( ) ; SenseiResult res = null ; int count = <NUM_LIT:0> ; do { Thread . sleep ( <NUM_LIT> ) ; res = broker . browse ( req ) ; System . out . println ( "<STR_LIT>" + res . getNumHits ( ) + "<STR_LIT>" ) ; ++ count ; } while ( count < <NUM_LIT:20> && res . getNumHits ( ) < <NUM_LIT> ) ; } private static void loadFromSpringContext ( ) { ApplicationContext testSpringCtx = null ; try { testSpringCtx = new ClassPathXmlApplicationContext ( "<STR_LIT>" ) ; } catch ( Throwable e ) { if ( e instanceof InstanceAlreadyExistsException ) logger . warn ( "<STR_LIT>" ) ; else logger . error ( "<STR_LIT>" , e . getCause ( ) ) ; } networkClient = ( SenseiNetworkClient ) testSpringCtx . getBean ( "<STR_LIT>" ) ; clusterClient = ( ClusterClient ) testSpringCtx . getBean ( "<STR_LIT>" ) ; requestRewriter = ( SenseiRequestScatterRewriter ) testSpringCtx . getBean ( "<STR_LIT>" ) ; networkServer1 = ( NetworkServer ) testSpringCtx . getBean ( "<STR_LIT>" ) ; networkServer2 = ( NetworkServer ) testSpringCtx . getBean ( "<STR_LIT>" ) ; _zoieFactory = ( SenseiZoieFactory < ? > ) testSpringCtx . getBean ( "<STR_LIT>" ) ; } public static boolean rmrf ( File f ) { if ( f == null || ! f . exists ( ) ) { return true ; } if ( f . isDirectory ( ) ) { for ( File sub : f . listFiles ( ) ) { if ( ! rmrf ( sub ) ) return false ; } } return f . delete ( ) ; } private static void shutdownSensei ( ) { try { broker . shutdown ( ) ; } catch ( Throwable t ) { } try { httpRestSenseiService . shutdown ( ) ; } catch ( Throwable t ) { } try { node1 . shutdown ( ) ; } catch ( Throwable t ) { } try { httpServer1 . stop ( ) ; } catch ( Throwable t ) { } try { node2 . shutdown ( ) ; } catch ( Throwable t ) { } try { httpServer2 . stop ( ) ; } catch ( Throwable t ) { } try { networkClient . shutdown ( ) ; } catch ( Throwable t ) { } try { clusterClient . shutdown ( ) ; } catch ( Throwable t ) { } rmrf ( IndexDir ) ; } } </s>
<s> package com . senseidb . test . plugin ; import java . util . HashSet ; import java . util . Map ; import com . browseengine . bobo . api . BoboIndexReader ; import com . browseengine . bobo . facets . data . FacetDataCache ; import com . browseengine . bobo . facets . data . FacetDataFetcher ; import com . browseengine . bobo . facets . data . PredefinedTermListFactory ; import com . browseengine . bobo . facets . data . TermFixedLengthLongArrayListFactory ; import com . browseengine . bobo . facets . impl . VirtualSimpleFacetHandler ; import com . senseidb . plugin . SenseiPluginFactory ; import com . senseidb . plugin . SenseiPluginRegistry ; import proj . zoie . api . ZoieIndexReader ; public class VirtualGroupIdFactory implements SenseiPluginFactory < VirtualSimpleFacetHandler > { @ Override public VirtualSimpleFacetHandler getBean ( Map < String , String > initProperties , String fullPrefix , SenseiPluginRegistry pluginRegistry ) { if ( "<STR_LIT:default>" . equals ( initProperties . get ( "<STR_LIT>" ) ) ) { HashSet < String > depends = new HashSet < String > ( ) ; depends . add ( "<STR_LIT>" ) ; return new VirtualSimpleFacetHandler ( "<STR_LIT>" , new PredefinedTermListFactory ( Long . class , "<STR_LIT>" ) , facetDataFetcher , depends ) ; } if ( "<STR_LIT>" . equals ( initProperties . get ( "<STR_LIT>" ) ) ) { HashSet < String > depends = new HashSet < String > ( ) ; depends . add ( "<STR_LIT>" ) ; return new VirtualSimpleFacetHandler ( "<STR_LIT>" , new TermFixedLengthLongArrayListFactory ( <NUM_LIT:2> ) , facetDataFetcherFixedLengthLongArray , depends ) ; } return null ; } public static FacetDataFetcher facetDataFetcher = new FacetDataFetcher ( ) { @ Override public Object fetch ( BoboIndexReader reader , int doc ) { FacetDataCache dataCache = ( FacetDataCache ) reader . getFacetData ( "<STR_LIT>" ) ; long ret = ( Long ) dataCache . valArray . getRawValue ( dataCache . orderArray . get ( doc ) ) ; if ( ret < <NUM_LIT:0> ) ret *= - <NUM_LIT:1> ; return ret ; } @ Override public void cleanup ( BoboIndexReader reader ) { } } ; public static class GroupIdFetcherFactory implements SenseiPluginFactory < FacetDataFetcher > { public FacetDataFetcher getBean ( Map < String , String > initProperties , String fullPrefix , SenseiPluginRegistry pluginRegistry ) { return VirtualGroupIdFactory . facetDataFetcher ; } } public static FacetDataFetcher facetDataFetcherFixedLengthLongArray = new FacetDataFetcher ( ) { @ Override public Object fetch ( BoboIndexReader reader , int doc ) { long uid = ( ( ZoieIndexReader ) reader . getInnerReader ( ) ) . getUID ( doc ) ; long [ ] val = new long [ <NUM_LIT:2> ] ; val [ <NUM_LIT:0> ] = uid ; if ( uid % <NUM_LIT:4> == <NUM_LIT:1> ) val [ <NUM_LIT:0> ] = val [ <NUM_LIT:0> ] - <NUM_LIT:1> ; if ( uid % <NUM_LIT:4> == <NUM_LIT:2> ) val [ <NUM_LIT:0> ] = val [ <NUM_LIT:0> ] - <NUM_LIT:2> ; val [ <NUM_LIT:1> ] = uid / <NUM_LIT:10> ; return val ; } @ Override public void cleanup ( BoboIndexReader reader ) { } } ; } </s>
<s> package com . senseidb . test . plugin ; import java . util . List ; import junit . framework . Assert ; import org . apache . commons . configuration . PropertiesConfiguration ; import org . apache . lucene . analysis . Analyzer ; import org . junit . After ; import org . junit . Before ; import org . junit . Test ; import com . browseengine . bobo . facets . FacetHandler ; import com . browseengine . bobo . facets . impl . SimpleFacetHandler ; import com . browseengine . bobo . facets . impl . VirtualSimpleFacetHandler ; import com . senseidb . plugin . SenseiPluginRegistry ; public class SenseiConfigurationTest extends Assert { private PropertiesConfiguration configuration ; private SenseiPluginRegistry pluginRegistry ; @ Before public void setUp ( ) throws Exception { configuration = new PropertiesConfiguration ( ) ; configuration . setDelimiterParsingDisabled ( true ) ; configuration . load ( getClass ( ) . getClassLoader ( ) . getResource ( "<STR_LIT>" ) ) ; pluginRegistry = SenseiPluginRegistry . build ( configuration ) ; pluginRegistry . start ( ) ; } @ After public void tearDown ( ) { pluginRegistry . stop ( ) ; } @ Test public void test1GetBeanByFullPrefix ( ) { Analyzer analyzer = pluginRegistry . getBeanByFullPrefix ( "<STR_LIT>" , Analyzer . class ) ; assertNotNull ( analyzer ) ; } @ Test public void test2GetBeanByName ( ) { Analyzer analyzer = pluginRegistry . getBeanByName ( "<STR_LIT>" , Analyzer . class ) ; assertNotNull ( analyzer ) ; } @ Test public void test3ConfigParams ( ) { MyCustomRouterFactory customRouterFactory = pluginRegistry . getBeansByType ( MyCustomRouterFactory . class ) . get ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , customRouterFactory . config . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , customRouterFactory . config . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT:3>" , customRouterFactory . config . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , customRouterFactory . config . get ( "<STR_LIT>" ) ) ; assertTrue ( customRouterFactory . started ) ; } @ Test public void test4GetBeanList ( ) { List < FacetHandler > customFacets = pluginRegistry . resolveBeansByListKey ( "<STR_LIT>" , FacetHandler . class ) ; assertEquals ( <NUM_LIT:6> , customFacets . size ( ) ) ; assertTrue ( customFacets . get ( <NUM_LIT:0> ) instanceof VirtualSimpleFacetHandler ) ; assertTrue ( customFacets . get ( <NUM_LIT:4> ) instanceof SimpleFacetHandler ) ; } @ Test public void test5GetEmptyBeanList ( ) { List < Object > beans = pluginRegistry . resolveBeansByListKey ( "<STR_LIT>" , Object . class ) ; assertEquals ( <NUM_LIT:0> , beans . size ( ) ) ; } @ Test public void test6GetFacet ( ) { assertEquals ( "<STR_LIT>" , pluginRegistry . getFacet ( "<STR_LIT>" ) . getName ( ) ) ; assertEquals ( "<STR_LIT>" , pluginRegistry . getFacet ( "<STR_LIT>" ) . getName ( ) ) ; } @ Test public void test7GetRuntimeFacet ( ) { assertEquals ( "<STR_LIT>" , pluginRegistry . getRuntimeFacet ( "<STR_LIT>" ) . getName ( ) ) ; assertEquals ( "<STR_LIT>" , pluginRegistry . getFacet ( "<STR_LIT>" ) . getName ( ) ) ; } public void test8GetRuntimeFacetClassCast ( ) { assertNull ( pluginRegistry . getFacet ( "<STR_LIT>" ) ) ; } } </s>
<s> package com . senseidb . test . plugin ; import java . util . Map ; import com . senseidb . plugin . SenseiPlugin ; import com . senseidb . plugin . SenseiPluginRegistry ; public class MyCustomRouterFactory implements SenseiPlugin { public Map < String , String > config ; public boolean started ; @ Override public void init ( Map < String , String > config , SenseiPluginRegistry pluginRegistry ) { this . config = config ; } @ Override public void start ( ) { started = true ; } @ Override public void stop ( ) { } } </s>
<s> package com . senseidb . test . plugin ; import com . browseengine . bobo . facets . FacetHandlerInitializerParam ; import com . browseengine . bobo . facets . RuntimeFacetHandler ; import com . browseengine . bobo . facets . AbstractRuntimeFacetHandlerFactory ; public class MockRuntimeFacetHandlerFactory extends AbstractRuntimeFacetHandlerFactory < FacetHandlerInitializerParam , RuntimeFacetHandler < ? > > { @ Override public String getName ( ) { return "<STR_LIT>" ; } @ Override public RuntimeFacetHandler < ? > get ( FacetHandlerInitializerParam params ) { return null ; } } </s>
<s> package com . senseidb . test . plugin ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import com . browseengine . bobo . facets . FacetHandler ; import com . browseengine . bobo . facets . data . PredefinedTermListFactory ; import com . browseengine . bobo . facets . impl . SimpleFacetHandler ; import com . senseidb . plugin . SenseiPluginFactory ; import com . senseidb . plugin . SenseiPluginRegistry ; public class OtherCustomFacetsFactory implements SenseiPluginFactory < List < FacetHandler < ? > > > { @ Override public List < FacetHandler < ? > > getBean ( Map < String , String > initProperties , String fullPrefix , SenseiPluginRegistry pluginRegistry ) { List < FacetHandler < ? > > ret = new ArrayList < FacetHandler < ? > > ( ) ; ret . add ( new SimpleFacetHandler ( "<STR_LIT>" , "<STR_LIT>" , new PredefinedTermListFactory ( Long . class ) , new HashSet < String > ( ) ) ) ; ret . add ( new SimpleFacetHandler ( "<STR_LIT>" , "<STR_LIT>" , new PredefinedTermListFactory ( Long . class ) , new HashSet < String > ( ) ) ) ; ret . add ( new SimpleFacetHandler ( "<STR_LIT>" , "<STR_LIT>" , new PredefinedTermListFactory ( Long . class ) , new HashSet < String > ( ) ) ) ; return ret ; } } </s>
<s> package com . senseidb . test ; import junit . framework . TestCase ; import org . apache . log4j . Logger ; import org . json . JSONObject ; import com . senseidb . search . req . mapred . TestMapReduce ; import com . senseidb . svc . api . SenseiService ; public class TestFederatedBroker extends TestCase { private static final Logger logger = Logger . getLogger ( TestMapReduce . class ) ; private static SenseiService httpRestSenseiService ; static { SenseiStarter . start ( "<STR_LIT>" , "<STR_LIT>" ) ; httpRestSenseiService = SenseiStarter . httpRestSenseiService ; } public void test1OneClusterIsEnough ( ) throws Exception { String req = "<STR_LIT>" ; JSONObject reqJson = new JSONObject ( req ) ; JSONObject res = TestSensei . search ( reqJson ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:24> , res . getInt ( "<STR_LIT>" ) ) ; res = TestSensei . search ( SenseiStarter . federatedBrokerUrl , reqJson . toString ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:24> , res . getInt ( "<STR_LIT>" ) ) ; } public void test2TwoClusters ( ) throws Exception { String req = "<STR_LIT>" ; JSONObject reqJson = new JSONObject ( req ) ; JSONObject res = TestSensei . search ( reqJson ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:24> , res . getInt ( "<STR_LIT>" ) ) ; res = TestSensei . search ( SenseiStarter . federatedBrokerUrl , reqJson . toString ( ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getJSONArray ( "<STR_LIT>" ) . length ( ) ) ; } } </s>
<s> package com . senseidb . test . util ; import junit . framework . TestCase ; import org . apache . commons . io . IOUtils ; import org . json . JSONObject ; import org . junit . Before ; import org . junit . Test ; import com . senseidb . util . JsonTemplateProcessor ; public class JsonTemplateProcessorTest extends TestCase { private String senseiRequestStr ; private JsonTemplateProcessor jsonTemplateProcessor ; @ Override @ Before public void setUp ( ) throws Exception { senseiRequestStr = new String ( IOUtils . toString ( getClass ( ) . getClassLoader ( ) . getResourceAsStream ( "<STR_LIT>" ) ) ) ; jsonTemplateProcessor = new JsonTemplateProcessor ( ) ; } @ Test public void testSubstituteTemplates ( ) throws Exception { JSONObject requestJson = new JSONObject ( senseiRequestStr ) ; JSONObject substituted = ( JSONObject ) jsonTemplateProcessor . process ( requestJson , jsonTemplateProcessor . getTemplates ( requestJson ) ) ; System . out . println ( substituted . toString ( <NUM_LIT:1> ) ) ; assertEquals ( <NUM_LIT:10> , substituted . getInt ( "<STR_LIT:count>" ) ) ; assertEquals ( <NUM_LIT:1.0> , substituted . getDouble ( "<STR_LIT>" ) , <NUM_LIT> ) ; assertEquals ( "<STR_LIT>" , substituted . getString ( "<STR_LIT>" ) ) ; } @ Test public void testSubstituteTemplatesNoMatch ( ) throws Exception { JSONObject requestJson = new JSONObject ( senseiRequestStr ) ; System . out . println ( requestJson . toString ( <NUM_LIT:1> ) ) ; requestJson . remove ( "<STR_LIT>" ) ; requestJson . put ( "<STR_LIT>" , new JSONObject ( ) . put ( "<STR_LIT>" , "<STR_LIT:value>" ) ) ; JSONObject substituted = jsonTemplateProcessor . substituteTemplates ( requestJson ) ; assertSame ( substituted , requestJson ) ; } } </s>
<s> package com . senseidb . test ; import junit . framework . TestCase ; import org . apache . log4j . Logger ; import org . json . JSONObject ; import com . senseidb . search . req . mapred . TestMapReduce ; import com . senseidb . svc . api . SenseiService ; public class TestIndexSelector extends TestCase { private static final Logger logger = Logger . getLogger ( TestIndexSelector . class ) ; private static SenseiService httpRestSenseiService ; static { SenseiStarter . start ( "<STR_LIT>" , "<STR_LIT>" ) ; httpRestSenseiService = SenseiStarter . httpRestSenseiService ; } public void test1SelectionRange1 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , res . getInt ( "<STR_LIT>" ) ) ; } public void testSelectionRange2 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:20> , res . getInt ( "<STR_LIT>" ) ) ; } public void testSelectionRange3 ( ) throws Exception { logger . info ( "<STR_LIT>" ) ; String req = "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:11> , res . getInt ( "<STR_LIT>" ) ) ; } } </s>
<s> package com . senseidb . test ; import java . text . DecimalFormat ; import java . text . DecimalFormatSymbols ; import java . text . Format ; import java . text . SimpleDateFormat ; import java . util . ArrayList ; import java . util . Date ; import java . util . HashSet ; import java . util . List ; import java . util . Locale ; import java . util . Set ; import junit . framework . TestCase ; import org . apache . lucene . document . Document ; import org . apache . lucene . document . Field ; import org . apache . lucene . document . Field . Index ; import org . apache . lucene . document . Field . Store ; import org . apache . lucene . document . Field . TermVector ; import proj . zoie . api . indexing . ZoieIndexable ; import proj . zoie . api . indexing . ZoieIndexable . IndexingReq ; import com . senseidb . indexing . DefaultSenseiInterpreter ; import com . senseidb . indexing . DeleteChecker ; import com . senseidb . indexing . Meta ; import com . senseidb . indexing . MetaType ; import com . senseidb . indexing . SkipChecker ; import com . senseidb . indexing . StoredValue ; import com . senseidb . indexing . Text ; import com . senseidb . indexing . Uid ; public class TestIndexingAPI extends TestCase { static class TestObj { @ Uid private long uid ; TestObj ( long uid ) { this . uid = uid ; } @ Text ( name = "<STR_LIT:text>" ) private String content ; @ Text ( store = "<STR_LIT>" , index = "<STR_LIT>" , termVector = "<STR_LIT>" ) private String content2 ; @ StoredValue ( name = "<STR_LIT>" ) private String storedVal ; @ Meta private int age ; @ Meta ( format = "<STR_LIT>" , type = MetaType . Date ) private Date today ; @ Meta ( name = "<STR_LIT>" , type = MetaType . String ) private short shortVal ; @ Meta private List < String > tags ; @ Meta ( name = "<STR_LIT>" , type = MetaType . Long ) private List < Long > nulls ; @ Meta ( name = "<STR_LIT>" , type = MetaType . Integer ) private Set < Integer > numSet ; @ DeleteChecker private boolean isDeleted ( ) { return uid == - <NUM_LIT:1> ; } @ SkipChecker private boolean isSkip ( ) { return uid == - <NUM_LIT:2> ; } } private DefaultSenseiInterpreter < TestObj > nodeInterpreter = new DefaultSenseiInterpreter ( TestObj . class ) ; public TestIndexingAPI ( ) { } public TestIndexingAPI ( String name ) { super ( name ) ; } public void testDelete ( ) { TestObj testObj = new TestObj ( <NUM_LIT:5> ) ; ZoieIndexable indexable = nodeInterpreter . convertAndInterpret ( testObj ) ; assertFalse ( indexable . isDeleted ( ) ) ; testObj = new TestObj ( - <NUM_LIT:1> ) ; indexable = nodeInterpreter . convertAndInterpret ( testObj ) ; assertTrue ( indexable . isDeleted ( ) ) ; } public void testSkip ( ) { TestObj testObj = new TestObj ( - <NUM_LIT:1> ) ; ZoieIndexable indexable = nodeInterpreter . convertAndInterpret ( testObj ) ; assertFalse ( indexable . isSkip ( ) ) ; testObj = new TestObj ( - <NUM_LIT:2> ) ; indexable = nodeInterpreter . convertAndInterpret ( testObj ) ; assertTrue ( indexable . isSkip ( ) ) ; } public void testUid ( ) { long uid = <NUM_LIT> ; TestObj testObj = new TestObj ( uid ) ; ZoieIndexable indexable = nodeInterpreter . convertAndInterpret ( testObj ) ; assertEquals ( <NUM_LIT> , indexable . getUID ( ) ) ; } public void testStoredContent ( ) { TestObj testObj = new TestObj ( <NUM_LIT:1> ) ; testObj . storedVal = "<STR_LIT>" ; ZoieIndexable indexable = nodeInterpreter . convertAndInterpret ( testObj ) ; IndexingReq [ ] reqs = indexable . buildIndexingReqs ( ) ; Document doc = reqs [ <NUM_LIT:0> ] . getDocument ( ) ; Field f = doc . getField ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , f . stringValue ( ) ) ; assertTrue ( f . isStored ( ) ) ; assertFalse ( f . isTermVectorStored ( ) ) ; assertFalse ( f . isIndexed ( ) ) ; assertFalse ( f . isTokenized ( ) ) ; } public void testTextContent ( ) { TestObj testObj = new TestObj ( <NUM_LIT:1> ) ; testObj . content = "<STR_LIT:abc>" ; testObj . content2 = "<STR_LIT>" ; ZoieIndexable indexable = nodeInterpreter . convertAndInterpret ( testObj ) ; IndexingReq [ ] reqs = indexable . buildIndexingReqs ( ) ; Document doc = reqs [ <NUM_LIT:0> ] . getDocument ( ) ; Field content1Field = doc . getField ( "<STR_LIT:text>" ) ; assertNotNull ( content1Field ) ; String val = content1Field . stringValue ( ) ; assertEquals ( "<STR_LIT:abc>" , val ) ; assertFalse ( content1Field . isStored ( ) ) ; assertFalse ( content1Field . isTermVectorStored ( ) ) ; assertTrue ( content1Field . isIndexed ( ) ) ; assertFalse ( content1Field . isTokenized ( ) ) ; Field content2Field = doc . getField ( "<STR_LIT>" ) ; assertNotNull ( content2Field ) ; val = content2Field . stringValue ( ) ; assertEquals ( "<STR_LIT>" , val ) ; assertTrue ( content2Field . isStored ( ) ) ; assertTrue ( content2Field . isTermVectorStored ( ) ) ; assertTrue ( content2Field . isIndexed ( ) ) ; assertFalse ( content2Field . isTokenized ( ) ) ; } private static boolean isMeta ( Field f ) { return ! f . isStored ( ) && f . isIndexed ( ) && ! f . isTermVectorStored ( ) && ! f . isTokenized ( ) ; } public void testMetaContent ( ) { long now = System . currentTimeMillis ( ) ; TestObj testObj = new TestObj ( <NUM_LIT:1> ) ; testObj . age = <NUM_LIT:11> ; testObj . shortVal = <NUM_LIT:3> ; testObj . today = new Date ( now ) ; testObj . tags = new ArrayList < String > ( ) ; testObj . tags . add ( "<STR_LIT>" ) ; testObj . tags . add ( "<STR_LIT>" ) ; testObj . numSet = new HashSet < Integer > ( ) ; testObj . numSet . add ( <NUM_LIT> ) ; testObj . numSet . add ( <NUM_LIT:6> ) ; testObj . numSet . add ( <NUM_LIT:7> ) ; testObj . nulls = null ; ZoieIndexable indexable = nodeInterpreter . convertAndInterpret ( testObj ) ; IndexingReq [ ] reqs = indexable . buildIndexingReqs ( ) ; Document doc = reqs [ <NUM_LIT:0> ] . getDocument ( ) ; Field ageField = doc . getField ( "<STR_LIT>" ) ; assertNotNull ( ageField ) ; assertTrue ( isMeta ( ageField ) ) ; String ageString = ageField . stringValue ( ) ; String formatString = DefaultSenseiInterpreter . DEFAULT_FORMAT_STRING_MAP . get ( MetaType . Integer ) ; Format formatter = new DecimalFormat ( formatString , new DecimalFormatSymbols ( Locale . US ) ) ; assertEquals ( formatter . format ( <NUM_LIT:11> ) , ageString ) ; Field shortField = doc . getField ( "<STR_LIT>" ) ; assertNotNull ( shortField ) ; assertTrue ( isMeta ( shortField ) ) ; String shortString = shortField . stringValue ( ) ; assertEquals ( "<STR_LIT:3>" , shortString ) ; Field todayField = doc . getField ( "<STR_LIT>" ) ; assertNotNull ( todayField ) ; assertTrue ( isMeta ( todayField ) ) ; String todayString = todayField . stringValue ( ) ; formatString = "<STR_LIT>" ; formatter = new SimpleDateFormat ( formatString ) ; assertEquals ( todayString , formatter . format ( testObj . today ) ) ; Field [ ] fields = doc . getFields ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:2> , fields . length ) ; for ( Field f : fields ) { assertTrue ( testObj . tags . contains ( f . stringValue ( ) ) ) ; } fields = doc . getFields ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:3> , fields . length ) ; for ( Field f : fields ) { assertTrue ( testObj . numSet . contains ( Integer . parseInt ( f . stringValue ( ) ) ) ) ; } } public static void main ( String [ ] args ) { DefaultSenseiInterpreter < TestObj > nodeInterpreter = new DefaultSenseiInterpreter ( TestObj . class ) ; System . out . println ( nodeInterpreter ) ; } } </s>
<s> package com . senseidb . test ; import java . util . HashSet ; import java . util . Map ; import junit . framework . TestCase ; import org . apache . commons . configuration . BaseConfiguration ; import org . apache . commons . configuration . Configuration ; import com . senseidb . util . RequestConverter ; public class TestRestServer extends TestCase { public TestRestServer ( String name ) { super ( name ) ; } public void testParamParsing ( ) throws Exception { BaseConfiguration conf = new BaseConfiguration ( ) ; conf . addProperty ( "<STR_LIT>" , "<STR_LIT>" ) ; conf . addProperty ( "<STR_LIT>" , "<STR_LIT>" ) ; conf . addProperty ( "<STR_LIT>" , "<STR_LIT>" ) ; conf . addProperty ( "<STR_LIT>" , "<STR_LIT>" ) ; conf . addProperty ( "<STR_LIT>" , "<STR_LIT>" ) ; conf . addProperty ( "<STR_LIT>" , "<STR_LIT>" ) ; conf . addProperty ( "<STR_LIT>" , "<STR_LIT:1>" ) ; conf . addProperty ( "<STR_LIT>" , "<STR_LIT:10>" ) ; conf . addProperty ( "<STR_LIT>" , "<STR_LIT:false>" ) ; conf . addProperty ( "<STR_LIT>" , "<STR_LIT>" ) ; conf . addProperty ( "<STR_LIT>" , "<STR_LIT:0>" ) ; conf . addProperty ( "<STR_LIT>" , "<STR_LIT:5>" ) ; conf . addProperty ( "<STR_LIT>" , "<STR_LIT:true>" ) ; conf . addProperty ( "<STR_LIT>" , "<STR_LIT>" ) ; Map < String , Configuration > mapConf = RequestConverter . parseParamConf ( conf , "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:0> , mapConf . size ( ) ) ; mapConf = RequestConverter . parseParamConf ( conf , "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:2> , mapConf . size ( ) ) ; Configuration selColorConf = mapConf . get ( "<STR_LIT>" ) ; String [ ] vals = selColorConf . getStringArray ( "<STR_LIT>" ) ; assertNotNull ( vals ) ; assertEquals ( <NUM_LIT:2> , vals . length ) ; HashSet < String > targetSet = new HashSet < String > ( ) ; targetSet . add ( "<STR_LIT>" ) ; targetSet . add ( "<STR_LIT>" ) ; for ( String val : vals ) { assertTrue ( targetSet . remove ( val ) ) ; } Configuration selCityConf = mapConf . get ( "<STR_LIT>" ) ; vals = selCityConf . getStringArray ( "<STR_LIT>" ) ; assertNotNull ( vals ) ; assertEquals ( <NUM_LIT:1> , vals . length ) ; assertEquals ( vals [ <NUM_LIT:0> ] , "<STR_LIT>" ) ; mapConf = RequestConverter . parseParamConf ( conf , "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:2> , mapConf . size ( ) ) ; selColorConf = mapConf . get ( "<STR_LIT>" ) ; assertEquals ( false , selColorConf . getBoolean ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:1> , selColorConf . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:10> , selColorConf . getInt ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , selColorConf . getString ( "<STR_LIT>" ) ) ; selCityConf = mapConf . get ( "<STR_LIT>" ) ; assertEquals ( true , selCityConf . getBoolean ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:0> , selCityConf . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:5> , selCityConf . getInt ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , selCityConf . getString ( "<STR_LIT>" ) ) ; } } </s>
<s> package com . senseidb . search . facet . attribute ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileWriter ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Iterator ; import java . util . LinkedHashMap ; import java . util . List ; import java . util . Map ; import org . apache . commons . io . IOUtils ; public class DataConverter { private static Map < String , Integer > keys = new LinkedHashMap < String , Integer > ( ) ; public static int numOfElementsPerDoc = <NUM_LIT:3> ; static { keys . put ( "<STR_LIT:key1>" , <NUM_LIT> ) ; keys . put ( "<STR_LIT>" , <NUM_LIT> ) ; keys . put ( "<STR_LIT>" , <NUM_LIT> ) ; keys . put ( "<STR_LIT>" , <NUM_LIT> ) ; keys . put ( "<STR_LIT>" , <NUM_LIT> ) ; keys . put ( "<STR_LIT>" , <NUM_LIT:30> ) ; keys . put ( "<STR_LIT>" , <NUM_LIT> ) ; keys . put ( "<STR_LIT>" , <NUM_LIT:15> ) ; keys . put ( "<STR_LIT>" , <NUM_LIT:10> ) ; keys . put ( "<STR_LIT>" , <NUM_LIT:5> ) ; } static List < String > values = new ArrayList < String > ( <NUM_LIT:100> ) ; static Iterator < String > iterator ; public static String next ( ) { if ( iterator == null || ! iterator . hasNext ( ) ) { iterator = values . iterator ( ) ; } return iterator . next ( ) ; } public static void main ( String [ ] args ) throws Exception { values = createValuesList ( keys ) ; File carsFile = new File ( "<STR_LIT>" ) ; File resultFile = new File ( "<STR_LIT>" ) ; FileWriter fileWriter = new FileWriter ( resultFile , true ) ; for ( String line : IOUtils . readLines ( new FileInputStream ( carsFile ) ) ) { line = line . replaceFirst ( "<STR_LIT:U+002C>" , formDocEntry ( numOfElementsPerDoc ) ) ; fileWriter . append ( line + "<STR_LIT:n>" ) ; } fileWriter . close ( ) ; String value = formDocEntry ( numOfElementsPerDoc ) ; } private static String formDocEntry ( int numOfElementsPerDoc ) { String ret = "<STR_LIT>" ; for ( int i = <NUM_LIT:0> ; i < numOfElementsPerDoc - <NUM_LIT:1> ; i ++ ) { ret += next ( ) + "<STR_LIT:U+002C>" ; } ret += next ( ) + "<STR_LIT>" ; return ret ; } private static List < String > createValuesList ( Map < String , Integer > keys ) { List < String > ret = new ArrayList < String > ( keys . size ( ) * <NUM_LIT:10> ) ; for ( String key : keys . keySet ( ) ) { int frequency = keys . get ( key ) ; for ( int i = <NUM_LIT:1> ; i < <NUM_LIT:11> ; i ++ ) { String val = "<STR_LIT>" + i ; for ( int j = <NUM_LIT:0> ; j < frequency ; j ++ ) { ret . add ( key + "<STR_LIT:=>" + val ) ; } frequency = ( int ) ( frequency * <NUM_LIT> ) ; if ( frequency < <NUM_LIT:1> ) { frequency = <NUM_LIT:1> ; } } } System . out . println ( ret ) ; Collections . shuffle ( ret ) ; return ret ; } } </s>
<s> package com . senseidb . search . node . inmemory ; import java . io . File ; import java . util . ArrayList ; import java . util . List ; import org . apache . commons . io . FileUtils ; import org . apache . commons . io . LineIterator ; import org . json . JSONObject ; import com . senseidb . search . req . SenseiResult ; import junit . framework . TestCase ; public class InMemorySenseiServiceTest extends TestCase { private InMemorySenseiService inMemorySenseiService ; private List < JSONObject > docs ; @ Override protected void setUp ( ) throws Exception { inMemorySenseiService = InMemorySenseiService . valueOf ( new File ( InMemoryIndexPerfTest . class . getClassLoader ( ) . getResource ( "<STR_LIT>" ) . toURI ( ) ) ) ; LineIterator lineIterator = FileUtils . lineIterator ( new File ( InMemoryIndexPerfTest . class . getClassLoader ( ) . getResource ( "<STR_LIT>" ) . toURI ( ) ) ) ; int i = <NUM_LIT:0> ; docs = new ArrayList < JSONObject > ( ) ; while ( lineIterator . hasNext ( ) && i < <NUM_LIT:100> ) { String car = lineIterator . next ( ) ; if ( car != null && car . contains ( "<STR_LIT:{>" ) ) docs . add ( new JSONObject ( car ) ) ; i ++ ; } lineIterator . close ( ) ; } public void test1 ( ) { SenseiResult result = inMemorySenseiService . doQuery ( InMemoryIndexPerfTest . getRequest ( ) , docs ) ; assertEquals ( <NUM_LIT:16> , result . getNumHits ( ) ) ; assertEquals ( <NUM_LIT:100> , result . getTotalDocs ( ) ) ; } } </s>
<s> package com . senseidb . search . node . inmemory ; import java . io . File ; import java . util . ArrayList ; import java . util . List ; import org . apache . commons . io . FileUtils ; import org . apache . commons . io . LineIterator ; import org . json . JSONObject ; import com . browseengine . bobo . api . BrowseSelection ; import com . browseengine . bobo . api . FacetSpec ; import com . browseengine . bobo . api . FacetSpec . FacetSortSpec ; import com . senseidb . search . req . SenseiRequest ; public class InMemoryIndexPerfEval { public static void main ( String [ ] args ) throws Exception { final InMemorySenseiService memorySenseiService = InMemorySenseiService . valueOf ( new File ( InMemoryIndexPerfEval . class . getClassLoader ( ) . getResource ( "<STR_LIT>" ) . toURI ( ) ) ) ; final List < JSONObject > docs = new ArrayList < JSONObject > ( <NUM_LIT> ) ; LineIterator lineIterator = FileUtils . lineIterator ( new File ( InMemoryIndexPerfEval . class . getClassLoader ( ) . getResource ( "<STR_LIT>" ) . toURI ( ) ) ) ; int i = <NUM_LIT:0> ; while ( lineIterator . hasNext ( ) && i < <NUM_LIT:100> ) { String car = lineIterator . next ( ) ; if ( car != null && car . contains ( "<STR_LIT:{>" ) ) docs . add ( new JSONObject ( car ) ) ; i ++ ; } Thread [ ] threads = new Thread [ <NUM_LIT:10> ] ; for ( int k = <NUM_LIT:0> ; k < threads . length ; k ++ ) { threads [ k ] = new Thread ( new Runnable ( ) { public void run ( ) { long time = System . currentTimeMillis ( ) ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:1000> ; j ++ ) { memorySenseiService . doQuery ( getRequest ( ) , docs ) ; } System . out . println ( "<STR_LIT>" + ( System . currentTimeMillis ( ) - time ) ) ; } } ) ; threads [ k ] . start ( ) ; } Thread . sleep ( <NUM_LIT> ) ; } private static void setspec ( SenseiRequest req , FacetSpec spec ) { req . setFacetSpec ( "<STR_LIT>" , spec ) ; req . setFacetSpec ( "<STR_LIT>" , spec ) ; req . setFacetSpec ( "<STR_LIT>" , spec ) ; req . setFacetSpec ( "<STR_LIT>" , spec ) ; req . setFacetSpec ( "<STR_LIT>" , spec ) ; req . setFacetSpec ( "<STR_LIT>" , spec ) ; req . setFacetSpec ( "<STR_LIT>" , spec ) ; req . setFacetSpec ( "<STR_LIT>" , spec ) ; } public static SenseiRequest getRequest ( ) { FacetSpec facetSpecall = new FacetSpec ( ) ; facetSpecall . setMaxCount ( <NUM_LIT> ) ; facetSpecall . setExpandSelection ( true ) ; facetSpecall . setMinHitCount ( <NUM_LIT:0> ) ; facetSpecall . setOrderBy ( FacetSortSpec . OrderHitsDesc ) ; FacetSpec facetSpec = new FacetSpec ( ) ; facetSpec . setMaxCount ( <NUM_LIT:5> ) ; SenseiRequest req = new SenseiRequest ( ) ; req . setCount ( <NUM_LIT:3> ) ; facetSpecall . setMaxCount ( <NUM_LIT:3> ) ; setspec ( req , facetSpecall ) ; BrowseSelection sel = new BrowseSelection ( "<STR_LIT>" ) ; String selVal = "<STR_LIT>" ; sel . addValue ( selVal ) ; req . addSelection ( sel ) ; return req ; } } </s>
<s> package com . senseidb . search . req . mapred ; import java . io . Serializable ; import java . util . ArrayList ; import java . util . List ; import org . json . JSONObject ; public class ListAllUIDs implements SenseiMapReduce < Serializable , Serializable > { @ Override public void init ( JSONObject params ) { } @ Override public Serializable map ( int [ ] docIds , int docIdCount , long [ ] uids , FieldAccessor accessor , FacetCountAccessor facetCountAccessor ) { ArrayList < Long > collectedUids = new ArrayList < Long > ( docIdCount ) ; for ( int i = <NUM_LIT:0> ; i < docIdCount ; i ++ ) { collectedUids . add ( uids [ docIds [ i ] ] ) ; } System . out . println ( "<STR_LIT>" + collectedUids ) ; return collectedUids ; } @ Override public List < Serializable > combine ( List < Serializable > mapResults , CombinerStage combinerStage ) { return mapResults ; } @ Override public Serializable reduce ( List < Serializable > combineResults ) { return new ArrayList < Serializable > ( combineResults ) ; } @ Override public JSONObject render ( Serializable reduceResult ) { return new JSONObject ( ) ; } } </s>
<s> package com . senseidb . search . req . mapred ; import java . io . Serializable ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . Iterator ; import java . util . List ; import java . util . Map ; import java . util . concurrent . atomic . AtomicInteger ; import org . jboss . netty . util . internal . ConcurrentHashMap ; import org . json . JSONArray ; import org . json . JSONException ; import org . json . JSONObject ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public class CountGroupByMapReduce implements SenseiMapReduce < HashMap < String , IntContainer > , ArrayList < GroupedValue > > { private static final long serialVersionUID = <NUM_LIT:1L> ; private String [ ] columns ; public void init ( JSONObject params ) { try { JSONArray columnsJson = params . getJSONArray ( "<STR_LIT>" ) ; columns = new String [ columnsJson . length ( ) ] ; for ( int i = <NUM_LIT:0> ; i < columnsJson . length ( ) ; i ++ ) { columns [ i ] = columnsJson . getString ( i ) ; } } catch ( JSONException ex ) { throw new RuntimeException ( ex ) ; } } public HashMap < String , IntContainer > map ( int [ ] docIds , int docIdCount , long [ ] uids , FieldAccessor accessor , FacetCountAccessor facetCountAccessor ) { HashMap < String , IntContainer > ret = new HashMap < String , IntContainer > ( ) ; int duplicatedUids = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < docIdCount ; i ++ ) { String key = getKey ( columns , accessor , docIds [ i ] ) ; IntContainer count = ret . get ( key ) ; if ( ! ret . containsKey ( key ) ) { ret . put ( key , new IntContainer ( <NUM_LIT:1> ) ) ; } else { count . add ( <NUM_LIT:1> ) ; } } return ret ; } private String getKey ( String [ ] columns , FieldAccessor fieldAccessor , int docId ) { StringBuilder key = new StringBuilder ( fieldAccessor . get ( columns [ <NUM_LIT:0> ] , docId ) . toString ( ) ) ; for ( int i = <NUM_LIT:1> ; i < columns . length ; i ++ ) { key . append ( "<STR_LIT::>" ) . append ( fieldAccessor . get ( columns [ i ] , docId ) . toString ( ) ) ; } return key . toString ( ) ; } @ Override public List < HashMap < String , IntContainer > > combine ( List < HashMap < String , IntContainer > > mapResults , CombinerStage combinerStage ) { if ( mapResults == null || mapResults . isEmpty ( ) ) return mapResults ; HashMap < String , IntContainer > ret = new HashMap < String , IntContainer > ( ) ; for ( int i = <NUM_LIT:0> ; i < mapResults . size ( ) ; i ++ ) { Map < String , IntContainer > map = mapResults . get ( i ) ; for ( String key : map . keySet ( ) ) { IntContainer count = ret . get ( key ) ; if ( count != null ) { count . add ( map . get ( key ) . value ) ; } else { ret . put ( key , map . get ( key ) ) ; } } } return java . util . Arrays . asList ( ret ) ; } @ Override public ArrayList < GroupedValue > reduce ( List < HashMap < String , IntContainer > > combineResults ) { if ( combineResults == null || combineResults . isEmpty ( ) ) return new ArrayList < GroupedValue > ( ) ; Map < String , IntContainer > retMap = new HashMap < String , IntContainer > ( ) ; for ( int i = <NUM_LIT:0> ; i < combineResults . size ( ) ; i ++ ) { Map < String , IntContainer > map = combineResults . get ( i ) ; for ( String key : map . keySet ( ) ) { IntContainer count = retMap . get ( key ) ; if ( count != null ) { count . add ( map . get ( key ) . value ) ; } else { retMap . put ( key , map . get ( key ) ) ; } } } ArrayList < GroupedValue > ret = new ArrayList < GroupedValue > ( ) ; for ( Map . Entry < String , IntContainer > entry : retMap . entrySet ( ) ) { ret . add ( new GroupedValue ( entry . getKey ( ) , entry . getValue ( ) . value ) ) ; } Collections . sort ( ret ) ; return ret ; } public JSONObject render ( ArrayList < GroupedValue > reduceResult ) { try { List < JSONObject > ret = new ArrayList < JSONObject > ( ) ; for ( GroupedValue grouped : reduceResult ) { ret . add ( new JSONObject ( ) . put ( grouped . key , grouped . value ) ) ; } return new JSONObject ( ) . put ( "<STR_LIT>" , new JSONArray ( ret ) ) ; } catch ( JSONException ex ) { throw new RuntimeException ( ex ) ; } } } class GroupedValue implements Comparable { String key ; int value ; public GroupedValue ( String key , int value ) { super ( ) ; this . key = key ; this . value = value ; } @ Override public int compareTo ( Object o ) { return ( ( GroupedValue ) o ) . value - value ; } @ Override public String toString ( ) { return key + "<STR_LIT>" + value ; } } </s>
<s> package com . senseidb . search . req . mapred ; import java . io . Serializable ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Iterator ; import java . util . List ; import java . util . Map ; import java . util . concurrent . atomic . AtomicInteger ; import org . jboss . netty . util . internal . ConcurrentHashMap ; import org . json . JSONArray ; import org . json . JSONException ; import org . json . JSONObject ; import scala . actors . threadpool . Arrays ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public class DistinctUIDCount implements SenseiMapReduce < HashSet < Long > , Integer > { private static final long serialVersionUID = <NUM_LIT:1L> ; public void init ( JSONObject params ) { } @ Override public HashSet < Long > map ( int [ ] docIds , int docIdCount , long [ ] uids , FieldAccessor accessor , FacetCountAccessor facetCountAccessor ) { HashSet < Long > ret = new HashSet < Long > ( docIdCount ) ; for ( int i = <NUM_LIT:0> ; i < docIdCount ; i ++ ) { ret . add ( uids [ docIds [ i ] ] ) ; } return ret ; } @ Override public List < HashSet < Long > > combine ( List < HashSet < Long > > mapResults , CombinerStage combinerStage ) { HashSet < Long > ret = new HashSet < Long > ( ) ; for ( HashSet < Long > mapResult : mapResults ) { ret . addAll ( mapResult ) ; } return java . util . Arrays . asList ( ret ) ; } @ Override public Integer reduce ( List < HashSet < Long > > combineResults ) { HashSet < Long > ret = new HashSet < Long > ( ) ; for ( HashSet < Long > mapResult : combineResults ) { ret . addAll ( mapResult ) ; } return ret . size ( ) ; } @ Override public JSONObject render ( Integer reduceResult ) { try { return new JSONObject ( ) . put ( "<STR_LIT>" , reduceResult ) ; } catch ( JSONException e ) { throw new RuntimeException ( e ) ; } } } </s>
<s> package com . senseidb . search . req . mapred ; import junit . framework . TestCase ; import org . apache . log4j . Logger ; import org . json . JSONObject ; import com . senseidb . svc . api . SenseiService ; import com . senseidb . test . SenseiStarter ; import com . senseidb . test . TestSensei ; public class TestMapReduce extends TestCase { private static final Logger logger = Logger . getLogger ( TestMapReduce . class ) ; private static SenseiService httpRestSenseiService ; static { SenseiStarter . start ( "<STR_LIT>" , "<STR_LIT>" ) ; httpRestSenseiService = SenseiStarter . httpRestSenseiService ; } public void test2GroupByColorAndGroupId ( ) throws Exception { String req = "<STR_LIT>" + "<STR_LIT>" ; JSONObject reqJson = new JSONObject ( req ) ; System . out . println ( reqJson . toString ( <NUM_LIT:1> ) ) ; JSONObject res = TestSensei . search ( reqJson ) ; JSONObject highestResult = res . getJSONObject ( "<STR_LIT>" ) . getJSONArray ( "<STR_LIT>" ) . getJSONObject ( <NUM_LIT:0> ) ; assertEquals ( <NUM_LIT:8> , highestResult . getInt ( highestResult . keys ( ) . next ( ) . toString ( ) ) ) ; } public void test4MaxMapReduce ( ) throws Exception { String req = "<STR_LIT>" + "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; JSONObject mapReduceResult = res . getJSONObject ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT> , Long . parseLong ( mapReduceResult . getString ( "<STR_LIT>" ) ) ) ; assertEquals ( <NUM_LIT> , Long . parseLong ( mapReduceResult . getString ( "<STR_LIT>" ) ) ) ; req = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; res = TestSensei . search ( new JSONObject ( req ) ) ; mapReduceResult = res . getJSONObject ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT> , Long . parseLong ( mapReduceResult . getString ( "<STR_LIT>" ) ) ) ; } public void test5DistinctCount ( ) throws Exception { String req = "<STR_LIT>" + "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; JSONObject mapReduceResult = res . getJSONObject ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT> , Long . parseLong ( mapReduceResult . getString ( "<STR_LIT>" ) ) ) ; req = "<STR_LIT:{>" + "<STR_LIT>" ; res = TestSensei . search ( new JSONObject ( req ) ) ; mapReduceResult = res . getJSONObject ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT> , Long . parseLong ( mapReduceResult . getString ( "<STR_LIT>" ) ) ) ; } public void test6MinMapReduce ( ) throws Exception { String req = "<STR_LIT>" + "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; JSONObject mapReduceResult = res . getJSONObject ( "<STR_LIT>" ) ; assertEquals ( - <NUM_LIT> , Long . parseLong ( mapReduceResult . getString ( "<STR_LIT>" ) ) ) ; assertEquals ( <NUM_LIT> , Long . parseLong ( mapReduceResult . getString ( "<STR_LIT>" ) ) ) ; req = "<STR_LIT>" + "<STR_LIT>" ; res = TestSensei . search ( new JSONObject ( req ) ) ; mapReduceResult = res . getJSONObject ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT> , Long . parseLong ( mapReduceResult . getString ( "<STR_LIT>" ) ) ) ; } public void test7SumMapReduce ( ) throws Exception { String req = "<STR_LIT>" + "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; JSONObject mapReduceResult = res . getJSONObject ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT> , mapReduceResult . getLong ( "<STR_LIT>" ) ) ; } public void test8AvgMapReduce ( ) throws Exception { String req = "<STR_LIT>" + "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; JSONObject mapReduceResult = res . getJSONObject ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT> , mapReduceResult . getLong ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , Long . parseLong ( mapReduceResult . getString ( "<STR_LIT:count>" ) ) ) ; } public void test9FacetCountMapReduce ( ) throws Exception { String req = "<STR_LIT>" + "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; JSONObject mapReduceResult = res . getJSONObject ( "<STR_LIT>" ) ; System . out . println ( mapReduceResult . toString ( <NUM_LIT:1> ) ) ; assertEquals ( <NUM_LIT> , mapReduceResult . getJSONObject ( "<STR_LIT>" ) . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , mapReduceResult . getJSONObject ( "<STR_LIT>" ) . getInt ( "<STR_LIT>" ) ) ; } public void test10FacetCountMapReduceWithFilter ( ) throws Exception { String req = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; JSONObject res = TestSensei . search ( new JSONObject ( req ) ) ; JSONObject mapReduceResult = res . getJSONObject ( "<STR_LIT>" ) ; System . out . println ( mapReduceResult . toString ( <NUM_LIT:1> ) ) ; assertEquals ( <NUM_LIT> , mapReduceResult . getJSONObject ( "<STR_LIT>" ) . getInt ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT> , mapReduceResult . getJSONObject ( "<STR_LIT>" ) . getInt ( "<STR_LIT>" ) ) ; } } </s>
<s> package com . senseidb . search . req . mapred ; import java . io . Serializable ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import org . json . JSONException ; import org . json . JSONObject ; import com . browseengine . bobo . facets . data . TermValueList ; import com . browseengine . bobo . util . BigSegmentedArray ; public class FacetCountsMapReduce implements SenseiMapReduce < HashMap < String , IntContainer > , ArrayList < GroupedValue > > { private static final long serialVersionUID = <NUM_LIT:1L> ; private String column ; public void init ( JSONObject params ) { try { column = params . getString ( "<STR_LIT>" ) ; } catch ( JSONException ex ) { throw new RuntimeException ( ex ) ; } } public HashMap < String , IntContainer > map ( int [ ] docIds , int docIdCount , long [ ] uids , FieldAccessor accessor , FacetCountAccessor facetCountAccessor ) { if ( ! facetCountAccessor . areFacetCountsPresent ( ) ) { return null ; } BigSegmentedArray countDistribution = facetCountAccessor . getFacetCollector ( column ) . getCountDistribution ( ) ; TermValueList termValueList = accessor . getTermValueList ( column ) ; HashMap < String , IntContainer > ret = new HashMap < String , IntContainer > ( countDistribution . size ( ) ) ; for ( int i = <NUM_LIT:0> ; i < countDistribution . size ( ) ; i ++ ) { ret . put ( termValueList . get ( i ) , new IntContainer ( countDistribution . get ( i ) ) ) ; } return ret ; } private String getKey ( String [ ] columns , FieldAccessor fieldAccessor , int docId ) { StringBuilder key = new StringBuilder ( fieldAccessor . get ( columns [ <NUM_LIT:0> ] , docId ) . toString ( ) ) ; for ( int i = <NUM_LIT:1> ; i < columns . length ; i ++ ) { key . append ( "<STR_LIT::>" ) . append ( fieldAccessor . get ( columns [ i ] , docId ) . toString ( ) ) ; } return key . toString ( ) ; } @ Override public List < HashMap < String , IntContainer > > combine ( List < HashMap < String , IntContainer > > mapResults , CombinerStage combinerStage ) { if ( mapResults == null || mapResults . isEmpty ( ) ) return mapResults ; HashMap < String , IntContainer > ret = new HashMap < String , IntContainer > ( ) ; for ( int i = <NUM_LIT:0> ; i < mapResults . size ( ) ; i ++ ) { Map < String , IntContainer > map = mapResults . get ( i ) ; if ( map == null ) { continue ; } for ( String key : map . keySet ( ) ) { IntContainer count = ret . get ( key ) ; if ( count != null ) { count . add ( map . get ( key ) . value ) ; } else { ret . put ( key , map . get ( key ) ) ; } } } return java . util . Arrays . asList ( ret ) ; } @ Override public ArrayList < GroupedValue > reduce ( List < HashMap < String , IntContainer > > combineResults ) { if ( combineResults == null || combineResults . isEmpty ( ) ) return new ArrayList < GroupedValue > ( ) ; Map < String , IntContainer > retMap = new HashMap < String , IntContainer > ( ) ; for ( int i = <NUM_LIT:0> ; i < combineResults . size ( ) ; i ++ ) { Map < String , IntContainer > map = combineResults . get ( i ) ; for ( String key : map . keySet ( ) ) { IntContainer count = retMap . get ( key ) ; if ( count != null ) { count . add ( map . get ( key ) . value ) ; } else { retMap . put ( key , map . get ( key ) ) ; } } } ArrayList < GroupedValue > ret = new ArrayList < GroupedValue > ( ) ; for ( Map . Entry < String , IntContainer > entry : retMap . entrySet ( ) ) { ret . add ( new GroupedValue ( entry . getKey ( ) , entry . getValue ( ) . value ) ) ; } Collections . sort ( ret ) ; return ret ; } public JSONObject render ( ArrayList < GroupedValue > reduceResult ) { try { JSONObject ret = new JSONObject ( ) ; for ( GroupedValue grouped : reduceResult ) { ret . put ( grouped . key , grouped . value ) ; } return new JSONObject ( ) . put ( "<STR_LIT>" , ret ) ; } catch ( JSONException ex ) { throw new RuntimeException ( ex ) ; } } } class IntContainer implements Serializable { public int value ; public IntContainer ( int value ) { super ( ) ; this . value = value ; } public IntContainer add ( int value ) { this . value += value ; return this ; } } </s>
<s> package com . sensei . test ; import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . File ; import java . io . FileReader ; import java . io . FileWriter ; import java . util . StringTokenizer ; import org . json . JSONObject ; import junit . framework . TestCase ; import com . google . protobuf . ByteString ; import com . google . protobuf . TextFormat . ParseException ; import com . sensei . search . req . protobuf . ProtoConvertUtil ; public class TestSerialization extends TestCase { public TestSerialization ( String testName ) { super ( testName ) ; } public void testIntegerSerialization ( ) { int [ ] intData = new int [ ] { <NUM_LIT:0> , - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } ; try { ByteString intDataString = ProtoConvertUtil . serializeData ( intData ) ; int [ ] outIntData = ProtoConvertUtil . toIntArray ( intDataString ) ; assertEquals ( intData . length , outIntData . length ) ; for ( int i = <NUM_LIT:0> ; i < intData . length ; i ++ ) { assertEquals ( intData [ i ] , outIntData [ i ] ) ; } } catch ( ParseException e ) { e . printStackTrace ( ) ; fail ( e . getMessage ( ) ) ; } } public void testDoubleSerialization ( ) { double [ ] doubleData = new double [ ] { <NUM_LIT> , Double . longBitsToDouble ( <NUM_LIT> ) , Double . longBitsToDouble ( - <NUM_LIT> ) } ; try { ByteString doubleDataString = ProtoConvertUtil . serializeData ( doubleData ) ; double [ ] outDoubleData = ProtoConvertUtil . toDoubleArray ( doubleDataString ) ; assertEquals ( doubleData . length , outDoubleData . length ) ; for ( int i = <NUM_LIT:0> ; i < doubleData . length ; i ++ ) { assertEquals ( doubleData [ i ] , outDoubleData [ i ] ) ; } } catch ( ParseException pe ) { pe . printStackTrace ( ) ; fail ( pe . getMessage ( ) ) ; } } public void testLongSerialization ( ) { long [ ] longData = new long [ ] { <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> } ; try { ByteString longDataString = ProtoConvertUtil . serializeData ( longData ) ; long [ ] outLongData = ProtoConvertUtil . toLongArray ( longDataString ) ; assertEquals ( longData . length , outLongData . length ) ; for ( int i = <NUM_LIT:0> ; i < longData . length ; i ++ ) { assertEquals ( longData [ i ] , outLongData [ i ] ) ; } } catch ( ParseException e ) { e . printStackTrace ( ) ; fail ( e . getMessage ( ) ) ; } } public void testBooleanSerialization ( ) { boolean [ ] boolData = new boolean [ ] { true , false , false , true } ; try { ByteString boolDataString = ProtoConvertUtil . serializeData ( boolData ) ; boolean [ ] outBoolData = ProtoConvertUtil . toBooleanArray ( boolDataString ) ; assertEquals ( boolData . length , outBoolData . length ) ; for ( int i = <NUM_LIT:0> ; i < boolData . length ; i ++ ) { assertEquals ( boolData [ i ] , outBoolData [ i ] ) ; } } catch ( ParseException e ) { e . printStackTrace ( ) ; fail ( e . getMessage ( ) ) ; } } public void testCharSerialization ( ) { char [ ] charData = new char [ ] { '<CHAR_LIT>' , '<CHAR_LIT:e>' , '<CHAR_LIT>' , '<CHAR_LIT>' , '<CHAR_LIT:e>' , '<CHAR_LIT>' } ; try { ByteString charDataString = ProtoConvertUtil . serializeData ( charData ) ; char [ ] outcharData = ProtoConvertUtil . toCharArray ( charDataString ) ; assertEquals ( charData . length , outcharData . length ) ; for ( int i = <NUM_LIT:0> ; i < charData . length ; i ++ ) { assertEquals ( charData [ i ] , outcharData [ i ] ) ; } } catch ( ParseException e ) { e . printStackTrace ( ) ; fail ( e . getMessage ( ) ) ; } } static void addContent ( String field , String val , String sep , StringBuilder content ) { StringTokenizer strtok = new StringTokenizer ( val , sep ) ; while ( strtok . hasMoreTokens ( ) ) { content . append ( strtok . nextToken ( ) ) . append ( "<STR_LIT:U+0020>" ) ; } } public static void main ( String [ ] args ) throws Exception { File inFile = new File ( "<STR_LIT>" ) ; File outfile = new File ( "<STR_LIT>" ) ; BufferedWriter writer = new BufferedWriter ( new FileWriter ( outfile ) ) ; BufferedReader reader = new BufferedReader ( new FileReader ( inFile ) ) ; JSONObject car = new JSONObject ( ) ; int uid = <NUM_LIT:0> ; while ( true ) { String line = reader . readLine ( ) ; if ( line == null ) break ; if ( "<STR_LIT>" . equals ( line ) ) { car . put ( "<STR_LIT:id>" , uid ) ; StringBuilder builder = new StringBuilder ( ) ; builder . append ( car . optString ( "<STR_LIT>" ) ) . append ( "<STR_LIT:U+0020>" ) ; builder . append ( car . optString ( "<STR_LIT>" ) ) . append ( "<STR_LIT:U+0020>" ) ; addContent ( "<STR_LIT>" , car . optString ( "<STR_LIT>" ) , "<STR_LIT:U+002C>" , builder ) ; addContent ( "<STR_LIT>" , car . optString ( "<STR_LIT>" ) , "<STR_LIT:/>" , builder ) ; addContent ( "<STR_LIT>" , car . optString ( "<STR_LIT>" ) , "<STR_LIT:/>" , builder ) ; car . put ( "<STR_LIT>" , builder . toString ( ) ) ; String jsonLine = car . toString ( ) ; writer . write ( jsonLine + "<STR_LIT:n>" ) ; writer . flush ( ) ; uid ++ ; } else { String [ ] parts = line . split ( "<STR_LIT::>" ) ; String name = parts [ <NUM_LIT:0> ] ; String val = parts [ <NUM_LIT:1> ] ; if ( "<STR_LIT>" . equals ( name ) || "<STR_LIT>" . equals ( name ) || "<STR_LIT>" . equals ( name ) ) { int intVal = Integer . parseInt ( val ) ; car . put ( name , intVal ) ; } else { car . put ( name , val ) ; } } } reader . close ( ) ; System . out . println ( "<STR_LIT>" ) ; reader = new BufferedReader ( new FileReader ( outfile ) ) ; while ( true ) { String line = reader . readLine ( ) ; if ( line == null ) break ; JSONObject jsonObj = new JSONObject ( line ) ; System . out . println ( jsonObj ) ; } reader . close ( ) ; } } </s>
<s> package com . senseidb . perf ; import java . io . File ; import java . util . ArrayList ; import java . util . List ; import org . apache . commons . io . FileUtils ; import org . apache . lucene . search . Sort ; import org . json . JSONException ; import org . json . JSONObject ; import com . senseidb . search . client . SenseiServiceProxy ; import com . senseidb . search . client . json . JsonSerializer ; import com . senseidb . search . client . req . SenseiClientRequest ; import com . senseidb . search . node . SenseiServer ; public class TestRunner { static int generatedUid = <NUM_LIT:0> ; private static ArrayList < JSONObject > jsons ; private static int size ; static int readUid = <NUM_LIT:0> ; public static void main ( String [ ] args ) throws Exception { org . apache . log4j . PropertyConfigurator . configure ( "<STR_LIT>" ) ; SenseiServer . main ( new String [ ] { "<STR_LIT>" } ) ; List < String > linesFromFile = FileUtils . readLines ( new File ( "<STR_LIT>" ) ) ; jsons = new ArrayList < JSONObject > ( ) ; for ( String line : linesFromFile ) { if ( line == null || ! line . contains ( "<STR_LIT:{>" ) ) { continue ; } jsons . add ( new JSONObject ( line ) ) ; } size = jsons . size ( ) ; Thread thread = new Thread ( ) { public void run ( ) { while ( true ) { putNextDoc ( ) ; } } ; } ; thread . start ( ) ; Thread [ ] queryThreads = new Thread [ <NUM_LIT:1> ] ; final SenseiServiceProxy proxy = new SenseiServiceProxy ( "<STR_LIT:localhost>" , <NUM_LIT> ) ; Runnable query = new Runnable ( ) { @ Override public void run ( ) { while ( true ) { String sendPostRaw = proxy . sendPostRaw ( proxy . getSearchUrl ( ) , ( ( JSONObject ) JsonSerializer . serialize ( SenseiClientRequest . builder ( ) . addSort ( com . senseidb . search . client . req . Sort . desc ( "<STR_LIT>" ) ) . build ( ) ) ) . toString ( ) ) ; try { int numihits = new JSONObject ( sendPostRaw ) . getInt ( "<STR_LIT>" ) ; Thread . sleep ( <NUM_LIT> ) ; if ( numihits == <NUM_LIT:0> ) { System . out . println ( "<STR_LIT>" ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } } } } ; for ( int i = <NUM_LIT:0> ; i < queryThreads . length ; i ++ ) { queryThreads [ i ] = new Thread ( query ) ; queryThreads [ i ] . start ( ) ; } Thread . sleep ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT:1000> ) ; thread . join ( ) ; } public static void putNextDoc ( ) { if ( readUid == size ) { readUid = <NUM_LIT:0> ; } if ( generatedUid == <NUM_LIT> ) { generatedUid = <NUM_LIT:0> ; } JSONObject newEvent = clone ( jsons . get ( readUid ++ ) ) ; try { newEvent . put ( "<STR_LIT:id>" , generatedUid ++ ) ; PerfFileDataProvider . queue . put ( newEvent ) ; } catch ( Exception e ) { System . out . println ( "<STR_LIT>" + e . getMessage ( ) ) ; } } private static JSONObject clone ( JSONObject obj ) { JSONObject ret = new JSONObject ( ) ; for ( String key : JSONObject . getNames ( obj ) ) { try { ret . put ( key , obj . opt ( key ) ) ; } catch ( JSONException ex ) { throw new RuntimeException ( ex ) ; } } return ret ; } } </s>
<s> package com . senseidb . perf ; import java . io . File ; import java . util . Comparator ; import java . util . Set ; import java . util . concurrent . LinkedBlockingQueue ; import org . json . JSONObject ; import proj . zoie . impl . indexing . StreamDataProvider ; import proj . zoie . impl . indexing . ZoieConfig ; import com . senseidb . gateway . SenseiGateway ; import com . senseidb . indexing . DataSourceFilter ; import com . senseidb . indexing . ShardingStrategy ; public class LinedFileDataProviderMockBuilder extends SenseiGateway < String > { private Comparator < String > _versionComparator = ZoieConfig . DEFAULT_VERSION_COMPARATOR ; @ Override public StreamDataProvider < JSONObject > buildDataProvider ( DataSourceFilter < String > dataFilter , String oldSinceKey , ShardingStrategy shardingStrategy , Set < Integer > partitions ) throws Exception { String path = config . get ( "<STR_LIT>" ) ; if ( path == null ) { path = "<STR_LIT>" ; } long offset = oldSinceKey == null ? <NUM_LIT> : Long . parseLong ( oldSinceKey ) ; PerfFileDataProvider provider = new PerfFileDataProvider ( _versionComparator , new File ( path ) , <NUM_LIT> , new LinkedBlockingQueue < JSONObject > ( <NUM_LIT> ) ) ; if ( dataFilter != null ) { provider . setFilter ( dataFilter ) ; } return provider ; } @ Override public Comparator < String > getVersionComparator ( ) { return _versionComparator ; } } </s>
<s> package com . senseidb . perf ; import java . io . File ; import java . util . Comparator ; import java . util . concurrent . LinkedBlockingQueue ; import org . json . JSONObject ; import proj . zoie . api . DataConsumer . DataEvent ; import com . senseidb . gateway . file . LinedJsonFileDataProvider ; public class PerfFileDataProvider extends LinedJsonFileDataProvider { public static LinkedBlockingQueue < JSONObject > queue ; public PerfFileDataProvider ( Comparator < String > versionComparator , File file , long startingOffset , LinkedBlockingQueue < JSONObject > queue ) { super ( versionComparator , file , startingOffset ) ; this . queue = queue ; } @ Override public DataEvent < JSONObject > next ( ) { JSONObject object = null ; try { object = queue . take ( ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } if ( _offset % <NUM_LIT> == <NUM_LIT:0> ) { System . out . println ( "<STR_LIT>" + _offset + "<STR_LIT>" + queue . size ( ) ) ; } if ( object != null ) { return new DataEvent < JSONObject > ( object , String . valueOf ( _offset ++ ) ) ; } return super . next ( ) ; } } </s>
<s> package com . senseidb . servlet ; import java . io . File ; import javax . servlet . ServletConfig ; import javax . servlet . ServletContext ; import javax . servlet . ServletException ; import com . linkedin . norbert . javacompat . network . IntegerConsistentHashPartitionedLoadBalancerFactory ; import com . linkedin . norbert . javacompat . network . PartitionedLoadBalancerFactory ; import com . senseidb . cluster . routing . SenseiPartitionedLoadBalancerFactory ; import com . senseidb . conf . SenseiConfParams ; import com . senseidb . conf . SenseiServerBuilder ; import com . senseidb . plugin . SenseiPluginRegistry ; import com . senseidb . search . node . SenseiServer ; import com . senseidb . servlet . DefaultSenseiJSONServlet ; import com . senseidb . servlet . SenseiConfigServletContextListener ; public class SenseiNodeServlet extends DefaultSenseiJSONServlet { private static final long serialVersionUID = <NUM_LIT:1L> ; private SenseiServer _senseiServer = null ; @ Override public void init ( ServletConfig config ) throws ServletException { ServletContext ctx = config . getServletContext ( ) ; String confDirName = ctx . getInitParameter ( SenseiConfigServletContextListener . SENSEI_CONF_DIR_PARAM ) ; if ( confDirName == null ) { throw new ServletException ( "<STR_LIT>" + SenseiConfigServletContextListener . SENSEI_CONF_DIR_PARAM + "<STR_LIT>" ) ; } SenseiServerBuilder builder ; try { builder = new SenseiServerBuilder ( new File ( confDirName ) , null ) ; ctx . setAttribute ( "<STR_LIT>" , builder . getConfiguration ( ) ) ; ctx . setAttribute ( "<STR_LIT>" , builder . getVersionComparator ( ) ) ; SenseiPluginRegistry pluginRegistry = builder . getPluginRegistry ( ) ; PartitionedLoadBalancerFactory < String > routerFactory = pluginRegistry . getBeanByFullPrefix ( SenseiConfParams . SERVER_SEARCH_ROUTER_FACTORY , PartitionedLoadBalancerFactory . class ) ; if ( routerFactory == null ) { routerFactory = new SenseiPartitionedLoadBalancerFactory ( <NUM_LIT> ) ; } ctx . setAttribute ( "<STR_LIT>" , routerFactory ) ; _senseiServer = builder . buildServer ( ) ; _senseiServer . start ( true ) ; super . init ( config ) ; } catch ( Exception e ) { throw new ServletException ( e . getMessage ( ) , e ) ; } } @ Override public void destroy ( ) { if ( _senseiServer != null ) { _senseiServer . shutdown ( ) ; } super . destroy ( ) ; } } </s>
<s> package edu . wpi . first . wpilibj ; import edu . wpi . first . wpilibj . parsing . ISensor ; public class Ultrasonic extends SensorBase implements PIDSource , ISensor { public static class Unit { public final int value ; static final int kInches_val = <NUM_LIT:0> ; static final int kMillimeters_val = <NUM_LIT:1> ; public static final Unit kInches = new Unit ( kInches_val ) ; public static final Unit kMillimeter = new Unit ( kMillimeters_val ) ; private Unit ( int value ) { this . value = value ; } } private static final double kPingTime = <NUM_LIT:10> * <NUM_LIT> ; private static final int kPriority = <NUM_LIT> ; private static final double kMaxUltrasonicTime = <NUM_LIT> ; private static final double kSpeedOfSoundInchesPerSec = <NUM_LIT> * <NUM_LIT> ; private static Ultrasonic m_firstSensor = null ; private static boolean m_automaticEnabled = false ; private DigitalInput m_echoChannel = null ; private DigitalOutput m_pingChannel = null ; private boolean m_allocatedChannels ; private boolean m_enabled = false ; private Counter m_counter = null ; private Ultrasonic m_nextSensor = null ; private static Thread m_task = null ; private Unit m_units ; private class UltrasonicChecker extends Thread { public synchronized void run ( ) { Ultrasonic u = null ; while ( m_automaticEnabled ) { if ( u == null ) { u = m_firstSensor ; } if ( u == null ) { return ; } if ( u . isEnabled ( ) ) { u . m_pingChannel . pulse ( kPingTime ) ; } u = u . m_nextSensor ; Timer . delay ( <NUM_LIT> ) ; } } } private synchronized void initialize ( ) { if ( m_task == null ) { m_task = new UltrasonicChecker ( ) ; } boolean originalMode = m_automaticEnabled ; setAutomaticMode ( false ) ; m_nextSensor = m_firstSensor ; m_firstSensor = this ; m_counter = new Counter ( m_echoChannel ) ; m_counter . setMaxPeriod ( <NUM_LIT:1.0> ) ; m_counter . setSemiPeriodMode ( true ) ; m_counter . reset ( ) ; m_counter . start ( ) ; m_enabled = true ; setAutomaticMode ( originalMode ) ; } public Ultrasonic ( final int pingChannel , final int echoChannel , Unit units ) { m_pingChannel = new DigitalOutput ( pingChannel ) ; m_echoChannel = new DigitalInput ( echoChannel ) ; m_allocatedChannels = true ; m_units = units ; initialize ( ) ; } public Ultrasonic ( final int pingChannel , final int echoChannel ) { this ( pingChannel , echoChannel , Unit . kInches ) ; } public Ultrasonic ( DigitalOutput pingChannel , DigitalInput echoChannel , Unit units ) { if ( pingChannel == null || echoChannel == null ) { throw new NullPointerException ( "<STR_LIT>" ) ; } m_allocatedChannels = false ; m_pingChannel = pingChannel ; m_echoChannel = echoChannel ; m_units = units ; initialize ( ) ; } public Ultrasonic ( DigitalOutput pingChannel , DigitalInput echoChannel ) { this ( pingChannel , echoChannel , Unit . kInches ) ; } public Ultrasonic ( final int pingSlot , final int pingChannel , final int echoSlot , final int echoChannel , Unit units ) { m_pingChannel = new DigitalOutput ( pingSlot , pingChannel ) ; m_echoChannel = new DigitalInput ( echoSlot , echoChannel ) ; m_allocatedChannels = true ; m_units = units ; initialize ( ) ; } public Ultrasonic ( final int pingSlot , final int pingChannel , final int echoSlot , final int echoChannel ) { this ( pingSlot , pingChannel , echoSlot , echoChannel , Unit . kInches ) ; } protected synchronized void free ( ) { boolean wasAutomaticMode = m_automaticEnabled ; setAutomaticMode ( false ) ; if ( m_allocatedChannels ) { if ( m_pingChannel != null ) { m_pingChannel . free ( ) ; } if ( m_echoChannel != null ) { m_echoChannel . free ( ) ; } } if ( m_counter != null ) { m_counter . free ( ) ; m_counter = null ; } m_pingChannel = null ; m_echoChannel = null ; if ( this == m_firstSensor ) { m_firstSensor = m_nextSensor ; if ( m_firstSensor == null ) { setAutomaticMode ( false ) ; } } else { for ( Ultrasonic s = m_firstSensor ; s != null ; s = s . m_nextSensor ) { if ( this == s . m_nextSensor ) { s . m_nextSensor = s . m_nextSensor . m_nextSensor ; break ; } } } if ( m_firstSensor != null && wasAutomaticMode ) { setAutomaticMode ( true ) ; } } public void setAutomaticMode ( boolean enabling ) { if ( enabling == m_automaticEnabled ) { return ; } m_automaticEnabled = enabling ; if ( enabling ) { for ( Ultrasonic u = m_firstSensor ; u != null ; u = u . m_nextSensor ) { u . m_counter . reset ( ) ; } m_task . start ( ) ; } else { while ( m_task . isAlive ( ) ) { Timer . delay ( <NUM_LIT> ) ; } for ( Ultrasonic u = m_firstSensor ; u != null ; u = u . m_nextSensor ) { u . m_counter . reset ( ) ; } } } public void ping ( ) { setAutomaticMode ( false ) ; m_counter . reset ( ) ; m_pingChannel . pulse ( kPingTime ) ; } public boolean isRangeValid ( ) { return m_counter . get ( ) > <NUM_LIT:1> ; } public double getRangeInches ( ) { if ( isRangeValid ( ) ) { return m_counter . getPeriod ( ) * kSpeedOfSoundInchesPerSec / <NUM_LIT> ; } else { return <NUM_LIT:0> ; } } public double getRangeMM ( ) { return getRangeInches ( ) * <NUM_LIT> ; } public double pidGet ( ) { switch ( m_units . value ) { case Unit . kInches_val : return getRangeInches ( ) ; case Unit . kMillimeters_val : return getRangeMM ( ) ; default : return <NUM_LIT:0.0> ; } } public void setDistanceUnits ( Unit units ) { m_units = units ; } public Unit getDistanceUnits ( ) { return m_units ; } public boolean isEnabled ( ) { return m_enabled ; } public void setEnabled ( boolean enable ) { m_enabled = enable ; } } </s>
<s> package edu . wpi . first . wpilibj ; public class SafePWM extends PWM implements MotorSafety { private MotorSafetyHelper m_safetyHelper ; void initSafePWM ( ) { m_safetyHelper = new MotorSafetyHelper ( this ) ; m_safetyHelper . setExpiration ( <NUM_LIT:0.0> ) ; m_safetyHelper . setSafetyEnabled ( false ) ; } public SafePWM ( final int channel ) { super ( channel ) ; initSafePWM ( ) ; } public SafePWM ( final int slot , final int channel ) { super ( slot , channel ) ; initSafePWM ( ) ; } public void setExpiration ( double timeout ) { m_safetyHelper . setExpiration ( timeout ) ; } public double getExpiration ( ) { return m_safetyHelper . getExpiration ( ) ; } public boolean isAlive ( ) { return m_safetyHelper . isAlive ( ) ; } public void stopMotor ( ) { disable ( ) ; } public boolean isSafetyEnabled ( ) { return m_safetyHelper . isSafetyEnabled ( ) ; } public void Feed ( ) { m_safetyHelper . feed ( ) ; } public void setSafetyEnabled ( boolean enabled ) { m_safetyHelper . setSafetyEnabled ( enabled ) ; } public void disable ( ) { setRaw ( kPwmDisabled ) ; } } </s>
<s> package edu . wpi . first . wpilibj ; public abstract class GenericHID { public static class Hand { public final int value ; static final int kLeft_val = <NUM_LIT:0> ; static final int kRight_val = <NUM_LIT:1> ; public static final Hand kLeft = new Hand ( kLeft_val ) ; public static final Hand kRight = new Hand ( kRight_val ) ; private Hand ( int value ) { this . value = value ; } } public final double getX ( ) { return getX ( Hand . kRight ) ; } public abstract double getX ( Hand hand ) ; public final double getY ( ) { return getY ( Hand . kRight ) ; } public abstract double getY ( Hand hand ) ; public final double getZ ( ) { return getZ ( Hand . kRight ) ; } public abstract double getZ ( Hand hand ) ; public abstract double getTwist ( ) ; public abstract double getThrottle ( ) ; public abstract double getRawAxis ( int which ) ; public final boolean getTrigger ( ) { return getTrigger ( Hand . kRight ) ; } public abstract boolean getTrigger ( Hand hand ) ; public final boolean getTop ( ) { return getTop ( Hand . kRight ) ; } public abstract boolean getTop ( Hand hand ) ; public final boolean getBumper ( ) { return getBumper ( Hand . kRight ) ; } public abstract boolean getBumper ( Hand hand ) ; public abstract boolean getRawButton ( int button ) ; } </s>
<s> package edu . wpi . first . wpilibj ; import com . sun . squawk . util . MathUtils ; import edu . wpi . first . wpilibj . parsing . IInputOutput ; public class Joystick extends GenericHID implements IInputOutput { static final byte kDefaultXAxis = <NUM_LIT:1> ; static final byte kDefaultYAxis = <NUM_LIT:2> ; static final byte kDefaultZAxis = <NUM_LIT:3> ; static final byte kDefaultTwistAxis = <NUM_LIT:3> ; static final byte kDefaultThrottleAxis = <NUM_LIT:4> ; static final int kDefaultTriggerButton = <NUM_LIT:1> ; static final int kDefaultTopButton = <NUM_LIT:2> ; public static class AxisType { public final int value ; static final int kX_val = <NUM_LIT:0> ; static final int kY_val = <NUM_LIT:1> ; static final int kZ_val = <NUM_LIT:2> ; static final int kTwist_val = <NUM_LIT:3> ; static final int kThrottle_val = <NUM_LIT:4> ; static final int kNumAxis_val = <NUM_LIT:5> ; public static final AxisType kX = new AxisType ( kX_val ) ; public static final AxisType kY = new AxisType ( kY_val ) ; public static final AxisType kZ = new AxisType ( kZ_val ) ; public static final AxisType kTwist = new AxisType ( kTwist_val ) ; public static final AxisType kThrottle = new AxisType ( kThrottle_val ) ; public static final AxisType kNumAxis = new AxisType ( kNumAxis_val ) ; private AxisType ( int value ) { this . value = value ; } } public static class ButtonType { public final int value ; static final int kTrigger_val = <NUM_LIT:0> ; static final int kTop_val = <NUM_LIT:1> ; static final int kNumButton_val = <NUM_LIT:2> ; public static final ButtonType kTrigger = new ButtonType ( ( kTrigger_val ) ) ; public static final ButtonType kTop = new ButtonType ( kTop_val ) ; public static final ButtonType kNumButton = new ButtonType ( ( kNumButton_val ) ) ; private ButtonType ( int value ) { this . value = value ; } } private DriverStation m_ds ; private final int m_port ; private final byte [ ] m_axes ; private final byte [ ] m_buttons ; public Joystick ( final int port ) { this ( port , AxisType . kNumAxis . value , ButtonType . kNumButton . value ) ; m_axes [ AxisType . kX . value ] = kDefaultXAxis ; m_axes [ AxisType . kY . value ] = kDefaultYAxis ; m_axes [ AxisType . kZ . value ] = kDefaultZAxis ; m_axes [ AxisType . kTwist . value ] = kDefaultTwistAxis ; m_axes [ AxisType . kThrottle . value ] = kDefaultThrottleAxis ; m_buttons [ ButtonType . kTrigger . value ] = kDefaultTriggerButton ; m_buttons [ ButtonType . kTop . value ] = kDefaultTopButton ; } protected Joystick ( int port , int numAxisTypes , int numButtonTypes ) { m_ds = DriverStation . getInstance ( ) ; m_axes = new byte [ numAxisTypes ] ; m_buttons = new byte [ numButtonTypes ] ; m_port = port ; } public double getX ( Hand hand ) { return getRawAxis ( m_axes [ AxisType . kX . value ] ) ; } public double getY ( Hand hand ) { return getRawAxis ( m_axes [ AxisType . kY . value ] ) ; } public double getZ ( Hand hand ) { return getRawAxis ( m_axes [ AxisType . kZ . value ] ) ; } public double getTwist ( ) { return getRawAxis ( m_axes [ AxisType . kTwist . value ] ) ; } public double getThrottle ( ) { return getRawAxis ( m_axes [ AxisType . kThrottle . value ] ) ; } public double getRawAxis ( final int axis ) { return m_ds . getStickAxis ( m_port , axis ) ; } public double getAxis ( final AxisType axis ) { switch ( axis . value ) { case AxisType . kX_val : return getX ( ) ; case AxisType . kY_val : return getY ( ) ; case AxisType . kZ_val : return getZ ( ) ; case AxisType . kTwist_val : return getTwist ( ) ; case AxisType . kThrottle_val : return getThrottle ( ) ; default : return <NUM_LIT:0.0> ; } } public boolean getTrigger ( Hand hand ) { return getRawButton ( m_buttons [ ButtonType . kTrigger . value ] ) ; } public boolean getTop ( Hand hand ) { return getRawButton ( m_buttons [ ButtonType . kTop . value ] ) ; } public boolean getBumper ( Hand hand ) { return false ; } public boolean getRawButton ( final int button ) { return ( ( <NUM_LIT> << ( button - <NUM_LIT:1> ) ) & m_ds . getStickButtons ( m_port ) ) != <NUM_LIT:0> ; } public boolean getButton ( ButtonType button ) { switch ( button . value ) { case ButtonType . kTrigger_val : return getTrigger ( ) ; case ButtonType . kTop_val : return getTop ( ) ; default : return false ; } } public double getMagnitude ( ) { return Math . sqrt ( MathUtils . pow ( getX ( ) , <NUM_LIT:2> ) + MathUtils . pow ( getY ( ) , <NUM_LIT:2> ) ) ; } public double getDirectionRadians ( ) { return MathUtils . atan2 ( getX ( ) , - getY ( ) ) ; } public double getDirectionDegrees ( ) { return Math . toDegrees ( getDirectionRadians ( ) ) ; } public int getAxisChannel ( AxisType axis ) { return m_axes [ axis . value ] ; } public void setAxisChannel ( AxisType axis , int channel ) { m_axes [ axis . value ] = ( byte ) channel ; } } </s>
<s> package edu . wpi . first . wpilibj ; import com . sun . cldc . jna . Pointer ; import com . sun . cldc . jna . Structure ; import edu . wpi . first . wpilibj . communication . FRCControl ; import edu . wpi . first . wpilibj . parsing . IInputOutput ; import edu . wpi . first . wpilibj . util . BoundaryException ; public class DriverStationEnhancedIO implements IInputOutput { static class output_t extends Structure { short digital = <NUM_LIT:0> ; short digital_oe = <NUM_LIT:0> ; short digital_pe = <NUM_LIT:0> ; short [ ] pwm_compare = new short [ <NUM_LIT:4> ] ; short [ ] pwm_period = new short [ <NUM_LIT:2> ] ; byte [ ] dac = new byte [ <NUM_LIT:2> ] ; byte leds = <NUM_LIT:0> ; private byte enables = <NUM_LIT:0> ; byte pwm_enable = <NUM_LIT:0> ; byte comparator_enable = <NUM_LIT:0> ; byte quad_index_enable = <NUM_LIT:0> ; byte fixed_digital_out = <NUM_LIT:0> ; final static int size = <NUM_LIT> ; output_t ( Pointer backingMemory ) { useMemory ( backingMemory ) ; } public void setEnables ( byte enablesByte ) { enables = enablesByte ; pwm_enable = ( byte ) ( ( enablesByte & ( byte ) <NUM_LIT> ) > > <NUM_LIT:4> ) ; comparator_enable = ( byte ) ( ( enablesByte & ( byte ) <NUM_LIT> ) > > <NUM_LIT:2> ) ; quad_index_enable = ( byte ) ( ( enablesByte & ( byte ) <NUM_LIT> ) ) ; } public byte getEnables ( ) { enables = ( byte ) ( ( ( pwm_enable << <NUM_LIT:4> ) & ( byte ) <NUM_LIT> ) | ( ( comparator_enable << <NUM_LIT:2> ) & ( byte ) <NUM_LIT> ) | ( ( quad_index_enable ) & ( byte ) <NUM_LIT> ) ) ; return enables ; } public void read ( ) { digital = backingNativeMemory . getShort ( <NUM_LIT:0> ) ; digital_oe = backingNativeMemory . getShort ( <NUM_LIT:2> ) ; digital_pe = backingNativeMemory . getShort ( <NUM_LIT:4> ) ; backingNativeMemory . getShorts ( <NUM_LIT:6> , pwm_compare , <NUM_LIT:0> , pwm_compare . length ) ; backingNativeMemory . getShorts ( <NUM_LIT> , pwm_period , <NUM_LIT:0> , pwm_period . length ) ; backingNativeMemory . getBytes ( <NUM_LIT> , dac , <NUM_LIT:0> , dac . length ) ; leds = backingNativeMemory . getByte ( <NUM_LIT:20> ) ; setEnables ( backingNativeMemory . getByte ( <NUM_LIT> ) ) ; fixed_digital_out = backingNativeMemory . getByte ( <NUM_LIT> ) ; } public void write ( ) { backingNativeMemory . setShort ( <NUM_LIT:0> , digital ) ; backingNativeMemory . setShort ( <NUM_LIT:2> , digital_oe ) ; backingNativeMemory . setShort ( <NUM_LIT:4> , digital_pe ) ; backingNativeMemory . setShorts ( <NUM_LIT:6> , pwm_compare , <NUM_LIT:0> , pwm_compare . length ) ; backingNativeMemory . setShorts ( <NUM_LIT> , pwm_period , <NUM_LIT:0> , pwm_period . length ) ; backingNativeMemory . setBytes ( <NUM_LIT> , dac , <NUM_LIT:0> , dac . length ) ; backingNativeMemory . setByte ( <NUM_LIT:20> , leds ) ; backingNativeMemory . setByte ( <NUM_LIT> , getEnables ( ) ) ; backingNativeMemory . setByte ( <NUM_LIT> , fixed_digital_out ) ; } public int size ( ) { return size ; } } static class input_t extends Structure { byte api_version ; byte fw_version ; short [ ] analog = new short [ <NUM_LIT:8> ] ; short digital ; short [ ] accel = new short [ <NUM_LIT:3> ] ; short [ ] quad = new short [ <NUM_LIT:2> ] ; byte buttons ; byte capsense_slider ; byte capsense_proximity ; final static int size = <NUM_LIT> ; input_t ( Pointer backingMemory ) { useMemory ( backingMemory ) ; } public void read ( ) { api_version = backingNativeMemory . getByte ( <NUM_LIT:0> ) ; fw_version = backingNativeMemory . getByte ( <NUM_LIT:1> ) ; backingNativeMemory . getShorts ( <NUM_LIT:2> , analog , <NUM_LIT:0> , analog . length ) ; digital = backingNativeMemory . getShort ( <NUM_LIT> ) ; backingNativeMemory . getShorts ( <NUM_LIT:20> , accel , <NUM_LIT:0> , accel . length ) ; backingNativeMemory . getShorts ( <NUM_LIT> , quad , <NUM_LIT:0> , quad . length ) ; buttons = backingNativeMemory . getByte ( <NUM_LIT:30> ) ; capsense_slider = backingNativeMemory . getByte ( <NUM_LIT:31> ) ; capsense_proximity = backingNativeMemory . getByte ( <NUM_LIT:32> ) ; } public void write ( ) { backingNativeMemory . setByte ( <NUM_LIT:0> , api_version ) ; backingNativeMemory . setByte ( <NUM_LIT:1> , fw_version ) ; backingNativeMemory . setShorts ( <NUM_LIT:2> , analog , <NUM_LIT:0> , analog . length ) ; backingNativeMemory . setShort ( <NUM_LIT> , digital ) ; backingNativeMemory . setShorts ( <NUM_LIT:20> , accel , <NUM_LIT:0> , accel . length ) ; backingNativeMemory . setShorts ( <NUM_LIT> , quad , <NUM_LIT:0> , quad . length ) ; backingNativeMemory . setByte ( <NUM_LIT:30> , buttons ) ; backingNativeMemory . setByte ( <NUM_LIT:31> , capsense_slider ) ; backingNativeMemory . setByte ( <NUM_LIT:32> , capsense_proximity ) ; } public int size ( ) { return size ; } } class status_block_t extends FRCControl . DynamicControlData { byte size = <NUM_LIT> ; byte id = kOutputBlockID ; output_t data ; byte flags ; { allocateMemory ( ) ; data = new output_t ( new Pointer ( backingNativeMemory . address ( ) . toUWord ( ) . toPrimitive ( ) + <NUM_LIT:2> , output_t . size ) ) ; } public void read ( ) { size = backingNativeMemory . getByte ( <NUM_LIT:0> ) ; id = backingNativeMemory . getByte ( <NUM_LIT:1> ) ; data . read ( ) ; flags = backingNativeMemory . getByte ( <NUM_LIT> ) ; } public void write ( ) { backingNativeMemory . setByte ( <NUM_LIT:0> , size ) ; backingNativeMemory . setByte ( <NUM_LIT:1> , id ) ; data . write ( ) ; backingNativeMemory . setByte ( <NUM_LIT> , flags ) ; } public int size ( ) { return <NUM_LIT> ; } public void copy ( status_block_t dest ) { write ( ) ; Pointer . copyBytes ( backingNativeMemory , <NUM_LIT:0> , dest . backingNativeMemory , <NUM_LIT:0> , size ( ) ) ; dest . read ( ) ; } } class control_block_t extends FRCControl . DynamicControlData { byte size = <NUM_LIT> ; byte id = kInputBlockID ; input_t data ; { allocateMemory ( ) ; data = new input_t ( new Pointer ( backingNativeMemory . address ( ) . toUWord ( ) . toPrimitive ( ) + <NUM_LIT:2> , input_t . size ) ) ; } public void read ( ) { size = backingNativeMemory . getByte ( <NUM_LIT:0> ) ; id = backingNativeMemory . getByte ( <NUM_LIT:1> ) ; data . read ( ) ; } public void write ( ) { backingNativeMemory . setByte ( <NUM_LIT:0> , size ) ; backingNativeMemory . setByte ( <NUM_LIT:1> , id ) ; data . write ( ) ; } public int size ( ) { return <NUM_LIT> ; } public void copy ( control_block_t dest ) { write ( ) ; Pointer . copyBytes ( backingNativeMemory , <NUM_LIT:0> , dest . backingNativeMemory , <NUM_LIT:0> , size ( ) ) ; dest . read ( ) ; } } public static class EnhancedIOException extends Exception { public EnhancedIOException ( String msg ) { super ( msg ) ; } } public static final double kAnalogInputResolution = ( ( double ) ( ( <NUM_LIT:1> << <NUM_LIT> ) - <NUM_LIT:1> ) ) ; public static final double kAnalogInputReference = <NUM_LIT> ; public static final double kAnalogOutputResolution = ( ( double ) ( ( <NUM_LIT:1> << <NUM_LIT:8> ) - <NUM_LIT:1> ) ) ; public static final double kAnalogOutputReference = <NUM_LIT> ; public static final double kAccelOffset = <NUM_LIT> ; public static final double kAccelScale = <NUM_LIT> ; public static final int kSupportedAPIVersion = <NUM_LIT:1> ; control_block_t m_inputData ; status_block_t m_outputData ; final Object m_inputDataSemaphore ; final Object m_outputDataSemaphore ; boolean m_inputValid ; boolean m_outputValid ; boolean m_configChanged ; boolean m_requestEnhancedEnable ; short [ ] m_encoderOffsets = new short [ <NUM_LIT:2> ] ; public static class tDigitalConfig { public final int value ; static final int kUnknown_val = <NUM_LIT:0> ; static final int kInputFloating_val = <NUM_LIT:1> ; static final int kInputPullUp_val = <NUM_LIT:2> ; static final int kInputPullDown_val = <NUM_LIT:3> ; static final int kOutput_val = <NUM_LIT:4> ; static final int kPWM_val = <NUM_LIT:5> ; static final int kAnalogComparator_val = <NUM_LIT:6> ; public static final tDigitalConfig kUnknown = new tDigitalConfig ( kUnknown_val ) ; public static final tDigitalConfig kInputFloating = new tDigitalConfig ( kInputFloating_val ) ; public static final tDigitalConfig kInputPullUp = new tDigitalConfig ( kInputPullUp_val ) ; public static final tDigitalConfig kInputPullDown = new tDigitalConfig ( kInputPullDown_val ) ; public static final tDigitalConfig kOutput = new tDigitalConfig ( ( kOutput_val ) ) ; public static final tDigitalConfig kPWM = new tDigitalConfig ( ( kPWM_val ) ) ; public static final tDigitalConfig kAnalogComparator = new tDigitalConfig ( ( kAnalogComparator_val ) ) ; private tDigitalConfig ( int value ) { this . value = value ; } } public static class tAccelChannel { public final int value ; static final int kAccelX_val = <NUM_LIT:0> ; static final int kAccelY_val = <NUM_LIT:1> ; static final int kAccelZ_val = <NUM_LIT:2> ; public static final tAccelChannel kAccelX = new tAccelChannel ( kAccelX_val ) ; public static final tAccelChannel kAccelY = new tAccelChannel ( kAccelY_val ) ; public static final tAccelChannel kAccelZ = new tAccelChannel ( kAccelZ_val ) ; private tAccelChannel ( int value ) { this . value = value ; } } public static class tPWMPeriodChannels { public final int value ; static final int kPWMChannels1and2_val = <NUM_LIT:0> ; static final int kPWMChannels3and4_val = <NUM_LIT:1> ; public static final tPWMPeriodChannels kPWMChannels1and2 = new tPWMPeriodChannels ( kPWMChannels1and2_val ) ; public static final tPWMPeriodChannels kPWMChannels3and4 = new tPWMPeriodChannels ( kPWMChannels3and4_val ) ; private tPWMPeriodChannels ( int value ) { this . value = value ; } } static final byte kInputBlockID = <NUM_LIT> , kOutputBlockID = <NUM_LIT> ; static final int kStatusValid = <NUM_LIT> , kStatusConfigChanged = <NUM_LIT> , kForceEnhancedMode = <NUM_LIT> ; DriverStationEnhancedIO ( ) { m_inputValid = false ; m_outputValid = false ; m_configChanged = false ; m_requestEnhancedEnable = false ; m_inputData = new control_block_t ( ) ; m_outputData = new status_block_t ( ) ; m_outputData . size = ( byte ) ( m_outputData . size ( ) - <NUM_LIT:1> ) ; m_outputData . id = kOutputBlockID ; m_outputData . data . fixed_digital_out = <NUM_LIT> ; m_inputDataSemaphore = new Object ( ) ; m_outputDataSemaphore = new Object ( ) ; m_encoderOffsets [ <NUM_LIT:0> ] = <NUM_LIT:0> ; m_encoderOffsets [ <NUM_LIT:1> ] = <NUM_LIT:0> ; } status_block_t tempOutputData = new status_block_t ( ) ; control_block_t tempInputData = new control_block_t ( ) ; void updateData ( ) { int retVal ; synchronized ( m_outputDataSemaphore ) { if ( m_outputValid || m_configChanged || m_requestEnhancedEnable ) { m_outputData . flags = kStatusValid ; if ( m_requestEnhancedEnable ) { m_outputData . flags |= kForceEnhancedMode ; } if ( m_configChanged ) { if ( ! m_outputValid ) { m_outputData . flags |= kForceEnhancedMode ; } m_outputData . flags |= kStatusConfigChanged ; } FRCControl . overrideIOConfig ( m_outputData , <NUM_LIT:5> ) ; } retVal = FRCControl . getDynamicControlData ( kOutputBlockID , tempOutputData , tempOutputData . size ( ) , <NUM_LIT:5> ) ; if ( retVal == <NUM_LIT:0> ) { if ( m_outputValid ) { if ( m_configChanged ) { if ( isConfigEqual ( tempOutputData , m_outputData ) ) { m_configChanged = false ; } } else { { mergeConfigIntoOutput ( tempOutputData , m_outputData ) ; } } } else { mergeConfigIntoOutput ( tempOutputData , m_outputData ) ; } m_requestEnhancedEnable = false ; m_outputValid = true ; } else { m_outputValid = false ; m_inputValid = false ; } } synchronized ( m_inputDataSemaphore ) { retVal = FRCControl . getDynamicControlData ( kInputBlockID , tempInputData , tempInputData . size ( ) , <NUM_LIT:5> ) ; if ( retVal == <NUM_LIT:0> && tempInputData . data . api_version == kSupportedAPIVersion ) { tempInputData . copy ( m_inputData ) ; m_inputValid = true ; } else { m_outputValid = false ; m_inputValid = false ; } } } void mergeConfigIntoOutput ( status_block_t dsOutputBlock , status_block_t localCache ) { localCache . data . digital = ( short ) ( ( localCache . data . digital & dsOutputBlock . data . digital_oe ) | ( dsOutputBlock . data . digital & ~ dsOutputBlock . data . digital_oe ) ) ; localCache . data . digital_oe = dsOutputBlock . data . digital_oe ; localCache . data . digital_pe = dsOutputBlock . data . digital_pe ; localCache . data . pwm_period [ <NUM_LIT:0> ] = dsOutputBlock . data . pwm_period [ <NUM_LIT:0> ] ; localCache . data . pwm_period [ <NUM_LIT:1> ] = dsOutputBlock . data . pwm_period [ <NUM_LIT:1> ] ; localCache . data . setEnables ( dsOutputBlock . data . getEnables ( ) ) ; } boolean isConfigEqual ( status_block_t dsOutputBlock , status_block_t localCache ) { if ( localCache . data . digital_oe != dsOutputBlock . data . digital_oe ) { return false ; } if ( ( localCache . data . digital & ~ dsOutputBlock . data . digital ) != ( dsOutputBlock . data . digital & ~ dsOutputBlock . data . digital ) ) { return false ; } if ( localCache . data . digital_pe != dsOutputBlock . data . digital_pe ) { return false ; } if ( localCache . data . pwm_period [ <NUM_LIT:0> ] != dsOutputBlock . data . pwm_period [ <NUM_LIT:0> ] ) { return false ; } if ( localCache . data . pwm_period [ <NUM_LIT:1> ] != dsOutputBlock . data . pwm_period [ <NUM_LIT:1> ] ) { return false ; } if ( localCache . data . getEnables ( ) != dsOutputBlock . data . getEnables ( ) ) { return false ; } return true ; } public double getAcceleration ( tAccelChannel channel ) throws EnhancedIOException { if ( ! m_inputValid ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } synchronized ( m_inputDataSemaphore ) { return ( m_inputData . data . accel [ channel . value ] - kAccelOffset ) / kAccelScale ; } } public double getAnalogIn ( int channel ) throws EnhancedIOException { return getAnalogInRatio ( channel ) * kAnalogInputReference ; } public double getAnalogInRatio ( int channel ) throws EnhancedIOException { BoundaryException . assertWithinBounds ( channel , <NUM_LIT:1> , <NUM_LIT:8> ) ; if ( ! m_inputValid ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } synchronized ( m_inputDataSemaphore ) { return m_inputData . data . analog [ channel - <NUM_LIT:1> ] / kAnalogInputResolution ; } } public double getAnalogOut ( int channel ) throws EnhancedIOException { BoundaryException . assertWithinBounds ( channel , <NUM_LIT:1> , <NUM_LIT:2> ) ; if ( ! m_outputValid ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } synchronized ( m_outputDataSemaphore ) { int tempData = m_outputData . data . dac [ channel - <NUM_LIT:1> ] ; tempData = tempData < <NUM_LIT:0> ? tempData + <NUM_LIT> : tempData ; return tempData * kAnalogOutputReference / kAnalogOutputResolution ; } } public void setAnalogOut ( int channel , double value ) throws EnhancedIOException { BoundaryException . assertWithinBounds ( channel , <NUM_LIT:1> , <NUM_LIT:2> ) ; if ( ! m_outputValid ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } if ( value < <NUM_LIT:0.0> ) { value = <NUM_LIT:0.0> ; } if ( value > kAnalogOutputReference ) { value = kAnalogOutputReference ; } if ( value > kAnalogOutputReference ) { value = kAnalogOutputReference ; } synchronized ( m_outputDataSemaphore ) { m_outputData . data . dac [ channel - <NUM_LIT:1> ] = ( byte ) ( value / kAnalogOutputReference * kAnalogOutputResolution ) ; } } public boolean getButton ( int channel ) throws EnhancedIOException { BoundaryException . assertWithinBounds ( channel , <NUM_LIT:1> , <NUM_LIT:6> ) ; return ( ( getButtons ( ) > > ( channel - <NUM_LIT:1> ) ) & <NUM_LIT:1> ) != <NUM_LIT:0> ; } public byte getButtons ( ) throws EnhancedIOException { if ( ! m_inputValid ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } synchronized ( m_inputDataSemaphore ) { return m_inputData . data . buttons ; } } public void setLED ( int channel , boolean value ) throws EnhancedIOException { BoundaryException . assertWithinBounds ( channel , <NUM_LIT:1> , <NUM_LIT:8> ) ; if ( ! m_outputValid ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } byte leds ; synchronized ( m_outputDataSemaphore ) { leds = m_outputData . data . leds ; leds &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ; if ( value ) { leds |= <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ; } m_outputData . data . leds = leds ; } } public void setLEDs ( byte value ) throws EnhancedIOException { if ( ! m_outputValid ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } synchronized ( m_outputDataSemaphore ) { m_outputData . data . leds = value ; } } public boolean getDigital ( int channel ) throws EnhancedIOException { BoundaryException . assertWithinBounds ( channel , <NUM_LIT:1> , <NUM_LIT:16> ) ; return ( ( getDigitals ( ) > > ( channel - <NUM_LIT:1> ) ) & <NUM_LIT:1> ) != <NUM_LIT:0> ; } public short getDigitals ( ) throws EnhancedIOException { if ( ! m_inputValid ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } synchronized ( m_inputDataSemaphore ) { return m_inputData . data . digital ; } } public void setDigitalOutput ( int channel , boolean value ) throws EnhancedIOException { BoundaryException . assertWithinBounds ( channel , <NUM_LIT:1> , <NUM_LIT:16> ) ; if ( ! m_outputValid ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } short digital ; synchronized ( m_outputDataSemaphore ) { if ( ( m_outputData . data . digital_oe & ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ) != <NUM_LIT:0> ) { digital = m_outputData . data . digital ; digital &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ; if ( value ) { digital |= <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ; } m_outputData . data . digital = digital ; } else { System . err . println ( "<STR_LIT>" ) ; } } } public tDigitalConfig getDigitalConfig ( int channel ) throws EnhancedIOException { BoundaryException . assertWithinBounds ( channel , <NUM_LIT:1> , <NUM_LIT:16> ) ; if ( ! m_outputValid ) { m_requestEnhancedEnable = true ; throw new EnhancedIOException ( "<STR_LIT>" ) ; } synchronized ( m_outputDataSemaphore ) { if ( ( channel >= <NUM_LIT:1> ) && ( channel <= <NUM_LIT:4> ) ) { if ( ( m_outputData . data . pwm_enable & ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ) != <NUM_LIT:0> ) { return tDigitalConfig . kPWM ; } } if ( ( channel >= <NUM_LIT:15> ) && ( channel <= <NUM_LIT:16> ) ) { if ( ( m_outputData . data . comparator_enable & ( <NUM_LIT:1> << ( channel - <NUM_LIT:15> ) ) ) != <NUM_LIT:0> ) { return tDigitalConfig . kAnalogComparator ; } } if ( ( m_outputData . data . digital_oe & ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ) != <NUM_LIT:0> ) { return tDigitalConfig . kOutput ; } if ( ( m_outputData . data . digital_pe & ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ) == <NUM_LIT:0> ) { return tDigitalConfig . kInputFloating ; } if ( ( m_outputData . data . digital & ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ) != <NUM_LIT:0> ) { return tDigitalConfig . kInputPullUp ; } else { return tDigitalConfig . kInputPullDown ; } } } public void setDigitalConfig ( int channel , tDigitalConfig config ) throws EnhancedIOException { BoundaryException . assertWithinBounds ( channel , <NUM_LIT:1> , <NUM_LIT:16> ) ; if ( config == tDigitalConfig . kPWM && ( ( channel > <NUM_LIT:4> ) || ( channel < <NUM_LIT:1> ) ) ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } if ( config == tDigitalConfig . kAnalogComparator && ( ( channel < <NUM_LIT:15> ) || ( channel > <NUM_LIT:16> ) ) ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } synchronized ( m_outputDataSemaphore ) { m_configChanged = true ; if ( ( channel >= <NUM_LIT:1> ) && ( channel <= <NUM_LIT:4> ) ) { if ( config == tDigitalConfig . kPWM ) { m_outputData . data . pwm_enable |= <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ; m_outputData . data . digital &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ; m_outputData . data . digital_oe |= <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ; m_outputData . data . digital_pe &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ; return ; } else { m_outputData . data . pwm_enable &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ; } } else if ( ( channel >= <NUM_LIT:15> ) && ( channel <= <NUM_LIT:16> ) ) { if ( config == tDigitalConfig . kAnalogComparator ) { m_outputData . data . comparator_enable |= <NUM_LIT:1> << ( channel - <NUM_LIT:15> ) ; m_outputData . data . digital &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ; m_outputData . data . digital_oe &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ; m_outputData . data . digital_pe &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ; return ; } else { m_outputData . data . comparator_enable &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:15> ) ) ; } } if ( config == tDigitalConfig . kInputFloating ) { m_outputData . data . digital &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ; m_outputData . data . digital_oe &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ; m_outputData . data . digital_pe &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ; } else if ( config == tDigitalConfig . kInputPullUp ) { m_outputData . data . digital |= <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ; m_outputData . data . digital_oe &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ; m_outputData . data . digital_pe |= <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ; } else if ( config == tDigitalConfig . kInputPullDown ) { m_outputData . data . digital &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ; m_outputData . data . digital_oe &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ; m_outputData . data . digital_pe |= <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ; } else if ( config == tDigitalConfig . kOutput ) { m_outputData . data . digital_oe |= <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ; m_outputData . data . digital_pe &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ; } else { } } } public double getPWMPeriod ( tPWMPeriodChannels channels ) throws EnhancedIOException { if ( ! m_outputValid ) { m_requestEnhancedEnable = true ; throw new EnhancedIOException ( "<STR_LIT>" ) ; } synchronized ( m_outputDataSemaphore ) { int tempData = m_outputData . data . pwm_period [ channels . value ] & <NUM_LIT> ; return tempData / <NUM_LIT> ; } } public void setPWMPeriod ( tPWMPeriodChannels channels , double period ) throws EnhancedIOException { double ticks = period * <NUM_LIT> ; if ( ticks > <NUM_LIT> ) { ticks = <NUM_LIT> ; throw new EnhancedIOException ( "<STR_LIT>" ) ; } else if ( ticks < <NUM_LIT:0.0> ) { ticks = <NUM_LIT:0.0> ; } double [ ] dutyCycles = new double [ <NUM_LIT:2> ] ; dutyCycles [ <NUM_LIT:0> ] = getPWMOutput ( ( channels . value << <NUM_LIT:1> ) + <NUM_LIT:1> ) ; dutyCycles [ <NUM_LIT:1> ] = getPWMOutput ( ( channels . value << <NUM_LIT:1> ) + <NUM_LIT:2> ) ; synchronized ( m_outputDataSemaphore ) { m_outputData . data . pwm_period [ channels . value ] = ( short ) ticks ; m_configChanged = true ; } setPWMOutput ( ( channels . value << <NUM_LIT:1> ) + <NUM_LIT:1> , dutyCycles [ <NUM_LIT:0> ] ) ; setPWMOutput ( ( channels . value << <NUM_LIT:1> ) + <NUM_LIT:2> , dutyCycles [ <NUM_LIT:1> ] ) ; } public boolean getFixedDigitalOutput ( int channel ) throws EnhancedIOException { BoundaryException . assertWithinBounds ( channel , <NUM_LIT:1> , <NUM_LIT:2> ) ; if ( ! m_outputValid ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } synchronized ( m_outputDataSemaphore ) { return ( ( m_outputData . data . fixed_digital_out > > ( channel - <NUM_LIT:1> ) ) & <NUM_LIT:1> ) != <NUM_LIT:0> ; } } public void setFixedDigitalOutput ( int channel , boolean value ) throws EnhancedIOException { BoundaryException . assertWithinBounds ( channel , <NUM_LIT:1> , <NUM_LIT:2> ) ; if ( ! m_outputValid ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } byte digital ; synchronized ( m_outputDataSemaphore ) { digital = m_outputData . data . fixed_digital_out ; digital &= ~ ( <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ) ; if ( value ) { digital |= <NUM_LIT:1> << ( channel - <NUM_LIT:1> ) ; } m_outputData . data . fixed_digital_out = digital ; } } public short getEncoder ( int encoderNumber ) throws EnhancedIOException { BoundaryException . assertWithinBounds ( encoderNumber , <NUM_LIT:1> , <NUM_LIT:2> ) ; if ( ! m_inputValid ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } synchronized ( m_inputDataSemaphore ) { return ( short ) ( m_inputData . data . quad [ encoderNumber - <NUM_LIT:1> ] - m_encoderOffsets [ encoderNumber - <NUM_LIT:1> ] ) ; } } public void resetEncoder ( int encoderNumber ) throws EnhancedIOException { BoundaryException . assertWithinBounds ( encoderNumber , <NUM_LIT:1> , <NUM_LIT:2> ) ; if ( ! m_inputValid ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } synchronized ( m_inputDataSemaphore ) { m_encoderOffsets [ encoderNumber - <NUM_LIT:1> ] = m_inputData . data . quad [ encoderNumber - <NUM_LIT:1> ] ; } } public boolean getEncoderIndexEnable ( int encoderNumber ) throws EnhancedIOException { BoundaryException . assertWithinBounds ( encoderNumber , <NUM_LIT:1> , <NUM_LIT:2> ) ; if ( ! m_outputValid ) { m_requestEnhancedEnable = true ; throw new EnhancedIOException ( "<STR_LIT>" ) ; } synchronized ( m_outputDataSemaphore ) { return ( ( m_outputData . data . quad_index_enable > > ( encoderNumber - <NUM_LIT:1> ) ) & <NUM_LIT:1> ) != <NUM_LIT:0> ; } } public void setEncoderIndexEnable ( int encoderNumber , boolean enable ) { BoundaryException . assertWithinBounds ( encoderNumber , <NUM_LIT:1> , <NUM_LIT:2> ) ; synchronized ( m_outputDataSemaphore ) { m_outputData . data . quad_index_enable &= ~ ( <NUM_LIT:1> << ( encoderNumber - <NUM_LIT:1> ) ) ; if ( enable ) { m_outputData . data . quad_index_enable |= <NUM_LIT:1> << ( encoderNumber - <NUM_LIT:1> ) ; } m_configChanged = true ; } } public double getTouchSlider ( ) throws EnhancedIOException { if ( ! m_inputValid ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } synchronized ( m_inputDataSemaphore ) { byte rawValue = m_inputData . data . capsense_slider ; int value = rawValue < <NUM_LIT:0> ? rawValue + <NUM_LIT> : rawValue ; return value == <NUM_LIT:255> ? - <NUM_LIT:1.0> : value / <NUM_LIT> ; } } public double getPWMOutput ( int channel ) throws EnhancedIOException { BoundaryException . assertWithinBounds ( channel , <NUM_LIT:1> , <NUM_LIT:4> ) ; if ( ! m_outputValid ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } synchronized ( m_outputDataSemaphore ) { int tempCompare = m_outputData . data . pwm_compare [ channel - <NUM_LIT:1> ] & <NUM_LIT> ; int tempPeriod = m_outputData . data . pwm_period [ ( channel - <NUM_LIT:1> ) > > <NUM_LIT:1> ] & <NUM_LIT> ; return ( double ) tempCompare / ( double ) tempPeriod ; } } public void setPWMOutput ( int channel , double value ) throws EnhancedIOException { BoundaryException . assertWithinBounds ( channel , <NUM_LIT:1> , <NUM_LIT:4> ) ; if ( ! m_outputValid ) { throw new EnhancedIOException ( "<STR_LIT>" ) ; } if ( value > <NUM_LIT:1.0> ) { value = <NUM_LIT:1.0> ; } else if ( value < <NUM_LIT:0.0> ) { value = <NUM_LIT:0.0> ; } synchronized ( m_outputDataSemaphore ) { m_outputData . data . pwm_compare [ channel - <NUM_LIT:1> ] = ( short ) ( value * ( double ) m_outputData . data . pwm_period [ ( channel - <NUM_LIT:1> ) > > <NUM_LIT:1> ] ) ; } } public byte getFirmwareVersion ( ) throws EnhancedIOException { if ( ! m_inputValid ) { m_requestEnhancedEnable = true ; throw new EnhancedIOException ( "<STR_LIT>" ) ; } synchronized ( m_inputDataSemaphore ) { return m_inputData . data . fw_version ; } } } </s>
<s> package edu . wpi . first . wpilibj ; import edu . wpi . first . wpilibj . parsing . IInputOutput ; import edu . wpi . first . wpilibj . util . AllocationException ; import edu . wpi . first . wpilibj . util . CheckedAllocationException ; public class DigitalInput extends DigitalSource implements IInputOutput { private int m_channel ; private DigitalModule m_module ; private void initDigitalInput ( int slot , int channel ) { checkDigitalChannel ( channel ) ; checkDigitalModule ( slot ) ; m_channel = channel ; m_module = DigitalModule . getInstance ( slot ) ; m_module . allocateDIO ( channel , true ) ; } public DigitalInput ( int channel ) { initDigitalInput ( getDefaultDigitalModule ( ) , channel ) ; } public DigitalInput ( int slot , int channel ) { initDigitalInput ( slot , channel ) ; } protected void free ( ) { m_module . freeDIO ( m_channel ) ; } public boolean get ( ) { boolean state = m_module . getDIO ( m_channel ) ; if ( state ) { return true ; } else { return false ; } } public int getChannel ( ) { return m_channel ; } public int getChannelForRouting ( ) { return DigitalModule . remapDigitalChannel ( getChannel ( ) - <NUM_LIT:1> ) ; } public int getModuleForRouting ( ) { return DigitalModule . slotToIndex ( m_module . getSlot ( ) ) ; } public boolean getAnalogTriggerForRouting ( ) { return false ; } public void requestInterrupts ( Object handler , Object param ) { try { m_interruptIndex = interrupts . allocate ( ) ; } catch ( CheckedAllocationException e ) { throw new AllocationException ( "<STR_LIT>" ) ; } allocateInterrupts ( false ) ; m_interrupt . writeConfig_WaitForAck ( false ) ; m_interrupt . writeConfig_Source_AnalogTrigger ( getAnalogTriggerForRouting ( ) ) ; m_interrupt . writeConfig_Source_Channel ( ( byte ) getChannelForRouting ( ) ) ; m_interrupt . writeConfig_Source_Module ( ( byte ) getModuleForRouting ( ) ) ; setUpSourceEdge ( true , false ) ; } public void requestInterrupts ( ) { try { m_interruptIndex = interrupts . allocate ( ) ; } catch ( CheckedAllocationException e ) { throw new AllocationException ( "<STR_LIT>" ) ; } allocateInterrupts ( true ) ; m_interrupt . writeConfig_Source_AnalogTrigger ( getAnalogTriggerForRouting ( ) ) ; m_interrupt . writeConfig_Source_Channel ( ( byte ) getChannelForRouting ( ) ) ; m_interrupt . writeConfig_Source_Module ( ( byte ) getModuleForRouting ( ) ) ; setUpSourceEdge ( true , false ) ; } public void setUpSourceEdge ( boolean risingEdge , boolean fallingEdge ) { if ( m_interrupt != null ) { m_interrupt . writeConfig_RisingEdge ( risingEdge ) ; m_interrupt . writeConfig_FallingEdge ( fallingEdge ) ; } } } </s>
<s> package edu . wpi . first . wpilibj ; import edu . wpi . first . wpilibj . fpga . tAccumulator ; import edu . wpi . first . wpilibj . util . AllocationException ; import edu . wpi . first . wpilibj . util . CheckedAllocationException ; public class AnalogChannel extends SensorBase implements PIDSource { private static final int kAccumulatorSlot = <NUM_LIT:1> ; private static Resource channels = new Resource ( kAnalogModules * kAnalogChannels ) ; private int m_channel ; private int m_slot ; private AnalogModule m_module ; private static final int [ ] kAccumulatorChannels = { <NUM_LIT:1> , <NUM_LIT:2> } ; private tAccumulator m_accumulator ; private long m_accumulatorOffset ; public AnalogChannel ( final int channel ) { this ( getDefaultAnalogModule ( ) , channel ) ; } public AnalogChannel ( final int slot , final int channel ) { checkAnalogModule ( slot ) ; checkAnalogChannel ( slot ) ; m_channel = channel ; m_slot = slot ; m_module = AnalogModule . getInstance ( slot ) ; try { channels . allocate ( AnalogModule . slotToIndex ( slot ) * kAnalogModules + m_channel - <NUM_LIT:1> ) ; } catch ( CheckedAllocationException e ) { throw new AllocationException ( "<STR_LIT>" + m_channel + "<STR_LIT>" + m_slot + "<STR_LIT>" ) ; } if ( channel == <NUM_LIT:1> || channel == <NUM_LIT:2> ) { m_accumulator = new tAccumulator ( ( byte ) ( channel - <NUM_LIT:1> ) ) ; m_accumulatorOffset = <NUM_LIT:0> ; } else { m_accumulator = null ; } } protected void free ( ) { channels . free ( ( AnalogModule . slotToIndex ( m_slot ) * kAnalogModules + m_channel - <NUM_LIT:1> ) ) ; m_channel = <NUM_LIT:0> ; m_slot = <NUM_LIT:0> ; m_accumulator = null ; m_accumulatorOffset = <NUM_LIT:0> ; } public AnalogModule getModule ( ) { return m_module ; } public int getValue ( ) { return m_module . getValue ( m_channel ) ; } public int getAverageValue ( ) { return m_module . getAverageValue ( m_channel ) ; } public double getVoltage ( ) { return m_module . getVoltage ( m_channel ) ; } public double getAverageVoltage ( ) { return m_module . getAverageVoltage ( m_channel ) ; } public long getLSBWeight ( ) { return m_module . getLSBWeight ( m_channel ) ; } public int getOffset ( ) { return m_module . getOffset ( m_channel ) ; } public int getChannel ( ) { return m_channel ; } public int getSlot ( ) { return m_module . getSlot ( ) ; } public void setAverageBits ( final int bits ) { m_module . setAverageBits ( m_channel , bits ) ; } public int getAverageBits ( ) { return m_module . getAverageBits ( m_channel ) ; } public void setOversampleBits ( final int bits ) { m_module . setOversampleBits ( m_channel , bits ) ; } public int getOversampleBits ( ) { return m_module . getOversampleBits ( m_channel ) ; } public void initAccumulator ( ) { if ( ! isAccumulatorChannel ( ) ) { throw new AllocationException ( "<STR_LIT>" + kAccumulatorSlot + "<STR_LIT>" + kAccumulatorChannels [ <NUM_LIT:0> ] + "<STR_LIT:U+002C>" + kAccumulatorChannels [ <NUM_LIT:1> ] ) ; } m_accumulatorOffset = <NUM_LIT:0> ; setAccumulatorCenter ( <NUM_LIT:0> ) ; resetAccumulator ( ) ; } public void setAccumulatorInitialValue ( long initialValue ) { m_accumulatorOffset = initialValue ; } public void resetAccumulator ( ) { m_accumulator . strobeReset ( ) ; } public void setAccumulatorCenter ( int center ) { m_accumulator . writeCenter ( center ) ; } public void setAccumulatorDeadband ( int deadband ) { m_accumulator . writeDeadband ( deadband ) ; } public long getAccumulatorValue ( ) { long value = m_accumulator . readOutput_Value ( ) + m_accumulatorOffset ; return value ; } public long getAccumulatorCount ( ) { long count = m_accumulator . readOutput_Count ( ) ; return count ; } public void getAccumulatorOutput ( AccumulatorResult result ) { if ( result == null ) { System . out . println ( "<STR_LIT>" ) ; } if ( m_accumulator == null ) { System . out . println ( "<STR_LIT>" ) ; } result . value = m_accumulator . readOutput_Value ( ) + m_accumulatorOffset ; result . count = m_accumulator . readOutput_Count ( ) ; } public boolean isAccumulatorChannel ( ) { if ( m_module . getSlot ( ) != kAccumulatorSlot ) { return false ; } for ( int i = <NUM_LIT:0> ; i < kAccumulatorChannels . length ; i ++ ) { if ( m_channel == kAccumulatorChannels [ i ] ) { return true ; } } return false ; } public double pidGet ( ) { return getAverageValue ( ) ; } } </s>
<s> package edu . wpi . first . wpilibj ; import edu . wpi . first . wpilibj . util . AllocationException ; import edu . wpi . first . wpilibj . util . CheckedAllocationException ; public class Resource { private static Resource m_resourceList = null ; private final boolean m_numAllocated [ ] ; private final int m_size ; private final Resource m_nextResource ; public static void restartProgram ( ) { for ( Resource r = Resource . m_resourceList ; r != null ; r = r . m_nextResource ) { for ( int i = <NUM_LIT:0> ; i < r . m_size ; i ++ ) { r . m_numAllocated [ i ] = false ; } } } public Resource ( final int size ) { m_size = size ; m_numAllocated = new boolean [ m_size ] ; for ( int i = <NUM_LIT:0> ; i < m_size ; i ++ ) { m_numAllocated [ i ] = false ; } m_nextResource = Resource . m_resourceList ; Resource . m_resourceList = this ; } public int allocate ( ) throws CheckedAllocationException { for ( int i = <NUM_LIT:0> ; i < m_size ; i ++ ) { if ( m_numAllocated [ i ] == false ) { m_numAllocated [ i ] = true ; return i ; } } throw new CheckedAllocationException ( "<STR_LIT>" ) ; } public int allocate ( final int index ) throws CheckedAllocationException { if ( index >= m_size ) { throw new CheckedAllocationException ( "<STR_LIT>" + index + "<STR_LIT>" ) ; } if ( m_numAllocated [ index ] == true ) { throw new CheckedAllocationException ( "<STR_LIT>" + index + "<STR_LIT>" ) ; } m_numAllocated [ index ] = true ; return index ; } public void free ( final int index ) { if ( m_numAllocated [ index ] == false ) throw new AllocationException ( "<STR_LIT>" ) ; m_numAllocated [ index ] = false ; } } </s>
<s> package edu . wpi . first . wpilibj ; public interface MotorSafety { public static final double DEFAULT_SAFETY_EXPIRATION = <NUM_LIT> ; void setExpiration ( double timeout ) ; double getExpiration ( ) ; boolean isAlive ( ) ; void stopMotor ( ) ; void setSafetyEnabled ( boolean enabled ) ; boolean isSafetyEnabled ( ) ; } </s>
<s> package edu . wpi . first . wpilibj ; import com . sun . squawk . util . MathUtils ; import edu . wpi . first . wpilibj . can . CANNotInitializedException ; import edu . wpi . first . wpilibj . can . CANTimeoutException ; import edu . wpi . first . wpilibj . parsing . IUtility ; public class RobotDrive implements MotorSafety , IUtility { protected MotorSafetyHelper m_safetyHelper ; public static class MotorType { public final int value ; static final int kFrontLeft_val = <NUM_LIT:0> ; static final int kFrontRight_val = <NUM_LIT:1> ; static final int kRearLeft_val = <NUM_LIT:2> ; static final int kRearRight_val = <NUM_LIT:3> ; public static final MotorType kFrontLeft = new MotorType ( kFrontLeft_val ) ; public static final MotorType kFrontRight = new MotorType ( kFrontRight_val ) ; public static final MotorType kRearLeft = new MotorType ( kRearLeft_val ) ; public static final MotorType kRearRight = new MotorType ( kRearRight_val ) ; private MotorType ( int value ) { this . value = value ; } } public static final double kDefaultExpirationTime = <NUM_LIT> ; public static final double kDefaultSensitivity = <NUM_LIT> ; public static final double kDefaultMaxOutput = <NUM_LIT:1.0> ; protected static final int kMaxNumberOfMotors = <NUM_LIT:4> ; protected final int m_invertedMotors [ ] = new int [ <NUM_LIT:4> ] ; protected double m_sensitivity ; protected double m_maxOutput ; protected SpeedController m_frontLeftMotor ; protected SpeedController m_frontRightMotor ; protected SpeedController m_rearLeftMotor ; protected SpeedController m_rearRightMotor ; protected boolean m_allocatedSpeedControllers ; protected boolean m_isCANInitialized = true ; public RobotDrive ( final int leftMotorChannel , final int rightMotorChannel ) { m_sensitivity = kDefaultSensitivity ; m_maxOutput = kDefaultMaxOutput ; m_frontLeftMotor = null ; m_rearLeftMotor = new Jaguar ( leftMotorChannel ) ; m_frontRightMotor = null ; m_rearRightMotor = new Jaguar ( rightMotorChannel ) ; for ( int i = <NUM_LIT:0> ; i < kMaxNumberOfMotors ; i ++ ) { m_invertedMotors [ i ] = <NUM_LIT:1> ; } m_allocatedSpeedControllers = true ; setupMotorSafety ( ) ; drive ( <NUM_LIT:0> , <NUM_LIT:0> ) ; } public RobotDrive ( final int frontLeftMotor , final int rearLeftMotor , final int frontRightMotor , final int rearRightMotor ) { m_sensitivity = kDefaultSensitivity ; m_maxOutput = kDefaultMaxOutput ; m_rearLeftMotor = new Jaguar ( rearLeftMotor ) ; m_rearRightMotor = new Jaguar ( rearRightMotor ) ; m_frontLeftMotor = new Jaguar ( frontLeftMotor ) ; m_frontRightMotor = new Jaguar ( frontRightMotor ) ; for ( int i = <NUM_LIT:0> ; i < kMaxNumberOfMotors ; i ++ ) { m_invertedMotors [ i ] = <NUM_LIT:1> ; } m_allocatedSpeedControllers = true ; setupMotorSafety ( ) ; drive ( <NUM_LIT:0> , <NUM_LIT:0> ) ; } public RobotDrive ( SpeedController leftMotor , SpeedController rightMotor ) { if ( leftMotor == null || rightMotor == null ) { m_rearLeftMotor = m_rearRightMotor = null ; throw new NullPointerException ( "<STR_LIT>" ) ; } m_frontLeftMotor = null ; m_rearLeftMotor = leftMotor ; m_frontRightMotor = null ; m_rearRightMotor = rightMotor ; m_sensitivity = kDefaultSensitivity ; m_maxOutput = kDefaultMaxOutput ; for ( int i = <NUM_LIT:0> ; i < kMaxNumberOfMotors ; i ++ ) { m_invertedMotors [ i ] = <NUM_LIT:1> ; } m_allocatedSpeedControllers = false ; } public RobotDrive ( SpeedController frontLeftMotor , SpeedController rearLeftMotor , SpeedController frontRightMotor , SpeedController rearRightMotor ) { if ( frontLeftMotor == null || rearLeftMotor == null || frontRightMotor == null || rearRightMotor == null ) { m_frontLeftMotor = m_rearLeftMotor = m_frontRightMotor = m_rearRightMotor = null ; throw new NullPointerException ( "<STR_LIT>" ) ; } m_frontLeftMotor = frontLeftMotor ; m_rearLeftMotor = rearLeftMotor ; m_frontRightMotor = frontRightMotor ; m_rearRightMotor = rearRightMotor ; m_sensitivity = kDefaultSensitivity ; m_maxOutput = kDefaultMaxOutput ; for ( int i = <NUM_LIT:0> ; i < kMaxNumberOfMotors ; i ++ ) { m_invertedMotors [ i ] = <NUM_LIT:1> ; } m_allocatedSpeedControllers = false ; } public void drive ( double outputMagnitude , double curve ) { double leftOutput , rightOutput ; if ( curve < <NUM_LIT:0> ) { double value = MathUtils . log ( - curve ) ; double ratio = ( value - m_sensitivity ) / ( value + m_sensitivity ) ; if ( ratio == <NUM_LIT:0> ) { ratio = <NUM_LIT> ; } leftOutput = outputMagnitude / ratio ; rightOutput = outputMagnitude ; } else if ( curve > <NUM_LIT:0> ) { double value = MathUtils . log ( curve ) ; double ratio = ( value - m_sensitivity ) / ( value + m_sensitivity ) ; if ( ratio == <NUM_LIT:0> ) { ratio = <NUM_LIT> ; } leftOutput = outputMagnitude ; rightOutput = outputMagnitude / ratio ; } else { leftOutput = outputMagnitude ; rightOutput = outputMagnitude ; } setLeftRightMotorOutputs ( leftOutput , rightOutput ) ; } public void tankDrive ( GenericHID leftStick , GenericHID rightStick ) { if ( leftStick == null || rightStick == null ) { throw new NullPointerException ( "<STR_LIT>" ) ; } tankDrive ( leftStick . getY ( ) , rightStick . getY ( ) ) ; } public void tankDrive ( GenericHID leftStick , final int leftAxis , GenericHID rightStick , final int rightAxis ) { if ( leftStick == null || rightStick == null ) { throw new NullPointerException ( "<STR_LIT>" ) ; } tankDrive ( leftStick . getRawAxis ( leftAxis ) , rightStick . getRawAxis ( rightAxis ) ) ; } public void tankDrive ( double leftValue , double rightValue ) { leftValue = limit ( leftValue ) ; rightValue = limit ( rightValue ) ; if ( leftValue >= <NUM_LIT:0.0> ) { leftValue = ( leftValue * leftValue ) ; } else { leftValue = - ( leftValue * leftValue ) ; } if ( rightValue >= <NUM_LIT:0.0> ) { rightValue = ( rightValue * rightValue ) ; } else { rightValue = - ( rightValue * rightValue ) ; } setLeftRightMotorOutputs ( leftValue , rightValue ) ; } public void arcadeDrive ( GenericHID stick , boolean squaredInputs ) { arcadeDrive ( stick . getY ( ) , stick . getX ( ) , squaredInputs ) ; } public void arcadeDrive ( GenericHID stick ) { this . arcadeDrive ( stick , true ) ; } public void arcadeDrive ( GenericHID moveStick , final int moveAxis , GenericHID rotateStick , final int rotateAxis , boolean squaredInputs ) { double moveValue = moveStick . getRawAxis ( moveAxis ) ; double rotateValue = rotateStick . getRawAxis ( rotateAxis ) ; arcadeDrive ( moveValue , rotateValue , squaredInputs ) ; } public void arcadeDrive ( GenericHID moveStick , final int moveAxis , GenericHID rotateStick , final int rotateAxis ) { this . arcadeDrive ( moveStick , moveAxis , rotateStick , rotateAxis , true ) ; } public void arcadeDrive ( double moveValue , double rotateValue , boolean squaredInputs ) { double leftMotorSpeed ; double rightMotorSpeed ; moveValue = limit ( moveValue ) ; rotateValue = limit ( rotateValue ) ; if ( squaredInputs ) { if ( moveValue >= <NUM_LIT:0.0> ) { moveValue = ( moveValue * moveValue ) ; } else { moveValue = - ( moveValue * moveValue ) ; } if ( rotateValue >= <NUM_LIT:0.0> ) { rotateValue = ( rotateValue * rotateValue ) ; } else { rotateValue = - ( rotateValue * rotateValue ) ; } } if ( moveValue > <NUM_LIT:0.0> ) { if ( rotateValue > <NUM_LIT:0.0> ) { leftMotorSpeed = moveValue - rotateValue ; rightMotorSpeed = Math . max ( moveValue , rotateValue ) ; } else { leftMotorSpeed = Math . max ( moveValue , - rotateValue ) ; rightMotorSpeed = moveValue + rotateValue ; } } else { if ( rotateValue > <NUM_LIT:0.0> ) { leftMotorSpeed = - Math . max ( - moveValue , rotateValue ) ; rightMotorSpeed = moveValue + rotateValue ; } else { leftMotorSpeed = moveValue - rotateValue ; rightMotorSpeed = - Math . max ( - moveValue , - rotateValue ) ; } } setLeftRightMotorOutputs ( leftMotorSpeed , rightMotorSpeed ) ; } public void arcadeDrive ( double moveValue , double rotateValue ) { this . arcadeDrive ( moveValue , rotateValue , true ) ; } public void mecanumDrive_Cartesian ( double x , double y , double rotation , double gyroAngle ) { double xIn = x ; double yIn = y ; yIn = - yIn ; double rotated [ ] = rotateVector ( xIn , yIn , gyroAngle ) ; xIn = rotated [ <NUM_LIT:0> ] ; yIn = rotated [ <NUM_LIT:1> ] ; double wheelSpeeds [ ] = new double [ kMaxNumberOfMotors ] ; wheelSpeeds [ MotorType . kFrontLeft_val ] = xIn + yIn + rotation ; wheelSpeeds [ MotorType . kFrontRight_val ] = - xIn + yIn - rotation ; wheelSpeeds [ MotorType . kRearLeft_val ] = - xIn + yIn + rotation ; wheelSpeeds [ MotorType . kRearRight_val ] = xIn + yIn - rotation ; normalize ( wheelSpeeds ) ; byte syncGroup = ( byte ) <NUM_LIT> ; m_frontLeftMotor . set ( wheelSpeeds [ MotorType . kFrontLeft_val ] * m_invertedMotors [ MotorType . kFrontLeft_val ] * m_maxOutput , syncGroup ) ; m_frontRightMotor . set ( wheelSpeeds [ MotorType . kFrontRight_val ] * m_invertedMotors [ MotorType . kFrontRight_val ] * m_maxOutput , syncGroup ) ; m_rearLeftMotor . set ( wheelSpeeds [ MotorType . kRearLeft_val ] * m_invertedMotors [ MotorType . kRearLeft_val ] * m_maxOutput , syncGroup ) ; m_rearRightMotor . set ( wheelSpeeds [ MotorType . kRearRight_val ] * m_invertedMotors [ MotorType . kRearRight_val ] * m_maxOutput , syncGroup ) ; if ( m_isCANInitialized ) { try { CANJaguar . updateSyncGroup ( syncGroup ) ; } catch ( CANNotInitializedException e ) { m_isCANInitialized = false ; } catch ( CANTimeoutException e ) { } } if ( m_safetyHelper != null ) m_safetyHelper . feed ( ) ; } public void mecanumDrive_Polar ( double magnitude , double direction , double rotation ) { double frontLeftSpeed , rearLeftSpeed , frontRightSpeed , rearRightSpeed ; magnitude = limit ( magnitude ) * Math . sqrt ( <NUM_LIT> ) ; double dirInRad = ( direction + <NUM_LIT> ) * <NUM_LIT> / <NUM_LIT> ; double cosD = Math . cos ( dirInRad ) ; double sinD = Math . cos ( dirInRad ) ; double wheelSpeeds [ ] = new double [ kMaxNumberOfMotors ] ; wheelSpeeds [ MotorType . kFrontLeft_val ] = ( sinD * magnitude + rotation ) ; wheelSpeeds [ MotorType . kFrontRight_val ] = ( cosD * magnitude - rotation ) ; wheelSpeeds [ MotorType . kRearLeft_val ] = ( cosD * magnitude + rotation ) ; wheelSpeeds [ MotorType . kRearRight_val ] = ( sinD * magnitude - rotation ) ; normalize ( wheelSpeeds ) ; byte syncGroup = ( byte ) <NUM_LIT> ; m_frontLeftMotor . set ( wheelSpeeds [ MotorType . kFrontLeft_val ] * m_invertedMotors [ MotorType . kFrontLeft_val ] * m_maxOutput , syncGroup ) ; m_frontRightMotor . set ( wheelSpeeds [ MotorType . kFrontRight_val ] * m_invertedMotors [ MotorType . kFrontRight_val ] * m_maxOutput , syncGroup ) ; m_rearLeftMotor . set ( wheelSpeeds [ MotorType . kRearLeft_val ] * m_invertedMotors [ MotorType . kRearLeft_val ] * m_maxOutput , syncGroup ) ; m_rearRightMotor . set ( wheelSpeeds [ MotorType . kRearRight_val ] * m_invertedMotors [ MotorType . kRearRight_val ] * m_maxOutput , syncGroup ) ; if ( m_isCANInitialized ) { try { CANJaguar . updateSyncGroup ( syncGroup ) ; } catch ( CANNotInitializedException e ) { m_isCANInitialized = false ; } catch ( CANTimeoutException e ) { } } if ( m_safetyHelper != null ) m_safetyHelper . feed ( ) ; } void holonomicDrive ( float magnitude , float direction , float rotation ) { mecanumDrive_Polar ( magnitude , direction , rotation ) ; } public void setLeftRightMotorOutputs ( double leftOutput , double rightOutput ) { if ( m_rearLeftMotor == null || m_rearRightMotor == null ) { throw new NullPointerException ( "<STR_LIT>" ) ; } byte syncGroup = ( byte ) <NUM_LIT> ; if ( m_frontLeftMotor != null ) { m_frontLeftMotor . set ( limit ( leftOutput ) * m_invertedMotors [ MotorType . kFrontLeft_val ] * m_maxOutput , syncGroup ) ; } m_rearLeftMotor . set ( limit ( leftOutput ) * m_invertedMotors [ MotorType . kRearLeft_val ] * m_maxOutput , syncGroup ) ; if ( m_frontRightMotor != null ) { m_frontRightMotor . set ( - limit ( rightOutput ) * m_invertedMotors [ MotorType . kFrontRight_val ] * m_maxOutput , syncGroup ) ; } m_rearRightMotor . set ( - limit ( rightOutput ) * m_invertedMotors [ MotorType . kRearRight_val ] * m_maxOutput , syncGroup ) ; if ( m_isCANInitialized ) { try { CANJaguar . updateSyncGroup ( syncGroup ) ; } catch ( CANNotInitializedException e ) { m_isCANInitialized = false ; } catch ( CANTimeoutException e ) { } } if ( m_safetyHelper != null ) m_safetyHelper . feed ( ) ; } protected static double limit ( double num ) { if ( num > <NUM_LIT:1.0> ) { return <NUM_LIT:1.0> ; } if ( num < - <NUM_LIT:1.0> ) { return - <NUM_LIT:1.0> ; } return num ; } protected static void normalize ( double wheelSpeeds [ ] ) { double maxMagnitude = Math . abs ( wheelSpeeds [ <NUM_LIT:0> ] ) ; int i ; for ( i = <NUM_LIT:1> ; i < kMaxNumberOfMotors ; i ++ ) { double temp = Math . abs ( wheelSpeeds [ i ] ) ; if ( maxMagnitude < temp ) maxMagnitude = temp ; } if ( maxMagnitude > <NUM_LIT:1.0> ) { for ( i = <NUM_LIT:0> ; i < kMaxNumberOfMotors ; i ++ ) { wheelSpeeds [ i ] = wheelSpeeds [ i ] / maxMagnitude ; } } } protected static double [ ] rotateVector ( double x , double y , double angle ) { double cosA = Math . cos ( angle * ( <NUM_LIT> / <NUM_LIT> ) ) ; double sinA = Math . sin ( angle * ( <NUM_LIT> / <NUM_LIT> ) ) ; double out [ ] = new double [ <NUM_LIT:2> ] ; out [ <NUM_LIT:0> ] = x * cosA - y * sinA ; out [ <NUM_LIT:1> ] = x * sinA + y * cosA ; return out ; } public void setInvertedMotor ( MotorType motor , boolean isInverted ) { m_invertedMotors [ motor . value ] = isInverted ? - <NUM_LIT:1> : <NUM_LIT:1> ; } public void setSensitivity ( double sensitivity ) { m_sensitivity = sensitivity ; } public void setMaxOutput ( double maxOutput ) { m_maxOutput = maxOutput ; } protected void free ( ) { if ( m_allocatedSpeedControllers ) { if ( m_frontLeftMotor != null ) { ( ( PWM ) m_frontLeftMotor ) . free ( ) ; } if ( m_frontRightMotor != null ) { ( ( PWM ) m_frontRightMotor ) . free ( ) ; } if ( m_rearLeftMotor != null ) { ( ( PWM ) m_rearLeftMotor ) . free ( ) ; } if ( m_rearRightMotor != null ) { ( ( PWM ) m_rearRightMotor ) . free ( ) ; } } } public void setExpiration ( double timeout ) { m_safetyHelper . setExpiration ( timeout ) ; } public double getExpiration ( ) { return m_safetyHelper . getExpiration ( ) ; } public boolean isAlive ( ) { return m_safetyHelper . isAlive ( ) ; } public boolean isSafetyEnabled ( ) { return m_safetyHelper . isSafetyEnabled ( ) ; } public void setSafetyEnabled ( boolean enabled ) { m_safetyHelper . setSafetyEnabled ( enabled ) ; } public void stopMotor ( ) { if ( m_frontLeftMotor != null ) { m_frontLeftMotor . set ( <NUM_LIT:0.0> ) ; } if ( m_frontRightMotor != null ) { m_frontRightMotor . set ( <NUM_LIT:0.0> ) ; } if ( m_rearLeftMotor != null ) { m_rearLeftMotor . set ( <NUM_LIT:0.0> ) ; } if ( m_rearRightMotor != null ) { m_rearRightMotor . set ( <NUM_LIT:0.0> ) ; } } private void setupMotorSafety ( ) { m_allocatedSpeedControllers = true ; m_safetyHelper = new MotorSafetyHelper ( this ) ; m_safetyHelper . setExpiration ( kDefaultExpirationTime ) ; m_safetyHelper . setSafetyEnabled ( true ) ; } } </s>
<s> package edu . wpi . first . wpilibj ; import edu . wpi . first . wpilibj . util . AllocationException ; import edu . wpi . first . wpilibj . util . CheckedAllocationException ; public class Solenoid extends SolenoidBase { private int m_channel ; private synchronized void initSolenoid ( ) { checkSolenoidModule ( m_chassisSlot ) ; checkSolenoidChannel ( m_channel ) ; try { m_allocated . allocate ( slotToIndex ( m_chassisSlot ) * kSolenoidChannels + m_channel - <NUM_LIT:1> ) ; } catch ( CheckedAllocationException e ) { throw new AllocationException ( "<STR_LIT>" + m_channel + "<STR_LIT>" + m_chassisSlot + "<STR_LIT>" ) ; } } public Solenoid ( final int channel ) { super ( getDefaultSolenoidModule ( ) ) ; m_channel = channel ; initSolenoid ( ) ; } public Solenoid ( final int slot , final int channel ) { super ( slot ) ; m_channel = channel ; initSolenoid ( ) ; } protected synchronized void free ( ) { m_allocated . free ( slotToIndex ( m_chassisSlot ) * kSolenoidChannels + m_channel - <NUM_LIT:1> ) ; } public void set ( boolean on ) { byte value = ( byte ) ( on ? <NUM_LIT> : <NUM_LIT:0x00> ) ; byte mask = ( byte ) ( <NUM_LIT:1> << ( m_channel - <NUM_LIT:1> ) ) ; set ( value , mask ) ; } public boolean get ( ) { int value = getAll ( ) & ( <NUM_LIT:1> << ( m_channel - <NUM_LIT:1> ) ) ; return ( value != <NUM_LIT:0> ) ; } } </s>
<s> package edu . wpi . first . wpilibj . fpga ; import com . ni . rio . * ; public class tGlobal extends tSystem { public tGlobal ( ) { super ( ) ; } protected void finalize ( ) { super . finalize ( ) ; } public static final int kNumSystems = <NUM_LIT:1> ; private static final int kGlobal_Version_Address = <NUM_LIT> ; public static int readVersion ( ) { return ( int ) ( ( NiRioSrv . peek32 ( m_DeviceHandle , kGlobal_Version_Address , status ) ) & <NUM_LIT> ) ; } private static final int kGlobal_FPGA_LED_Address = <NUM_LIT> ; public static void writeFPGA_LED ( final boolean value ) { NiRioSrv . poke32 ( m_DeviceHandle , kGlobal_FPGA_LED_Address , ( value ? <NUM_LIT:1> : <NUM_LIT:0> ) , status ) ; } public static boolean readFPGA_LED ( ) { return ( ( NiRioSrv . peek32 ( m_DeviceHandle , kGlobal_FPGA_LED_Address , status ) ) != <NUM_LIT:0> ? true : false ) ; } private static final int kGlobal_LocalTime_Address = <NUM_LIT> ; public static long readLocalTime ( ) { return ( long ) ( ( NiRioSrv . peek32 ( m_DeviceHandle , kGlobal_LocalTime_Address , status ) ) & <NUM_LIT> ) ; } private static final int kGlobal_Revision_Address = <NUM_LIT> ; public static long readRevision ( ) { return ( long ) ( ( NiRioSrv . peek32 ( m_DeviceHandle , kGlobal_Revision_Address , status ) ) & <NUM_LIT> ) ; } } </s>