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

Javaの実装をPerlでテストする

 Javaの実装をPerlでテストする

Avatar for karupanerura

karupanerura

March 19, 2023
Tweet

More Decks by karupanerura

Other Decks in Programming

Transcript

  1. @karupanerura • DeNA Co., LTD - Software Engineer • Japan

    Perl Association - Chief Director • Perl / Go / Java / Type Script / etc...
  2. Plack::Testͷྫ test_psgi client => sub { my $cb = shift;

    my $req = HTTP::Request->new(GET => "http://localhost/hello"); my $res = $cb->($req); is $res->content, 'Hello World'; is $res->content_type, 'text/plain'; is $res->code, 200; }, app => sub { my $env = shift; return [ 200, [ 'Content-Type' => 'text/plain' ], [ "Hello World" ] ]; };
  3. Plack::Testͷྫ test_psgi client => sub { my $cb = shift;

    my $req = HTTP::Request->new(GET => "http://localhost/hello"); my $res = $cb->($req); is $res->content, 'Hello World'; is $res->content_type, 'text/plain'; is $res->code, 200; }, app => sub { my $env = shift; return [ 200, [ 'Content-Type' => 'text/plain' ], [ "Hello World" ] ]; };
  4. Plack::Testͷྫ test_psgi client => sub { my $cb = shift;

    my $req = HTTP::Request->new(GET => "http://localhost/hello"); my $res = $cb->($req); # <---------- focus here is $res->content, 'Hello World'; is $res->content_type, 'text/plain'; is $res->code, 200; }, app => sub { my $env = shift; return [ 200, [ 'Content-Type' => 'text/plain' ], [ "Hello World" ] ]; };
  5. ͜͏͍͏ײ͡ͷίʔυ͕͋Δ my $sent = 0; my $guard = Test::Mock::Guard->new( 'MyEmailSender'

    => { send => sub { $sent++ } }, ); my $res = $doit->($req); is $sent, 1, 'ϝʔϧΛ1௨͓ͬͨ͘Α';
  6. select(2)Λ࢖ͬͨղ๏ • Internal API΁ͷϦΫΤετΛड͚औΔSocketΛListen͢Δ • HTTP ClientͰJavaʹϦΫΤετΛ౤͛ͨΒselect(2)Ͱ଴ͭ • Internal API΁ͷϦΫΤετ͕དྷΔ

    or Java͔ΒϨεϙϯε͕དྷΔ • Listenͨ͠Socket͕ى͖ͨΒInternal APIΛॲཧͯ͠·ͨselect(2) • Java͔ΒϨεϙϯε͕དྷͨΒऴྃ
  7. Ͳ͏΍ͬͯ΍ͬͯΔͷ • LWP(HTTP Client)Λຐվ଄ͭͭ͠Starlet(PSGI Server)Λѱ༻͢Δ • LWP::Protocol::httpsΛܧঝͨ͠ΦϨΦϨprotocolΛͭͬͯ͘޷͖์୊ • Starlet::Server#accept_loop͸max reqs

    per childΛ1ʹͯ͠ݺͼग़͢ • Server::Starter༻ʹ༻ҙ͞Εͨlistenersʹࣗ෼Ͱ࡞ͬͨSocketΛ౉͢ • acceptͯ͠ϦΫΤετΛॲཧ͢Δ·ͰStarletͰશࣗಈ