Add test/machi_pb_test.erl, finish PB refactoring
This commit is contained in:
parent
a82bd68f3c
commit
40c0a72b48
4 changed files with 99 additions and 33 deletions
BIN
rebar
vendored
BIN
rebar
vendored
Binary file not shown.
|
@ -4,9 +4,6 @@
|
||||||
{erl_opts, [{parse_transform, lager_transform}, debug_info]}.
|
{erl_opts, [{parse_transform, lager_transform}, debug_info]}.
|
||||||
{edoc_opts, [{dir, "./edoc"}]}.
|
{edoc_opts, [{dir, "./edoc"}]}.
|
||||||
|
|
||||||
{plugins, [riak_pb_msgcodegen]}.
|
|
||||||
{plugin_dir, "plugins"}.
|
|
||||||
|
|
||||||
{deps, [
|
{deps, [
|
||||||
{lager, ".*", {git, "git://github.com/basho/lager.git", {tag, "2.0.1"}}},
|
{lager, ".*", {git, "git://github.com/basho/lager.git", {tag, "2.0.1"}}},
|
||||||
{protobuffs, "0.8.*", {git, "git://github.com/basho/erlang_protobuffs.git", {tag, "0.8.1p4"}}}
|
{protobuffs, "0.8.*", {git, "git://github.com/basho/erlang_protobuffs.git", {tag, "0.8.1p4"}}}
|
||||||
|
|
|
@ -35,7 +35,7 @@ option java_outer_classname = "MachiPB";
|
||||||
//
|
//
|
||||||
//////////////////////////////////////////
|
//////////////////////////////////////////
|
||||||
|
|
||||||
enum MpbGeneralStatusCode {
|
enum Mpb_GeneralStatusCode {
|
||||||
OK = 0;
|
OK = 0;
|
||||||
BAD_ARG = 1;
|
BAD_ARG = 1;
|
||||||
WEDGED = 2;
|
WEDGED = 2;
|
||||||
|
@ -43,7 +43,7 @@ enum MpbGeneralStatusCode {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Must match with machi.hrl's values!
|
// Must match with machi.hrl's values!
|
||||||
enum MpbCSumType {
|
enum Mpb_CSumType {
|
||||||
CSUM_TAG_NONE = 0;
|
CSUM_TAG_NONE = 0;
|
||||||
CSUM_TAG_CLIENT_GEN = 1;
|
CSUM_TAG_CLIENT_GEN = 1;
|
||||||
CSUM_TAG_SERVER_GEN = 2;
|
CSUM_TAG_SERVER_GEN = 2;
|
||||||
|
@ -57,28 +57,22 @@ enum MpbCSumType {
|
||||||
//////////////////////////////////////////
|
//////////////////////////////////////////
|
||||||
|
|
||||||
// chunk_pos() type
|
// chunk_pos() type
|
||||||
message MpbChunkPos {
|
message Mpb_ChunkPos {
|
||||||
required uint64 offset = 1;
|
required uint64 offset = 1;
|
||||||
required uint64 chunk_size = 2;
|
required uint64 chunk_size = 2;
|
||||||
required string file_name = 3;
|
required string file_name = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// chunk_csum() type
|
// chunk_csum() type
|
||||||
message MpbChunkCSum {
|
message Mpb_ChunkCSum {
|
||||||
required MpbCSumType type = 1;
|
required Mpb_CSumType type = 1;
|
||||||
required bytes csum = 2;
|
required bytes csum = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// epoch_id() type
|
// epoch_id() type
|
||||||
message MpbEpochId {
|
message Mpb_EpochId {
|
||||||
required uint32 epoch_num = 1;
|
required uint32 epoch_num = 1;
|
||||||
required MpbChunkCSum epoch_csum = 2;
|
required Mpb_ChunkCSum epoch_csum = 2;
|
||||||
}
|
|
||||||
|
|
||||||
// Error response - may be generated for any Req
|
|
||||||
message MpbErrorResp {
|
|
||||||
required string errmsg = 1;
|
|
||||||
required uint32 errcode = 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////
|
//////////////////////////////////////////
|
||||||
|
@ -87,40 +81,48 @@ message MpbErrorResp {
|
||||||
//
|
//
|
||||||
//////////////////////////////////////////
|
//////////////////////////////////////////
|
||||||
|
|
||||||
|
// Error response - may be generated for any Req
|
||||||
|
message Mpb_ErrorResp {
|
||||||
|
// Free-form (depends on server, which is probably a bad idea TODO)
|
||||||
|
required int32 code = 1;
|
||||||
|
required string msg = 2;
|
||||||
|
optional bytes extra = 3;
|
||||||
|
}
|
||||||
|
|
||||||
// ping() request & response
|
// ping() request & response
|
||||||
|
|
||||||
message MpbEchoReq {
|
message Mpb_EchoReq {
|
||||||
optional string message = 1;
|
optional string message = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message MpbEchoResp {
|
message Mpb_EchoResp {
|
||||||
optional string message = 1;
|
optional string message = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Authentication request & response
|
// Authentication request & response
|
||||||
|
|
||||||
message MpbAuthReq {
|
message Mpb_AuthReq {
|
||||||
required bytes user = 1;
|
required bytes user = 1;
|
||||||
required bytes password = 2;
|
required bytes password = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message MpbAuthResp {
|
message Mpb_AuthResp {
|
||||||
required uint32 code = 1;
|
required uint32 code = 1;
|
||||||
// TODO: not implemented yet
|
// TODO: not implemented yet
|
||||||
}
|
}
|
||||||
|
|
||||||
// append_chunk() request & response
|
// append_chunk() request & response
|
||||||
|
|
||||||
message MpbAppendChunkReq {
|
message Mpb_AppendChunkReq {
|
||||||
required string prefix = 1;
|
required string prefix = 1;
|
||||||
optional bytes placement_key = 2;
|
optional bytes placement_key = 2;
|
||||||
required bytes chunk = 3;
|
required bytes chunk = 3;
|
||||||
optional uint32 chunk_extra = 4;
|
optional uint32 chunk_extra = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message MpbAppendChunkResp {
|
message Mpb_AppendChunkResp {
|
||||||
required MpbGeneralStatusCode status = 1;
|
required Mpb_GeneralStatusCode status = 1;
|
||||||
optional MpbChunkPos chunk_pos = 2;
|
optional Mpb_ChunkPos chunk_pos = 2;
|
||||||
optional MbpGeneralError = 3;
|
optional MbpGeneralError = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +132,7 @@ message MpbAppendChunkResp {
|
||||||
//
|
//
|
||||||
//////////////////////////////////////////
|
//////////////////////////////////////////
|
||||||
|
|
||||||
message MpbRequest_v1 {
|
message Mpb_Request {
|
||||||
// TODO: If we wish to support pipelined requests sometime in the
|
// TODO: If we wish to support pipelined requests sometime in the
|
||||||
// future, this is the placeholder to do it.
|
// future, this is the placeholder to do it.
|
||||||
required bytes req_id = 1;
|
required bytes req_id = 1;
|
||||||
|
@ -141,12 +143,12 @@ message MpbRequest_v1 {
|
||||||
// NOTE: The erlang protobuffs compiler doesn't support 'oneof'.
|
// NOTE: The erlang protobuffs compiler doesn't support 'oneof'.
|
||||||
// But 'oneof' appears to be a very tiny memory optimization
|
// But 'oneof' appears to be a very tiny memory optimization
|
||||||
// that not all languages might care about? (Erlang doesn't)
|
// that not all languages might care about? (Erlang doesn't)
|
||||||
optional MpbEchoReq echo = 10;
|
optional Mpb_EchoReq echo = 10;
|
||||||
optional MpbAuthReq auth = 11;
|
optional Mpb_AuthReq auth = 11;
|
||||||
optional MpbAppendChunkReq append_chunk = 12;
|
optional Mpb_AppendChunkReq append_chunk = 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
message MpbResponse_v1 {
|
message Mpb_Response {
|
||||||
// TODO: If we wish to support pipelined requests sometime in the
|
// TODO: If we wish to support pipelined requests sometime in the
|
||||||
// future, this is the placeholder to do it.
|
// future, this is the placeholder to do it.
|
||||||
required bytes req_id = 1;
|
required bytes req_id = 1;
|
||||||
|
@ -157,10 +159,10 @@ message MpbResponse_v1 {
|
||||||
// bad/unexpected happened within the server.
|
// bad/unexpected happened within the server.
|
||||||
// Clients should always check this response and, if defined,
|
// Clients should always check this response and, if defined,
|
||||||
// ignroe any request-specific response at codes 10+.
|
// ignroe any request-specific response at codes 10+.
|
||||||
optional MpbErrorResp = 2;
|
optional Mpb_ErrorResp generic = 2;
|
||||||
|
|
||||||
// Specific responses.
|
// Specific responses.
|
||||||
optional MpbEchoResp echo = 10;
|
optional Mpb_EchoResp echo = 10;
|
||||||
optional MpbAuthResp auth = 11;
|
optional Mpb_AuthResp auth = 11;
|
||||||
optional MpbAppendChunkResp append_chunk = 12;
|
optional Mpb_AppendChunkResp append_chunk = 12;
|
||||||
}
|
}
|
||||||
|
|
67
test/machi_pb_test.erl
Normal file
67
test/machi_pb_test.erl
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
%% -------------------------------------------------------------------
|
||||||
|
%%
|
||||||
|
%% Machi: a small village of replicated files
|
||||||
|
%%
|
||||||
|
%% Copyright (c) 2014-2015 Basho Technologies, Inc. All Rights Reserved.
|
||||||
|
%%
|
||||||
|
%% This file is provided to you under the Apache License,
|
||||||
|
%% Version 2.0 (the "License"); you may not use this file
|
||||||
|
%% except in compliance with the License. You may obtain
|
||||||
|
%% a copy of the License at
|
||||||
|
%%
|
||||||
|
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
%%
|
||||||
|
%% Unless required by applicable law or agreed to in writing,
|
||||||
|
%% software distributed under the License is distributed on an
|
||||||
|
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
%% KIND, either express or implied. See the License for the
|
||||||
|
%% specific language governing permissions and limitations
|
||||||
|
%% under the License.
|
||||||
|
%%
|
||||||
|
%% -------------------------------------------------------------------
|
||||||
|
-module(machi_pb_test).
|
||||||
|
|
||||||
|
-include("machi_pb.hrl").
|
||||||
|
|
||||||
|
-compile(export_all).
|
||||||
|
|
||||||
|
-ifdef(TEST).
|
||||||
|
-ifndef(PULSE).
|
||||||
|
|
||||||
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
|
%% We don't expect any problems with these functions: nearly all
|
||||||
|
%% code executed is compiled from the PB definition file(s) and so
|
||||||
|
%% ought to be bug-free. Errors are likely to be caused by
|
||||||
|
%% changes in the spec but without corresponding changes to
|
||||||
|
%% message types/names here.
|
||||||
|
|
||||||
|
smoke_requests_test() ->
|
||||||
|
Echo0 = #mpb_request{req_id= <<"x">>,
|
||||||
|
echo=#mpb_echoreq{}},
|
||||||
|
Echo0 = encdec_request(Echo0),
|
||||||
|
Echo1 = #mpb_request{req_id= <<"x">>,
|
||||||
|
echo=#mpb_echoreq{message="Yo!"}},
|
||||||
|
Echo1 = encdec_request(Echo1),
|
||||||
|
|
||||||
|
ok.
|
||||||
|
|
||||||
|
smoke_responses_test() ->
|
||||||
|
R1 = #mpb_response{req_id= <<"x">>,
|
||||||
|
generic=#mpb_errorresp{code=7,
|
||||||
|
msg="foo",
|
||||||
|
extra= <<"bar">>}},
|
||||||
|
R1 = encdec_response(R1),
|
||||||
|
|
||||||
|
ok.
|
||||||
|
|
||||||
|
encdec_request(M) ->
|
||||||
|
machi_pb:decode_mpb_request(
|
||||||
|
list_to_binary(machi_pb:encode_mpb_request(M))).
|
||||||
|
|
||||||
|
encdec_response(M) ->
|
||||||
|
machi_pb:decode_mpb_response(
|
||||||
|
list_to_binary(machi_pb:encode_mpb_response(M))).
|
||||||
|
|
||||||
|
-endif. % !PULSE
|
||||||
|
-endif. % TEST
|
Loading…
Reference in a new issue