1018 - 1024


# 1018 - 1024

# 1018 - JUnit์˜ assertThat, assertj์˜ assertThat

ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋Š” ํฌ๊ฒŒ ์‹คํ–‰ ๋‹จ๊ณ„, ๊ฒ€์ฆ ๋‹จ๊ณ„๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๋‹ค.

  • ์‹คํ–‰ ๋‹จ๊ณ„์—์„œ๋Š” ์‚ฌ์šฉ์ž ์ž…๋ ฅ์„ ๋ชจ๋ฐฉํ•˜์—ฌ ํ…Œ์ŠคํŠธํ•  ๋กœ์ง์„ ์‹คํ–‰
  • ๊ฒ€์ฆ ๋‹จ๊ณ„์—์„œ๋Š” ์‹คํ–‰ ๋‹จ๊ณ„๊ฐ€ ์˜ˆ์ƒํ•œ ๋Œ€๋กœ ๋™์ž‘ํ•˜๋Š”์ง€ ๊ฒ€์ฆ JUnit์—์„œ ๊ฒ€์ฆ ๋‹จ๊ณ„๋ฅผ ๋„์™€์ฃผ๋Š” ๋ฉ”์†Œ๋“œ๊ฐ€ ๋ฐ”๋กœ assertThat์ด๋ผ๋Š” ๋ฉ”์†Œ๋“œ๋‹ค.

# org.junit.Assert.assertThat

public static <T> void assertThat(T actual, Matcher<? super T> matcher)
  • org.junit.Assert.assertThat์˜ ๊ธฐ๋ณธ ํ˜•ํƒœ
  • actual ์ธ์ž์— ๊ฒ€์ฆ๋Œ€์ƒ(์‹คํ–‰ ๋‹จ๊ณ„์˜ ๊ฒฐ๊ณผ)์„ ๋„ฃ๊ณ , ์ด์™€ ๋น„๊ตํ•˜๋Š” ๋กœ์ง(matcher)์„ ์ฃผ์ž…๋ฐ›์•„ ๊ฒ€์ฆ ๋‹จ๊ณ„๋ฅผ ์ˆ˜ํ–‰ํ•œ๋‹ค.

๊ฐœ๋ฐœ์ž๊ฐ€ matcher๋ฅผ ์ง์ ‘ ๊ตฌํ˜„ํ•˜๋Š”๊ฒƒ์€ ๋น„ํšจ์œจ์ ์ด๊ณ , ๊ตฌํ˜„ํ•œ matcher์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ๋„ ์žˆ๋‹ค. matcher์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ํ…Œ์ŠคํŠธ๊ฐ€ ์‹คํŒจํ•˜๋Š”๋ฐ, ์™ธ๋ถ€ ์š”์ธ์— ์˜ํ–ฅ์„ ๋ฐ›๋Š” ๊ฒƒ์€ ์ข‹์€ ํ…Œ์ŠคํŠธ๋ผ๊ณ  ํ•  ์ˆ˜ ์—†๋‹ค. ๋”ฐ๋ผ์„œ JUnit์˜ assertThat์€ hamcrest์— ๊ตฌํ˜„๋œ matcher์„ ์‚ฌ์šฉํ•˜๋„๋ก ๊ฐ•์ œํ•˜๊ณ  ์žˆ๋‹ค.

# org.junit.Assert.assertThat ์˜ˆ์ œ ์ฝ”๋“œ

  • 0๋ณด๋‹ค ์ปค์•ผํ•œ๋‹ค
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.greaterThan;

...
@Test
public void number_test() throws Exception {
    int number = 3;

    int result = mathService.add(number, 3);

    assertThat(result, greaterThan(0));
}
  • 0๋ณด๋‹ค ํฌ๊ณ  10๋ณด๋‹ค๋Š” ์ž‘์•ผ์•ผ ํ•œ๋‹ค.
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.core.AllOf.allOf;

...
@Test
public void number_test() throws Exception {
    int number = 3;

    int result = mathService.add(number, 3);

    assertThat(result, allOf(
        greaterThan(0),
        lessThan(10)
    ));
}

