/**
   * Initializes all mocks needed to execute a query operation.
   *
   * @param nodeResultLimit configures the result size limit, use <code>Long.MAX_VALUE</code> to
   *     disable feature
   * @param numberOfReturnedQueryEntries configures the number of returned entries of the query
   *     operation
   */
  protected void initMocks(long nodeResultLimit, int numberOfReturnedQueryEntries) {
    for (int i = 0; i < numberOfReturnedQueryEntries; i++) {
      QueryableEntry queryableEntry = mock(QueryableEntry.class);
      when(queryableEntry.getKeyData()).thenAnswer(randomDataAnswer);
      when(queryableEntry.getIndexKey()).thenAnswer(randomDataAnswer);
      when(queryableEntry.getValueData()).thenAnswer(randomDataAnswer);

      queryEntries.add(queryableEntry);
      queryEntrySet.add(queryableEntry);
    }

    QueryResult queryResult = new QueryResult(nodeResultLimit);

    when(mapContextQuerySupport.newQueryResult(anyInt())).thenReturn(queryResult);
    when(mapContextQuerySupport.queryOnPartition(
            MAP_NAME, TruePredicate.INSTANCE, Operation.GENERIC_PARTITION_ID))
        .thenReturn(queryEntries);

    IndexService indexService = mock(IndexService.class);
    when(indexService.query(TruePredicate.INSTANCE)).thenReturn(queryEntrySet);

    MapConfig mapConfig = mock(MapConfig.class);
    when(mapConfig.isStatisticsEnabled()).thenReturn(false);

    MapServiceContext mapServiceContext = mock(MapServiceContext.class);
    when(mapServiceContext.getMapContextQuerySupport()).thenReturn(mapContextQuerySupport);

    MapService mapService = mock(MapService.class);
    when(mapService.getMapServiceContext()).thenReturn(mapServiceContext);

    queryOperation.mapService = mapService;

    MapContainer mapContainer = mock(MapContainer.class);
    when(mapContainer.getIndexService()).thenReturn(indexService);
    when(mapContainer.getMapConfig()).thenReturn(mapConfig);

    queryOperation.mapContainer = mapContainer;

    InternalPartitionService partitionService = mock(InternalPartitionService.class);
    when(partitionService.getPartitionStateVersion()).thenReturn(0);
    when(partitionService.hasOnGoingMigrationLocal()).thenReturn(false);

    NodeEngine nodeEngine = mock(NodeEngine.class);
    when(nodeEngine.getPartitionService()).thenReturn(partitionService);

    queryOperation.setNodeEngine(nodeEngine);
  }
 @Override
 protected void writeInternal(ObjectDataOutput out) throws IOException {
   super.writeInternal(out);
   final List<Data> keyValueSequence = this.keyValueSequence;
   final int size = keyValueSequence.size();
   out.writeInt(size);
   for (Data data : keyValueSequence) {
     data.writeData(out);
   }
 }
 @Override
 protected void writeInternal(ObjectDataOutput out) throws IOException {
   super.writeInternal(out);
   final int size = entries.size();
   out.writeInt(size);
   for (int i = 0; i < size; i++) {
     final Map.Entry<Data, Data> entry = entries.get(i);
     out.writeData(entry.getKey());
     out.writeData(entry.getValue());
     recordInfos.get(i).writeData(out);
   }
 }
 @Override
 protected void readInternal(ObjectDataInput in) throws IOException {
   super.readInternal(in);
   final int size = in.readInt();
   if (size < 1) {
     keyValueSequence = Collections.emptyList();
   } else {
     final List<Data> tmpKeyValueSequence = new ArrayList<Data>(size);
     for (int i = 0; i < size; i++) {
       final Data data = in.readData();
       tmpKeyValueSequence.add(data);
     }
     keyValueSequence = tmpKeyValueSequence;
   }
 }
 @Override
 protected void readInternal(ObjectDataInput in) throws IOException {
   super.readInternal(in);
   final int size = in.readInt();
   entries = new ArrayList<Map.Entry<Data, Data>>(size);
   recordInfos = new ArrayList<RecordInfo>(size);
   for (int i = 0; i < size; i++) {
     Data key = in.readData();
     Data value = in.readData();
     Map.Entry entry = new AbstractMap.SimpleImmutableEntry<Data, Data>(key, value);
     entries.add(entry);
     final RecordInfo recordInfo = new RecordInfo();
     recordInfo.readData(in);
     recordInfos.add(recordInfo);
   }
 }
 /**
  * Executes the query operation and returns the {@link QueryResult}.
  *
  * @return {@link QueryResult}
  */
 protected QueryResult getQueryResult() throws Exception {
   queryOperation.run();
   return (QueryResult) queryOperation.getResponse();
 }