Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AWS を使ったシステムのテスト方針 #jawsug #jawsug_niigataken #...

AWS を使ったシステムのテスト方針 #jawsug #jawsug_niigataken #nds60

第60回 長岡IT技術者勉強会資料

Kazumune Katagiri

June 22, 2019
Tweet

More Decks by Kazumune Katagiri

Other Decks in Technology

Transcript

  1. ॳΊͯͷํ΋ͦ͏Ͱͳ͍ํ΋ • ยۅ Ұफ (͔ͨ͗Γ ͔ͣΉͶ) • id: nemuzuka /

    @nemuzuka • Java / Scala / Kotlin(࠷ۙ࢝Ίͨ) • ݸਓࣄۀओ • 95 % ͘Β͍ϦϞʔτ(௕Ԭ)ͰϫʔΫ
  2. ݴ༿ͷఆٛ • Unit Test (UT) • ର৅ͷΫϥε(ϝιου)ͷৼΔ෣͍ͷςετ • Integration Test

    (IT) • API ͷݺͼग़͠ͷৼΔ෣͍ͷςετ • System Test (ST) • ෳ਺ͷ API ͷݺͼग़͠΍ AWS ͷػೳΛ࢖ͬͯϢʔεέʔε͕ ຬ͍ͨͤͯΔ͔ͷςετ
  3. ͋ΔγεςϜͷߏ੒ ALB Fargate RDS SNS1 SQS1 SNS2 subscribe ը໘ଆͷ௨஌༻ Controller

    Service Repository EventPublisher MessagePolling Service EventPublisher Repository ఆظతʹ polling ExternalClient ֎෦αʔϏε
  4. Unit Test • ґଘ͢Δ class ͸ Mock Խ • e.g.

    Controller ͷςετͰ͸ Service ͸ Mock Խ͢Δ • Mock ࢖ͬͨՕॴ͸ݺΜͩ͜ͱ + Ҿ਺ͷ assert Λߦ͏ • Repository ࣮૷ͷςετ͸ H2 ౳࢖ͬͯɺSQL ͷςετΛߦ͏ • AWS / ֎෦αʔϏεΛҙࣝ͢ΔՕॴ͸ແཧʹςετ͠ͳ͍ • AWS ͷ SDK Λ࢖͏ՕॴΛہॴԽ͢Δ • EventPublisher / MessagePolling • Mock αʔόతͳ΋ͷΛཱͯͯ΋͍͍͚Ͳɺ࣮ػͰ֬ೝͨ͠ํ͕࣮֬ • AWS / ֎෦αʔϏεΛҙࣝ͢Δͷ͸ class ͷ࣮૷ଆ • ݺͼग़͠ݩ͸ interface ͚ͩ஌͍ͬͯΕ͹ྑ͍ • ֎෦αʔϏε͕ Test ϞʔυͰςετͰ͖ΔͳΒ΍ͬͨํ͕ྑ͍ Controller Service Repository EventPublisher MessagePolling ExternalClient ɹɹɹ : ςετΫϥεΛ࡞Δ୯Ґ DomainModel ValueObject
  5. Integration Test • جຊతʹ͸࣮ࡍͷ object Λ࢖͏ • Repository ͸ H2

    ͱ͔࢖͏ • ςετέʔεͷதͰ table ͷ assert ΋ߦ͏ • AWS / ֎෦αʔϏεΛҙࣝ͢ΔՕॴ͸ Mock Խ • ֎෦αʔϏε͕ Test ϞʔυͰςετͰ͖ΔͳΒ࣮ࡍ ͷ object Λ࢖ͬͯ௨৴ͯ͠΋ྑ͍ • γφϦΦͬΆ͘ API Λ૊Έ߹ΘͤͨςετέʔεΛ࡞ͬ ͯ΋ྑ͍ • Controller ݺͼग़͠ -> (SQS ͔ΒͷϝοηʔδΛऔͬ ͖ͯͨςΠͰ) Service ݺͼग़͠ Controller Service Repository EventPublisher MessagePolling Service EventPublisher Repository ExternalClient ɹɹɹ : ςετΫϥεΛ࡞Δ୯Ґ : ςετΫϥεͷ։࢝Ґஔ
  6. System Test • AWS ্ʹຊ൪ͱಉ͡ ߏ੒ͷ ST ؀ڥΛ࡞Δ • ST

    ؀ڥʹ Docker Image ΛσϓϩΠ • ST ؀ڥͷ API Λςε τΫϥε͔Βݺͼग़͢ ALB Fargate RDS SNS1 SQS1 SNS2 ֎෦αʔϏε
  7. ςετίʔυͷ؅ཧͱ࣮ߦλΠϛϯά • ςετίʔυ͸ϓϩμΫγϣϯίʔυ ͱҰॹͷϦϙδτϦͰ؅ཧ • feature branch Λ push ͨ࣌͠ʹ

    CircleCI ্Ͱςετ࣮ࢪ • merge ৚݅͸ϨϏϡʔͱ CircleCI ͷςετʹ pass ͢Δ͜ͱ • ςετʹ pass ͢Δͱ Docker Image ͕Ͱ͖Δ • System Test ༻ͷγφϦΦΛ؅ཧ͢ ΔϦϙδτϦΛ༻ҙ • Test Ϋϥε͚ͩͷϦϙδτϦ • System Test ؀ڥʹ Docker Image ΛσϓϩΠͯ͠ɺTest ࣮ߦ(CircleCI) • ຖ೔ఆظతʹ System Test Λ࣮ߦ ͠ɺςετ͕௨Δ͔Λ֬ೝ͢Δ Unit Test / Integration Test System Test
  8. SQS • ෳ਺ճϝοηʔδ͕औΕΔ͜ͱ͕͋Δ / ॱং͕อূ͞Εͳ͍ • FIFO ΋͋Δ͚Ͳεϧʔϓοτ͕… • ॏෳΛආ͚ΔͷͰ͸ͳ͘ɺෳ਺ճϝοηʔδ͕औΕͯ΋େৎ෉

    ͳΑ͏ʹઃܭ͢Δ • e.g. ॲཧΛߦ͏લఏ৚݅Λຬͨ͞ͳ͍৔߹ɺࣺͯΔ • e.g. ॲཧதͷεςʔλεͷ৔߹ɺϦΫΤετΛड͚෇͚ͳ ͍
  9. RDS(ͱ͍͏͔ MySQL) • ద੾ʹ index షΖ͏ • Πϯελϯε͋͛ͯ΋ SSD Ͱ΋݅਺૿͑Δͱμϝͳ࣌͸μϝ

    • τϥϯβΫγϣϯ෼཭Ϩϕϧҙࣝ͠Α͏ • MySQL ͷ REPEATABLE READ Ͱߋ৽ॲཧͷεϧʔϓοτग़ͤΔͷ…͔ʁ • Oracle ͬΆ͘ MySQL ࢖͏ͱେମϠέυ͢Δ ಡΜͩ࣌ؒ͸ଛ͠ͳ͍ˠ
  10. SQS + RDS • SQS ͷ enqueue ͱ dequeue +

    ॲཧͷλΠϛ ϯάʹؾΛ͚ͭͯ • RDS ͷ commit લʹ enqueue ͯ͠͠· ͍ɺ dequeue ͨ͠ଆͷॲཧͰର৅ͷϨίʔ υ͕ͳ͍…ͱ͍͏͜ͱʹͳΒͳ͍Α͏ʹ
  11. ·ͱΊ • ςετ͸େࣄ͚ͩͲؤுΓ͗͢ͳ͍ • ݕূίʔυͱςετ͸ผɻUT / IT ͰԿͰ΋΍Ζ͏ͱ͠ͳ͍ํ͕ྑ͍ • ੹຿Λ෼͚Ε͹

    UT ΋͠΍͘͢ͳΔɻDI ࢖͑Δํ͕ςετ͠΍͍͢(assert ͕࢓ࠐΈ΍͍͢) • JVM ࢖͏ͳΒ SpringBoot + Kotlin ͕ࠓͷॴݸਓతʹੜ࢈ੑߴ͍ؾ͕͢Δ • AWS ࢖͏ͱָʹͳΔͱ͜Ζ͸ੵۃతʹ࢖͍͖ͬͯ·͠ΐ͏ʂ • ஌ͬͯΕ͹େৎ෉ͳ͜ͱ͕ଟ͍Ͱ͢ɻͨͩɺ؂ࢹͱܭଌ͸ॏཁ • ࣄલʹෛՙςετ͓ͯ͘͠ͱۚͰղܾͰ͖ͳ͍͜ͱʹؾ෇͖΍͍͢Ͱ͢ • όʔδϣϯͷԘ௮͚͸Ͱ͖ͳ͍ͷͰɺςετ͕ແ͍ͱόʔδϣϯ UP ͕͠ΜͲ͍Ͱ͢ • UI ଆ(εϚϑΥΞϓϦ / ϒϥ΢β)ͷࠓ࣌ͷςετͬͯͲ͏΍ͬͯΔͷ͔ඇৗʹؾʹͳΓ·͢ʂ