# org.junit.Assert.assertThat ๋‹จ์ 

  • ์ž๋™์™„์„ฑ
    allOf, greaterThan, lessThan ๋“ฑ์˜ ๋ฉ”์†Œ๋“œ๋“ค์„ ๋ฏธ๋ฆฌ import ํ•ด๋†“์ง€ ์•Š์œผ๋ฉด, IDE์—์„œ ์ž๋™์™„์„ฑ์„ ํ•ด์ฃผ์ง€ ๋ชปํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ•„์š”ํ•œ ๋ฉ”์†Œ๋“œ๋ฅผ ๊ณต์‹๋ฌธ์„œ์—์„œ ์ฐพ๊ฑฐ๋‚˜, ์ด๋ฆ„์„ ์™ธ์›Œ์„œ ์ž‘์„ฑํ•ด์•ผ ํ•œ๋‹ค.

  • Assertion ๋ถ„๋ฅ˜(matcher)
    ์œ„ ๋กœ์ง์—์„œ๋Š” int ํƒ€์ž…์— ๋Œ€ํ•œ matcher๋งŒ ํ•„์š”ํ•œ๋ฐ, org.hamcrest.Matchers ํด๋ž˜์Šค์—๋Š” ์—ฌ๋Ÿฌ ํƒ€์ž…์— ๋Œ€ํ•œ matcher๊ฐ€ ํ•จ๊ป˜ ๋“ค์–ด์žˆ๋‹ค. ๊ทธ๋ž˜์„œ ์›ํ•˜๋Š” matcher๋ฅผ ์ฐพ๊ธฐ๊ฐ€ ํž˜๋“ค๋‹ค.

  • ํ™•์žฅ์„ฑ
    ์ถ”๊ฐ€๋œ ์กฐ๊ฑด๋„ ๊ฐ™์ด ๊ฒ€์ฆํ•˜๊ธฐ ์œ„ํ•ด์„œ allOf๋ผ๋Š” ๋ฉ”์†Œ๋“œ๋กœ ๊ธฐ์กด ์กฐ๊ฑด๊ณผ ๋ฌถ์–ด์ค˜์•ผ ํ–ˆ๋‹ค. assertj์—์„œ๋Š” ์ด๋Ÿฐ ๋ถˆํŽธํ•จ์„ ํ•ด๊ฒฐํ•˜๊ณ  ๋ฉ”์†Œ๋“œ ์ฒด์ด๋‹ ํŒจํ„ดํ˜•์‹์œผ๋กœ ์‚ฌ์šฉ ๊ฐ€๋…์„ฑ์„ ํ–ฅ์ƒ์‹œํ‚จ assertThat์„ ์ œ๊ณตํ•œ๋‹ค.

# org.assertj.core.api.Assertions.assertThat

public static AbstractAssert<SELF, T> assertThat(T actual)
  • assertj์˜ assertThat์€ ์ธ์ž๋กœ actual(๊ฒ€์ฆ๋Œ€์ƒ)๋งŒ ๋ฐ›๋Š”๋‹ค. ๊ทธ๋ฆฌ๊ณ  actual์˜ ํƒ€์ž…์— ๋”ฐ๋ผ AbstractAssert๋ผ๋Š” ์ถ”์ƒํด๋ž˜์Šค๋ฅผ ์ƒ์†ํ•œ Assert ์ƒ์†ํ•œ Assert ํด๋ž˜์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
public static AbstractIntegerAssert<?> assertThat(int actual)
public static AbstractDateAssert<?> assertThat(Date actual)
public static AbstractUriAssert<?> assertThat(URI actual)

ํƒ€์ž…์— ๋”ฐ๋ผ ๊ฐ Assert ํด๋ž˜์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ณ  ๊ฐ ํด๋ž˜์Šค๋“ค์€ ํƒ€์ž…์— ๋งž๋Š” Assertion ๋ฉ”์†Œ๋“œ๋ฅผ ์ œ๊ณตํ•œ๋‹ค.

  • AbstractIntegerAssert (java.long.Integer)
    • isGreaterThan(int other)
    • isLessThan(int other)
    • ...
  • AbstractDateAssert (java.util.Date)
    • hasTime(long timestamp)
    • hasYear(int year)
    • isAfter(Date other)
    • isBefore(Date other)
    • ...
  • AbstractUriAssert (java.net.URI)
    • hasNoParameters()
    • hasNoQuery()
    • hasNoPort()
    • ...

=> ๊ฐ Assertion ๋ฉ”์†Œ๋“œ๋Š” ๋ฐ˜ํ™˜ ํƒ€์ž…์ด SELF ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ฉ”์†Œ๋“œ ์ฒด์ด๋‹ ํŒจํ„ด์œผ๋กœ ํ…Œ์ŠคํŠธ ๋กœ์ง์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

# org.assertj.core.api.Assertions.assertThat ์˜ˆ์ œ ์ฝ”๋“œ

import static org.assertj.core.api.Assertions.assertThat;

...
@Test
public void number_test() throws Exception {
    int number = 3;

    int result = mathService.add(number ,3);

    assertThat(result)
                .isGreaterThan(0)
                .isLessThan(10);
}

# ์ •๋ฆฌ

JUnit, AssertJ๊ฐ€ ์ œ๊ณตํ•˜๋Š” assertThat ๋ฉ”์†Œ๋“œ๋ฅผ ๋น„๊ตํ•œ ๊ฒฐ๊ณผ ์ž๋™์™„์„ฑ, Assertion๋ถ„๋ฅ˜, ํ™•์žฅ์„ฑ ์„ธ๊ฐ€์ง€์˜ ์ด์œ ๋กœ AssertJ์˜ assertThat์„ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•œ๋‹ค.


