Summary

Code(groovy)

import static net.grinder.script.Grinder.grinder
import static org.junit.Assert.*
import static org.hamcrest.Matchers.*
import net.grinder.script.GTest
import net.grinder.script.Grinder
import net.grinder.scriptengine.groovy.junit.GrinderRunner
import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess
import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread
// import static net.grinder.util.GrinderUtils.* // You can use this if you're using nGrinder after 3.2.3
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith

import org.ngrinder.http.HTTPRequest
import org.ngrinder.http.HTTPRequestControl
import org.ngrinder.http.HTTPResponse
import org.ngrinder.http.cookie.Cookie
import org.ngrinder.http.cookie.CookieManager

import groovy.json.JsonOutput
/**
* A simple example using the HTTP plugin that shows the retrieval of a single page via HTTP.
*
* This script is automatically generated by ngrinder.
*
* @author admin
*/
@RunWith(GrinderRunner)
class TestRunner {

	public static GTest test
	public static HTTPRequest request
	public static Map<String, String> headers = [:]
	public static Map<String, Object> params = [:]
	public static List<Cookie> cookies = []
	
	@BeforeProcess
	public static void beforeProcess() {
		HTTPRequestControl.setConnectionTimeout(300000)
		test = new GTest(1, "49.50.164.137")
		request = new HTTPRequest()

		// Set header data
		headers.put("Content-Type", "application/json")
		grinder.logger.info("before process.")
	}

	@BeforeThread
	public void beforeThread() {
		test.record(this, "test")
		grinder.statistics.delayReports = true
		grinder.logger.info("before thread.")
	}

	@Before
	public void before() {
		request.setHeaders(headers)
		CookieManager.addCookies(cookies)
		grinder.logger.info("before. init headers and cookies")
	}

	@Test
	public void test() {
		Map<String, Object> paramData = new HashMap<>();
		
		int randomNum = Math.abs(new Random().nextInt() % 10000) + 1 //
		String email = Integer.toString(randomNum) + "@yousinsa.com" //
		
		paramData.put("userEmail", email);
		paramData.put("userPassword", "password");
		
		String json = JsonOutput.toJson(paramData);		
		HTTPResponse response = request.POST("<http://49.50.164.137:8080/api/v1/users/sign-in>", json.getBytes()) //

		if (response.statusCode == 301 || response.statusCode == 302) {
			grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", response.statusCode)
		} else {
			assertThat(response.statusCode, is(200))
		}
	}
}

Stress Simulation Result

Untitled

Untitled

분석

Untitled

Untitled

EXPLAIN select
  userentity0_.id as id1_5_,
  userentity0_.created_at as created_2_5_,
  userentity0_.updated_at as updated_3_5_,
  userentity0_.user_email as user_ema4_5_,
  userentity0_.user_name as user_nam5_5_,
  userentity0_.user_password as user_pas6_5_,
  userentity0_.user_role as user_rol7_5_
from
  users userentity0_
where
  userentity0_.user_email = '[email protected]'

Explain

원인 분석

문제 해결 방안

<aside> 👉 1. UserEmail에 Unique 제약조건을 통해서 Index가 생성되도록 설정

</aside>

VUser500