import encoding from 'k6/encoding';
import http from 'k6/http';
import { check } from 'k6';
const username = 'root';
const password = 'rootpassword';
export default function () {
// username, password 를 base64 로 encoding
const credentials = `${username}:${password}`;
const encodedCredentials = encoding.b64encode(credentials);
// Aggregator node 로의 data api 호출 url
const url = 'http://10.0.0.165:3307/api/v2/query/rows';
// HTTP Post 방식으로 전달할 SQL Payload 설정
const emp_no = Math.floor(Math.random() * 300000 + 1)
const payload = JSON.stringify({
sql: "SELECT * FROM emp2 where emp_no = (?)",
args: [emp_no],
database: "jsdb",
});
// HTTP Post 방식으로 전달할 Header 설정 : Authentication / Content-type
const params = {
auth: "basic",
headers: {
"Authorization": `Basic ${encodedCredentials}`,
'Content-Type': 'application/json',
},
};
// http post 방식으로 호출
let res = http.post(url, payload, params);
// 필요시 Data 확인
//console.log(res.body);
}
JavaScript
복사