# 1019 - ์ •์  ๋ฉค๋ฒ„ static (์ •์  ํ‚ค์›Œ๋“œ)

# static ํ‚ค์›Œ๋“œ

ํด๋ž˜์Šค ๋ฉค๋ฒ„(๋ณ€์ˆ˜, ๋ฉ”์†Œ๋“œ)์— ๋ถ™์ด๋Š” ํ‚ค์›Œ๋“œ
๋ฉค๋ฒ„๋ณ€์ˆ˜๋Š” ํด๋ž˜์Šค๊ฐ€ ๊ฐ์ฒด๋กœ ์ƒ์„ฑ๋  ๋•Œ ๋ฉ”๋ชจ๋ฆฌ์— ๋กœ๋”ฉํ•˜์ง€๋งŒ, static ํ‚ค์›Œ๋“œ๊ฐ€ ๋ถ™์€ ๋ฉค๋ฒ„๋Š” ํ”„๋กœ๊ทธ๋žจ์ด ์‹คํ–‰ ๋  ๋•Œ ๋ฉ”๋ชจ๋ฆฌ์— ๋กœ๋“œ๋œ๋‹ค.
ํด๋ž˜์Šค ๋ฉค๋ฒ„์ด๊ธด ํ•˜์ง€๋งŒ ์ž๊ธฐ๊ฐ€ ๋กœ๋“œ๋˜๊ธฐ ์œ„ํ•œ ๊ณต๊ฐ„์œผ๋กœ์จ๋งŒ ํด๋ž˜์Šค์•ˆ์— ์„ ์–ธํ•˜๋Š” ์˜๋ฏธ๊ฐ€ ์žˆ๋‹ค.

  1. ๋ฉค๋ฒ„๋ณ€์ˆ˜
  2. ๋ฉค๋ฒ„ ๋ฉ”์†Œ๋“œ
  • ๋ฉ”์†Œ๋“œ ๋‚ด์—์„œ ์‚ฌ์šฉ ๋ถˆ๊ฐ€

# ๋ฉค๋ฒ„๋ณ€์ˆ˜

  • static ๋ณ€์ˆ˜, ์ •์ ๋ณ€์ˆ˜, ๊ณต์šฉ๋ณ€์ˆ˜
  • ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ณ  ๋ฐ”๋กœ ํด๋ž˜์Šค๋ช….๋ฉ”์†Œ๋“œ() ๋˜๋Š” ํด๋ž˜์Šค๋ช….๋ณ€์ˆ˜๋ช…์œผ๋กœ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
    • Util Class : java.uitl.Math
  • ๋ฉค๋ฒ„๋ณ€์ˆ˜๋Š” ๋ฉ”๋ชจ๋ฆฌ์— ํ•œ๋ฒˆ ํ• ๋‹น๋˜์–ด ํ”„๋กœ๊ทธ๋žจ์ด ์ข…๋ฃŒ๋  ๋–„ ํ•ด์ œ๋˜๋Š” ๋ณ€์ˆ˜๋กœ, ๋ฉ”๋ชจ๋ฆฌ์— ํ•œ๋ฒˆ ํ• ๋‹น๋˜๋ฏ€๋กœ ์—ฌ๋Ÿฌ ๊ฐ์ฒด๊ฐ€ ํ•ด๋‹น ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๊ณต์œ ํ•˜๊ฒŒ ๋œ๋‹ค.
  • ๋ฉค๋ฒ„ ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๋ฉ”์†Œ๋“œ ๋˜ํ•œ ๋ฉค๋ฒ„ ๋ฉ”์†Œ๋“œ๋กœ ์„ ์–ธ๋˜์–ด์•ผ ํ•œ๋‹ค.

# ์‚ฌ์šฉ

  • static ๋ณ€์ˆ˜ : ์ผ๋ฐ˜์ ์œผ๋กœ ์ƒ์ˆ˜๋“ค๋งŒ ๋ชจ์•„์„œ ์‚ฌ์šฉํ•˜๋ฉฐ ์ƒ์ˆ˜์˜ ๋ณ€์ˆ˜๋ช…์€ ๋Œ€๋ฌธ์ž์™€ _๋ฅผ ์กฐํ•ฉํ•˜์—ฌ ์ด๋ฆ„์ง“๊ณ , ๋˜ํ•œ ์ƒ์†์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด final class๋กœ ์„ ์–ธ์„ ํ•œ๋‹ค.
  • static ๋ฉ”์†Œ๋“œ : ์ƒ์†์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด final class๋กœ ์„ ์–ธ์„ ํ•˜๊ณ , ์œ ํ‹ธ ๊ด€๋ จ๋œ ํ•จ์ˆ˜๋“ค์„ ๋ชจ์•„๋‘”๋‹ค.

