<commit_before>-module(eavro_rpc_proto_tests).

-include("eavro.hrl").

-include_lib("eunit/include/eunit.hrl").

parse_flume_proto_test() ->
    Proto = eavro_rpc_proto:parse_protocol_file("../test/data/flume.avpr"),
    ?assertMatch(
       #avro_proto{ ns       = <<"org.apache.flume.source.avro">>,
		    name     = <<"AvroSourceProtocol">>,
		    types    = [_ | _],
		    messages = [#avro_message{} | _],
		    json     = <<_,_/binary>>}, Proto).<commit_msg>Add RPC test against Java e-mail server.<commit_after>-module(eavro_rpc_proto_tests).

-include("eavro.hrl").

-include_lib("eunit/include/eunit.hrl").

parse_flume_proto_test() ->
    Proto = eavro_rpc_proto:parse_protocol_file("../test/data/flume.avpr"),
    ?assertMatch(
       #avro_proto{ ns       = <<"org.apache.flume.source.avro">>,
		    name     = <<"AvroSourceProtocol">>,
		    types    = [_ | _],
		    messages = [#avro_message{} | _],
		    json     = <<_,_/binary>>}, Proto).

call_email_server_test_() ->
    {timeout, 30, 
     fun()->
	     Port = erlang:open_port(
		      {spawn, "mvn exec:java -Dexec.mainClass=\"email.Main\""},
		      [{cd, "../jtest"},
		       {env, []},
		       binary,
		       stream,
		       {parallelism, true},
		       exit_status]),
	     try
		 ok = await_start_finished(Port),
		 {ok, P} = eavro_rpc_fsm:start_link(
			     "localhost", 65111, "../jtest/src/main/avro/mail.avpr"),
		 Ret = eavro_rpc_fsm:call(
			 P, send, 
			 _Args = [ _Rec = [ <<"TOOOO">>, <<"FROOOOOM">>, <<"HELLO">> ] ]),
		 ?assertMatch({ok, <<"Sending ",_/binary>>}, Ret)
	     after
		 erlang:port_close(Port)
	     end
     end}.
    
await_start_finished(Port) ->
    receive
	{Port, {data, <<"Server started",_/binary>>}} -> ok;
	{Port, {data, _}} ->
	    await_start_finished(Port)
    end.
{'fraction_non_alphanumeric': 0.19162011173184357, 'fraction_numerical': 0.003910614525139665, 'mean_word_length': 2.73125, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5754337', 'n_tokens_mistral': 735, 'n_tokens_neox': 665, 'n_words': 96}