#!/bin/bash

# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and

# A YCSB-like executable that can be integrated into PerfKitBenchmarker.
#
# It is intended to be run in a VM that is brought up by PerfKitBenchmarker
# with node.js, npm, and google-cloud for nodejs installed. The environment can
# be configured as follows:
#
# curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh \
#   | bash
# export NVM_DIR="$HOME/.nvm"
# [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# nvm install stable'
# nvm alias default stable')
# npm install --save express @google-cloud/storage @google-cloud/common-grpc \
#   binary-search-bounds dedent fs path stats-lite yargs checkpoint-stream
#   lodash.chunk merge-stream google-gax lodash.flatten delay p-queue \
#   stack-trace lodash.snakecase lodash.random time-span
# sudo sudo apt-get -y install git
# git clone https://github.com/googleapis/nodejs-spanner.git

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

ln -s ${HOME}/nodejs-spanner/src ${DIR}/../../src
ln -s ${HOME}/node_modules ${DIR}/../node_modules

node ${DIR}/../ycsb.js run "${@:4}"