# 1020 - ํŠธ๋žœ์žญ์…˜ ๊ฒฉ๋ฆฌ ์ˆ˜์ค€(isolation level)

# ํŠธ๋žœ์žญ์…˜ ๊ฒฉ๋ฆฌ์ˆ˜์ค€์ด๋ž€?

ํŠธ๋žœ์žญ์…˜ ๊ฒฉ๋ฆฌ์ˆ˜์ค€(isolation level)์ด๋ž€ ๋™์‹œ์— ์—ฌ๋Ÿฌ ํŠธ๋žœ์žญ์…˜์ด ์ฒ˜๋ฆฌ๋  ๋–„, ํŠธ๋žœ์žญ์…˜๋ผ๋ฆฌ ์–ผ๋งˆ๋‚˜ ์„œ๋กœ ๊ณ ๋ฆฝ๋˜์–ด ์žˆ๋Š”์ง€๋ฅผ ๋‚˜ํƒœ๋‚ด๋Š” ๊ฒƒ์ด๋‹ค.
์ฆ‰, ๊ฐ„๋‹จํ•˜๊ฒŒ ๋งํ•ด ํŠน์ • ํŠธ๋žœ์žญ์…˜์ด ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์— ๋ณ€๊ฒฝํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋„๋ก ํ—ˆ์šฉํ• ์ง€ ๋ง์ง€๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋Š” ACID ํŠน์ง•๊ณผ ๊ฐ™์ด ํŠธ๋žœ์žญ์…˜์ด ๋…๋ฆฝ์ ์ธ ์ˆ˜ํ–‰์„ ํ•˜๋„๋ก Locking์„ ํ†ตํ•ด, ํŠธ๋žœ์žญ์…˜์ด DB๋ฅผ ๋‹ค๋ฃจ๋Š” ๋™์•ˆ ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์ด ๊ด€์—ฌํ•˜์ง€ ๋ชปํ•˜๋„๋ก ๋ง‰๋Š” ๊ฒƒ์ด ํ•„์š”ํ•˜๋‹ค.

ํ•˜์ง€๋งŒ ๋ฌด์กฐ๊ฑด Locking์œผ๋กœ ๋™์‹œ์— ์ˆ˜ํ–‰๋˜๋Š” ์ˆ˜๋งŽ์€ ํŠธ๋žœ์žญ์…˜๋“ค์„ ์ˆœ์„œ๋Œ€๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•˜๊ฒŒ ๋˜๋ฉด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ์„ฑ๋Šฅ์€ ๋–จ์–ด์ง€๊ฒŒ ๋œ๋‹ค. ํ•˜์ง€๋งŒ, ์„ฑ๋Šฅ์„ ๋†’์ด๊ธฐ ์œ„ํ•ด Locking์˜ ๋ฒ”์œ„๋ฅผ ์ค„์ธ๋‹ค๋ฉด, ์ž˜๋ชป๋œ ๊ฐ’์ด ์ฒ˜๋ฆฌ๋  ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒ ํ•  ์ˆ˜ ์žˆ๋‹ค.

๋”ฐ๋ผ์„œ ์ตœ๋Œ€ํ•œ ํšจ์œจ์ ์ธ Locking ๋ฐฉ๋ฒ•์ด ํ•„์š”ํ•˜๋‹ค.

# Lock

  • Lock : ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ์˜ ์ˆœ์ฐจ์„ฑ์„ ๋ณด์žฅํ•˜๊ธฐ ์œ„ํ•œ ๋ฐฉ๋ฒ•(๋™์‹œ์„ฑ ์ œ์–ด)
    DBMS ๋งˆ๋‹ค Lock์„ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ์‹์ด ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— DBMS๋ฅผ ํšจ๊ณผ์ ์œผ๋กœ ์ด์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ ํ•ด๋‹น DB์˜ Lock์— ๋Œ€ํ•œ ์ดํ•ด๊ฐ€ ์š”๊ตฌ๋œ๋‹ค.
    • ๊ณต์œ (shared) lock : ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์„ ๋•Œ ์‚ฌ์šฉ๋˜์–ด ์ง€๋Š” lock.
      • ๊ณต์œ ๋ฝ์€ ๊ณต์œ ๋ฝ๋ผ๋ฆฌ ๋™์‹œ์— ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. ํ•˜์ง€๋งŒ, ๊ณต์œ ๋ฝ์ด ์„ค์ •๋œ ๋ฐ์ดํ„ฐ์— ๋ฐฐํƒ€๋ฝ์„ ์‚ฌ์šฉํ•  ์ˆ˜๋Š” ์—†๋‹ค.
    • ๋ฐฐํƒ€(Exclusive) lock : ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ€๊ฒฝํ•˜๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉ๋˜๋ฉฐ, ํŠธ๋žœ์žญ์…˜์ด ์™„๋ฃŒ๋  ๋–„๊นŒ์ง€ ์œ ์ง€๋œ๋‹ค.
      • Lock์ด ํ•ด์ œ๋  ๋–„๊นŒ์ง€ ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜(์ฝ๊ธฐ ํฌํ•จ)์€ ํ•ด๋‹น ๋ฆฌ์†Œ์Šค์— ์ ‘๊ทผํ•  ์ˆ˜ ์—†๋‹ค.
      • ํ•ด๋‹น Lockdms ํŠธ๋žœ์žญ์…˜์ด ์ˆ˜ํ–‰๋˜๊ณ  ์žˆ๋Š” ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•ด์„œ๋Š” ์ ‘๊ทผํ•˜์—ฌ ํ•จ๊ผ Lock์„ ์„ค์ •ํ•  ์ˆ˜ ์—†๋‹ค.

# ๊ฒฉ๋ฆฌ ์ˆ˜์ค€

  • READ UNCOMMITTED (๋ ˆ๋ฒจ 0)
    • SELECT ๋ฌธ์žฅ์ด ์ˆ˜ํ–‰๋˜๋Š” ๋™์•ˆ ํ•ด๋‹น ๋ฐ์ดํ„ฐ์— Shared Lock์ด ๊ฑธ๋ฆฌ์ง€ ์•Š๋Š” ๊ณ„์ธต
    • ํŠธ๋žœ์žญ์…˜์— ์ฒ˜๋ฆฌ์ค‘์ด๊ฑฐ๋‚˜, ์•„์ง Commit๋˜์ง€ ์•Š์€ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์ด ์ฝ๋Š” ๊ฒƒ์„ ํ—ˆ์šฉํ•จ
    • ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ์ผ๊ด€์„ฑ์„ ์œ ์ง€ํ•˜๋Š” ๊ฒƒ์ด ๋ถˆ๊ฐ€๋Šฅํ•จ
    • Dirty Read ๋ฐœ์ƒ => ๋ฐ์ดํ„ฐ ์ •ํ•ฉ์„ฑ์— ๋ฌธ์ œ๋ฐœ์ƒ
  • READ COMMITTED (๋ ˆ๋ฒจ 1)
    • SELECT ๋ฌธ์žฅ์ด ์ˆ˜ํ–‰๋˜๋Š” ๋™์•ˆ ํ•ด๋‹น ๋ฐ์ดํ„ฐ์— Shared Lock์ด ๊ฑธ๋ฆฌ๋Š” ๊ณ„์ธต
    • ํŠธ๋žœ์žญ์…˜์ด ์ˆ˜ํ–‰๋˜๋Š” ๋™์•ˆ ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์ด ์ ‘๊ทผํ•  ์ˆ˜ ์—†์–ด ๋Œ€๊ธฐํ•˜๊ฒŒ ๋จ
    • Commit์ด ์ด๋ฃจ์–ด์ง„ ํŠธ๋žœ์žญ์…”๋งŒ ์กฐํšŒ ๊ฐ€๋Šฅ
    • Non-Repeatable Read ๋ฐœ์ƒ
  • REPEATABLE READ (๋ ˆ๋ฐœ 2)
    • ํŠธ๋žœ์žญ์…˜์ด ์™„๋ฃŒ๋  ๋•Œ๊นŒ์ง€ SELECT ๋ฌธ์žฅ์ด ์‚ฌ์šฉ๋˜๋Š” ๋ชจ๋“  ๋ฐ์ดํ„ฐ์— Shared Lock์ด ๊ฑธ๋ฆฌ๋Š” ๊ณ„์ธต
    • ํŠธ๋žœ์žญ์…˜์ด ๋ฒ”์œ„ ๋‚ด์—์„œ ์กฐํšŒํ•œ ๋ฐ์ดํ„ฐ ๋‚ด์šฉ์ด ํ•ญ์ƒ ๋™์ผํ•จ์„ ๋ณด์žฅํ•จ
    • ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž๋Š” ํŠธ๋žœ์žญ์…˜ ์˜์—ญ์— ํ•ด๋‹น๋˜๋Š” ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ์ˆ˜์ • ๋ถˆ๊ฐ€๋Šฅ
    • Non-Repeatable Read ๋ถ€์ •ํ•ฉ์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š์Œ
    • ์ž์‹ ์˜ ํŠธ๋žœ์žญ์…˜ ๋ฒˆํ˜ธ๋ณด๋‹ค ๋‚ฎ์€ ํŠธ๋žœ์žญ์…˜ ๋ฒˆํ˜ธ์—์„œ ๋ณ€๊ฒฝ๋œ(์ปค๋ฐ‹๋œ) ๊ฒƒ๋งŒ ๋ณด๊ฒŒ ๋œ๋‹ค.
    • Phantom Read ๋ฐœ์ƒ
  • SERIALIZABLE (๋ ˆ๋ฐœ 3)
    • ํŠธ๋žœ์žญ์…˜์ด ์™„๋ฃŒ๋  ๋–„๊นŒ์ง€ SELECT ๋ฌธ์žฅ์ด ์‚ฌ์šฉ๋˜๋Š” ๋ชจ๋“  ๋ฐ์ดํ„ฐ์— Shared Lock์ด ๊ฑธ๋ฆฌ๋Š” ๊ณ„์ธต
    • ๊ฐ€์žฅ ์—„๊ฒฉํ•œ ๊ฒฉ๋ฆฌ ์ˆ˜์ค€์œผ๋กœ ์™„๋ฒฝํ•œ ์ฝ๊ธฐ ์ผ๊ด€์„ฑ ๋ชจ๋“œ๋ฅผ ์ œ๊ณตํ•จ
    • ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž๋Š” ํŠธ๋žœ์žญ์…˜ ์˜์—ญ์— ํ•ด๋‹น๋˜๋Š” ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ์ˆ˜์ • ๋ฐ ์ž…๋ ฅ ๋ถˆ๊ฐ€๋Šฅ

์•„๋ž˜๋กœ ๋‚ด๋ ค๊ฐˆ์ˆ˜๋ก ํŠธ๋žœ์žญ์…˜๊ฐ„ ๊ณ ๋ฆฝ ์ •๋„๊ฐ€ ๋†’์•„์ง€๋ฉฐ, ์„ฑ๋Šฅ์ด ๋–จ์–ด์ง€๋Š” ๊ฒƒ์ด ์ผ๋ฐ˜์ ์ด๋‹ค.
์ผ๋ฐ˜์ ์ธ ์˜จ๋ผ์ธ ์„œ๋น„์Šค์—์„œ๋Š” READ COMMITTED๋‚˜ REPEATABLE READ ์ค‘ ํ•˜๋‚˜๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
(oracle = READ COMMITTED, mysql = REPEATABLE READ)

# ์„ ํƒ ์‹œ ๊ณ ๋ ค์‚ฌํ•ญ

Isolation Level์— ๋Œ€ํ•œ ์กฐ์ •์€, ๋™์‹œ์„ฑ๊ณผ ๋ฐ์ดํ„ฐ ๋ฌด๊ฒฐ์„ฑ์— ์—ฐ๊ด€๋˜์–ด ์žˆ๋‹ค.

๋™์‹œ์„ฑ์„ ์ฆ๊ฐ€์‹œํ‚ค๋ฉด ๋ฐ์ดํ„ฐ ๋ฌด๊ฒฐ์„ฑ์— ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๊ณ , ๋ฐ์ดํ„ฐ ๋ฌด๊ฒฐ์„ฑ์„ ์œ ์ง€ํ•˜๋ฉด ๋™์‹œ์„ฑ์ด ๋–จ์–ด์ง€๊ฒŒ ๋œ๋‹ค.
=> ํŠธ๋ ˆ์ด๋“œ ์˜คํ”„

# 1022 - ์ด๋ถ„ ํƒ์ƒ‰

  • ์ด์ง„ ํƒ์ƒ‰(์ด๋ถ„ ํƒ์ƒ‰) ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ์ •๋ ฌ๋˜์–ด ์žˆ๋Š” ๋ฆฌ์ŠคํŠธ์—์„œ ํƒ์ƒ‰ ๋ฒ”์œ„๋ฅผ ์ ˆ๋ฐ˜์”ฉ ์ขํ˜€๊ฐ€๋ฉฐ ๋ฐ์ดํ„ฐ๋ฅผ ํƒ์ƒ‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.
  • ์ด์ง„ ํƒ์ƒ‰์€ ๋ฐฐ์—ด ๋‚ด๋ถ€์˜ ๋ฐ์ดํ„ฐ๊ฐ€ ์ •๋ ฌ๋˜์–ด ์žˆ์–ด์•ผ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋‹ค.
  • ๋ณ€์ˆ˜ 3๊ฐœ(start, end, mid)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํƒ์ƒ‰ํ•œ๋‹ค. ์ฐพ์œผ๋ ค๋Š” ๋ฐ์ดํ„ฐ์™€ ์ค‘๊ฐ„์  ์œ„์น˜์— ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜๋ณต์ ์œผ๋กœ ๋น„๊ตํ•ด์„œ ์›ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ๋Š” ๊ฒƒ์ด ์ด์ง„ ํƒ์ƒ‰์˜ ๊ณผ์ •์ด๋‹ค.
  • ์‹œ๊ฐ„ ๋ณต์žก๋„๋Š” O(logN) ์ด๋‹ค.

# ์ž๋ฐ” ๊ตฌํ˜„

  • ์ผ๋ฐ˜์ ์ธ ์ด๋ถ„ ํƒ์ƒ‰ ๊ตฌํ˜„
private static boolean find(int num, int[] arr) {
    // left
    int l = 0;
    // right
    int r = arr.length-1;

    while(l <= r) {
        int mid = (l+r) / 2;
        if(arr[mid] == num) {
            return true;            
        } else if (arr[mid] > num) {
            r = mid-1;
        } else {
            l = mid+1;
        }
    }
    return false;
} 
  • Lower Bound, Upper Bound ๊ตฌํ˜„
private static int lowerBound(int num){
    int l = 0;
    int r = arr.length;

    while(l<r){
        int mid = (l+r)/2;

        if(arr[mid] >= num){
            r = mid;
        } else {
            l = mid + 1;
        }
    }
return l;
}

private static int upperBound(int num){
    int l = 0;
    int r = arr.length;

    while(l<r){
        int mid = (l+r)/2;
        if(arr[mid] <= num){
            l = mid + 1;
        } else {
            r = mid;
        }
    }
    return l;
}   

# 1023 - [๋ฐฑ์—”๋“œ ๊ธฐ๋ณธ]๋ฒ„์ „๊ด€๋ฆฌ ์‹œ์Šคํ…œ๊ณผ ๋ฒ„์ „ ๊ด€๋ฆฌ ์›นํ˜ธ์ŠคํŒ… ์„œ๋น„์Šค ๊ฒฐ์ •

# ๋ฒ„์ „ ๊ด€๋ฆฌ ์‹œ์Šคํ…œ

  • ์‚ฌ์šฉ์ด์œ  : ์‹œ์Šคํ…œ์˜ ๋„์›€์„ ๋ฐ›์•„ ํ˜‘์—…์„ ์›ํ™œ์ด ํ•˜๋Š” ๊ฒƒ
  • ๋ณ€๊ฒฝ์„ ์‰ฝ๊ฒŒ ๋˜๋Œ๋ฆด ์ˆ˜ ์žˆ๋‹ค.
  • git, svn, mercurial

# ๋ฒ„์ „๊ด€๋ฆฌ ์›นํ˜ธ์ŠคํŒ… ์„œ๋น„์Šค

  • ์ฝ”๋“œ๋ฅผ ์ €์žฅํ•  ์„œ๋ฒ„
  • hook์„ ํ†ตํ•ด ํ…Œ์ŠคํŠธ์‹คํ–‰ ๋ฐ ์ž๋™ํ™” ๋ฐฐํฌ
  • pull request
  • github, gitlab, bitbucket
  • github : ์ด์Šˆ ํŠธ๋ž˜์ปค(GitHub Issues), Projects, ZenHubํ”Œ๋Ÿฌ๊ทธ์ธ
    • ํŠน์ • ๋ธŒ๋žœ์น˜๋ฅผ ํ–ฅํ•œ pull request์— ๋Œ€ํ•ด n๊ฐœ ์ด์ƒ์˜ ๋ฆฌ๋ทฐ๋ฅผ ๋ฐ›์•„์•ผ mergeํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ
    • Organization์—์„œ ํŒ€์„ ๋งŒ๋“ค์–ด ์‚ฌ์šฉ์ž๋ฅผ ํฌํ•จ์‹œํ‚ค๊ณ , ํŒ€๋‹จ์œ„๋กœ ์ €์žฅ์†Œ์— ๊ฐ๊ฐ์— read/write/admin ๊ถŒํ•œ๋ถ€์—ฌ, ์„œ๋ธŒ ํŒ€์„ ๋งŒ๋“ค์–ด ๋” ์„ธ๋ถ€์ ์ธ ์œ„๊ณ„

# Git GUI

  • github desktop
  • source tree
  • gitkraken

# 1024 - [๋ฐฑ์—”๋“œ ๊ธฐ๋ณธ]๊ฐœ๋ฐœ ํ”„๋กœ์„ธ์Šค ์ •๋ฆฝ

# ๊ฐœ๋ฐœ ํ”„๋กœ์„ธ์Šค ์ •๋ฆฝ์ด๋ž€?

  • ๊ฐœ๋ฐœ ํ”„๋กœ์„ธ์Šค๋Š” ์–ด๋–ป๊ฒŒ ์ด์Šˆ๋ฅผ ๊ด€๋ฆฌํ•˜๊ณ , ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ์ž‘์—…์„ ์ง„ํ–‰ํ•˜๊ณ , ์™„๋ฃŒ๋œ ์ž‘์—…์€ ์–ด๋–ค ๊ณผ์ •์„ ๊ฑฐ์ณ์„œ ์‹ค์ œ ์ œํ’ˆ์— ๋ฐ˜์˜์‹œํ‚ฌ์ง€์™€ ๊ฐ™์€ ๊ฒƒ๋“ค์„ ๊ทœ์น™ํ™” ์‹œํ‚จ ๊ฒƒ์ด๋‹ค.
    • ์ž‘์—…๋“ค์ด ์–ด๋–ค ์ƒํƒœ์ธ์ง€(์ค€๋น„ ์ค‘/์ง„ํ–‰ ์ค‘/์™„๋ฃŒ)
    • ์ด์Šˆ๋ฅผ ์‹ค์ œ๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ์ž…์žฅ์—์„œ, ๊ฐœ๋ฐœ ํ”„๋กœ์„ธ์Šค์— ๋”ฐ๋ผ ์ž‘์—…์„ ์ง„ํ–‰ํ•˜๋ฉด ์–ด๋Š ๋ธŒ๋žœ์น˜์—์„œ ์–ด๋–ค ์ด๋ฆ„์œผ๋กœ ๋ธŒ๋žœ์น˜๋ฅผ ์ƒ์„ฑํ• ์ง€/์–ด๋Š ๋ธŒ๋žœ์น˜๋กœ pull request๋ฅผ ์˜ฌ๋ฆฌ๋ฉฐ ๋ฆฌ๋ทฐ๋ฅผ ๋ฐ›์•„์•ผ ํ• ์ง€/master merge ํ›„ ์–ด๋–ค ํ›„์† ์ž‘์—…์„ ์ง„ํ–‰ํ•ด์•ผ ํ•˜๋Š”์ง€์™€ ๊ฐ™์€ ๊ณ ๋ฏผ์„ ์ค„์ผ ์ˆ˜ ์žˆ๋”ฐ. ์‹ค์ œ๋กœ ์ž‘์„ฑํ•˜๋Š” ์ฝ”๋“œ์—๋งŒ ์ง‘์ค‘ํ•˜๋Š” ํ™˜๊ฒฝ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.
    • ์ž˜ ์ •๋ฆฝ๋œ ๊ฐœ๋ฐœ ํ”„๋กœ์„ธ์Šค๋Š” ์ƒ์‚ฐ์„ฑ์„ ๋†’์ด๋Š” ๊ฒƒ์— ๊ธฐ์—ฌํ•˜๋ฉฐ, ์ž‘์—…์˜ ์ง„ํ–‰์„ ๋งค๋„๋Ÿฝ๊ฒŒ ๋งŒ๋“ค๊ณ , ๊ฒฐ๊ณผ๋ฌผ์˜ ํ€„๋ฆฌํ‹ฐ๋ฅผ ๋†’์ธ๋‹ค.

# ์ด์Šˆ ๊ด€๋ฆฌ ๋„๊ตฌ

  • ์ž‘์—…์ž๋ฅผ assign
  • ์ด์Šˆ์— ๋Œ€ํ•ด ์ปค๋ฎค๋‹ˆ์ผ€์ด์…˜
  • ํƒœ๊ทธ/๋ผ๋ฒจ ๋“ฑ์œผ๋กœ ์ด์Šˆ์˜ ์ข…๋ฅ˜๋ฅผ ๊ตฌ๋ถ„
  • ์ด์Šˆ์˜ ์ƒํƒœ๋ฅผ ํ†ตํ•ด ์‹œ๊ฐํ™”
  • ๋˜๋„๋ก GitHub ๋‚ด์—์„œ ํ•ด๊ฒฐ
  • Asana, Jira, Trello, GitHub Issues & Projects
  • GitHub Issues & Projects
    • assign, issue conversation, customized label, filter by label, projects์— issues ์—ฐ๋™, projects์˜ automation ๊ธฐ๋Šฅ์„ ํ†ตํ•ด ์ด์Šˆ ๊ตฌ๋ถ„๊ณผ ์ด์Šˆ ์ƒํƒœ ์ž๋™ ๊ฐฑ์‹ 
    • GitHub Issues์—์„œ ์ด์Šˆ๋ฅผ ๋“ฑ๋กํ•˜๋ฉด ํ•ด๋‹น ์ด์Šˆ์— ๋Œ€ํ•œ ๋ฒˆํ˜ธ๊ฐ€ ๋งค๊ฒจ์ง€๊ณ , ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€์— #123 ๊ฐ™์ด ๋ฒˆํ˜ธ๋ฅผ ๋ช…์‹œ์— ๋‘๋ฉด ์ž๋™์œผ๋กœ ํ•ด๋‹น ์ด์Šˆ๊ฐ€ ๋งํฌ
    • Projects, Issues
Last update: September 13, 2022 21:44
Contributors: ahnjs