thrift 0.0.751142 → 0.0.810255.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/CHANGELOG +3 -1
  2. data/Manifest +47 -44
  3. data/README +19 -6
  4. data/Rakefile +1 -1
  5. data/benchmark/Benchmark.thrift +19 -0
  6. data/benchmark/benchmark.rb +20 -3
  7. data/benchmark/client.rb +20 -2
  8. data/benchmark/server.rb +22 -4
  9. data/benchmark/thin_server.rb +22 -4
  10. data/ext/binary_protocol_accelerated.c +32 -21
  11. data/ext/binary_protocol_accelerated.h +19 -0
  12. data/ext/compact_protocol.c +665 -0
  13. data/ext/compact_protocol.h +20 -0
  14. data/ext/constants.h +19 -1
  15. data/ext/extconf.rb +19 -0
  16. data/ext/macros.h +41 -0
  17. data/ext/memory_buffer.c +29 -5
  18. data/ext/memory_buffer.h +19 -0
  19. data/ext/protocol.c +20 -1
  20. data/ext/protocol.h +19 -0
  21. data/ext/struct.c +115 -83
  22. data/ext/struct.h +19 -0
  23. data/ext/thrift_native.c +23 -2
  24. data/lib/thrift/client.rb +19 -1
  25. data/lib/thrift/core_ext/fixnum.rb +29 -0
  26. data/lib/thrift/core_ext.rb +23 -0
  27. data/lib/thrift/exceptions.rb +19 -2
  28. data/lib/thrift/processor.rb +19 -1
  29. data/lib/thrift/protocol/base_protocol.rb +290 -0
  30. data/lib/thrift/protocol/{binaryprotocol.rb → binary_protocol.rb} +27 -15
  31. data/lib/thrift/protocol/binary_protocol_accelerated.rb +35 -0
  32. data/lib/thrift/protocol/compact_protocol.rb +422 -0
  33. data/lib/thrift/serializer/deserializer.rb +33 -0
  34. data/lib/thrift/serializer/serializer.rb +34 -0
  35. data/lib/thrift/server/base_server.rb +31 -0
  36. data/lib/thrift/server/{httpserver.rb → mongrel_http_server.rb} +19 -5
  37. data/lib/thrift/server/{nonblockingserver.rb → nonblocking_server.rb} +42 -24
  38. data/lib/thrift/server/simple_server.rb +43 -0
  39. data/lib/thrift/server/thread_pool_server.rb +75 -0
  40. data/lib/thrift/server/threaded_server.rb +47 -0
  41. data/lib/thrift/struct.rb +73 -47
  42. data/lib/thrift/thrift_native.rb +24 -0
  43. data/lib/thrift/transport/base_server_transport.rb +37 -0
  44. data/lib/thrift/transport/base_transport.rb +70 -0
  45. data/lib/thrift/transport/buffered_transport.rb +77 -0
  46. data/lib/thrift/transport/framed_transport.rb +90 -0
  47. data/lib/thrift/transport/http_client_transport.rb +45 -0
  48. data/lib/thrift/transport/io_stream_transport.rb +39 -0
  49. data/lib/thrift/transport/memory_buffer_transport.rb +96 -0
  50. data/lib/thrift/transport/server_socket.rb +63 -0
  51. data/lib/thrift/transport/socket.rb +22 -53
  52. data/lib/thrift/transport/unix_server_socket.rb +60 -0
  53. data/lib/thrift/transport/unix_socket.rb +40 -0
  54. data/lib/thrift/types.rb +20 -2
  55. data/lib/thrift.rb +50 -19
  56. data/script/proto_benchmark.rb +121 -0
  57. data/script/read_struct.rb +43 -0
  58. data/script/write_struct.rb +30 -0
  59. data/spec/ThriftSpec.thrift +40 -2
  60. data/spec/{protocol_spec.rb → base_protocol_spec.rb} +25 -7
  61. data/spec/{transport_spec.rb → base_transport_spec.rb} +44 -52
  62. data/spec/binary_protocol_accelerated_spec.rb +41 -0
  63. data/spec/{binaryprotocol_spec.rb → binary_protocol_spec.rb} +20 -2
  64. data/spec/{binaryprotocol_spec_shared.rb → binary_protocol_spec_shared.rb} +117 -16
  65. data/spec/client_spec.rb +23 -4
  66. data/spec/compact_protocol_spec.rb +117 -0
  67. data/spec/exception_spec.rb +19 -0
  68. data/spec/http_client_spec.rb +49 -0
  69. data/spec/{httpserver_spec.rb → mongrel_http_server_spec.rb} +26 -7
  70. data/spec/{nonblockingserver_spec.rb → nonblocking_server_spec.rb} +25 -5
  71. data/spec/processor_spec.rb +19 -0
  72. data/spec/serializer_spec.rb +27 -10
  73. data/spec/server_socket_spec.rb +80 -0
  74. data/spec/server_spec.rb +35 -16
  75. data/spec/socket_spec.rb +19 -55
  76. data/spec/socket_spec_shared.rb +19 -0
  77. data/spec/spec_helper.rb +34 -9
  78. data/spec/struct_spec.rb +26 -18
  79. data/spec/types_spec.rb +19 -1
  80. data/spec/{unixsocket_spec.rb → unix_socket_spec.rb} +19 -1
  81. data/thrift.gemspec +6 -6
  82. data.tar.gz.sig +0 -0
  83. metadata +80 -70
  84. metadata.gz.sig +0 -0
  85. data/COPYING +0 -14
  86. data/LICENSE +0 -14
  87. data/Makefile.am +0 -15
  88. data/benchmark/gen-rb/BenchmarkService.rb +0 -81
  89. data/benchmark/gen-rb/Benchmark_constants.rb +0 -11
  90. data/benchmark/gen-rb/Benchmark_types.rb +0 -10
  91. data/lib/thrift/deprecation.rb +0 -155
  92. data/lib/thrift/protocol/binaryprotocolaccelerated.rb +0 -19
  93. data/lib/thrift/protocol/tbinaryprotocol.rb +0 -2
  94. data/lib/thrift/protocol/tprotocol.rb +0 -2
  95. data/lib/thrift/protocol.rb +0 -270
  96. data/lib/thrift/serializer.rb +0 -27
  97. data/lib/thrift/server/thttpserver.rb +0 -2
  98. data/lib/thrift/server/tserver.rb +0 -2
  99. data/lib/thrift/server.rb +0 -135
  100. data/lib/thrift/thrift.rb +0 -14
  101. data/lib/thrift/transport/httpclient.rb +0 -29
  102. data/lib/thrift/transport/thttpclient.rb +0 -2
  103. data/lib/thrift/transport/tsocket.rb +0 -2
  104. data/lib/thrift/transport/ttransport.rb +0 -2
  105. data/lib/thrift/transport/unixsocket.rb +0 -58
  106. data/lib/thrift/transport.rb +0 -319
  107. data/spec/backwards_compatibility_spec.rb +0 -136
  108. data/spec/binaryprotocolaccelerated_spec.rb +0 -101
  109. data/spec/deprecation_spec.rb +0 -443
  110. data/spec/gen-rb/NonblockingService.rb +0 -268
  111. data/spec/gen-rb/ThriftSpec_constants.rb +0 -11
  112. data/spec/gen-rb/ThriftSpec_types.rb +0 -134
  113. data/spec/httpclient_spec.rb +0 -31
@@ -0,0 +1,39 @@
1
+ # encoding: ascii-8bit
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+ #
20
+
21
+ # Very very simple implementation of wrapping two objects, one with a #read
22
+ # method and one with a #write method, into a transport for thrift.
23
+ #
24
+ # Assumes both objects are open, remain open, don't require flushing, etc.
25
+ #
26
+ module Thrift
27
+ class IOStreamTransport < BaseTransport
28
+ def initialize(input, output)
29
+ @input = input
30
+ @output = output
31
+ end
32
+
33
+ def open?; not @input.closed? or not @output.closed? end
34
+ def read(sz); @input.read(sz) end
35
+ def write(buf); @output.write(buf) end
36
+ def close; @input.close; @output.close end
37
+ def to_io; @input end # we're assuming this is used in a IO.select for reading
38
+ end
39
+ end
@@ -0,0 +1,96 @@
1
+ # encoding: ascii-8bit
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+ #
20
+
21
+ module Thrift
22
+ class MemoryBufferTransport < BaseTransport
23
+ GARBAGE_BUFFER_SIZE = 4*(2**10) # 4kB
24
+
25
+ # If you pass a string to this, you should #dup that string
26
+ # unless you want it to be modified by #read and #write
27
+ #--
28
+ # this behavior is no longer required. If you wish to change it
29
+ # go ahead, just make sure the specs pass
30
+ def initialize(buffer = nil)
31
+ @buf = buffer || ''
32
+ @index = 0
33
+ end
34
+
35
+ def open?
36
+ return true
37
+ end
38
+
39
+ def open
40
+ end
41
+
42
+ def close
43
+ end
44
+
45
+ def peek
46
+ @index < @buf.size
47
+ end
48
+
49
+ # this method does not use the passed object directly but copies it
50
+ def reset_buffer(new_buf = '')
51
+ @buf.replace new_buf
52
+ @index = 0
53
+ end
54
+
55
+ def available
56
+ @buf.length - @index
57
+ end
58
+
59
+ def read(len)
60
+ data = @buf.slice(@index, len)
61
+ @index += len
62
+ @index = @buf.size if @index > @buf.size
63
+ if @index >= GARBAGE_BUFFER_SIZE
64
+ @buf = @buf.slice(@index..-1)
65
+ @index = 0
66
+ end
67
+ if data.size < len
68
+ raise EOFError, "Not enough bytes remain in buffer"
69
+ end
70
+ data
71
+ end
72
+
73
+ def write(wbuf)
74
+ @buf << wbuf
75
+ end
76
+
77
+ def flush
78
+ end
79
+
80
+ def inspect_buffer
81
+ out = []
82
+ for idx in 0...(@buf.size)
83
+ # if idx != 0
84
+ # out << " "
85
+ # end
86
+
87
+ if idx == @index
88
+ out << ">"
89
+ end
90
+
91
+ out << @buf[idx].to_s(16)
92
+ end
93
+ out.join(" ")
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,63 @@
1
+ # encoding: ascii-8bit
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+ #
20
+
21
+ require 'socket'
22
+
23
+ module Thrift
24
+ class ServerSocket < BaseServerTransport
25
+ # call-seq: initialize(host = nil, port)
26
+ def initialize(host_or_port, port = nil)
27
+ if port
28
+ @host = host_or_port
29
+ @port = port
30
+ else
31
+ @host = nil
32
+ @port = host_or_port
33
+ end
34
+ @handle = nil
35
+ end
36
+
37
+ attr_reader :handle
38
+
39
+ def listen
40
+ @handle = TCPServer.new(@host, @port)
41
+ end
42
+
43
+ def accept
44
+ unless @handle.nil?
45
+ sock = @handle.accept
46
+ trans = Socket.new
47
+ trans.handle = sock
48
+ trans
49
+ end
50
+ end
51
+
52
+ def close
53
+ @handle.close unless @handle.nil? or @handle.closed?
54
+ @handle = nil
55
+ end
56
+
57
+ def closed?
58
+ @handle.nil? or @handle.closed?
59
+ end
60
+
61
+ alias to_io handle
62
+ end
63
+ end
@@ -1,16 +1,27 @@
1
- # Copyright (c) 2006- Facebook
2
- # Distributed under the Apache Software License
3
- #
4
- # See accompanying file LICENSE or visit the Thrift site at:
5
- # http://developers.facebook.com/thrift/
6
- #
7
- # Author: Mark Slee <mcslee@facebook.com>
8
- #
9
- require 'thrift/transport'
1
+ # encoding: ascii-8bit
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+ #
20
+
10
21
  require 'socket'
11
22
 
12
23
  module Thrift
13
- class Socket < Transport
24
+ class Socket < BaseTransport
14
25
  def initialize(host='localhost', port=9090, timeout=nil)
15
26
  @host = host
16
27
  @port = port
@@ -122,46 +133,4 @@ module Thrift
122
133
  @handle
123
134
  end
124
135
  end
125
- deprecate_class! :TSocket => Socket
126
-
127
- class ServerSocket < ServerTransport
128
- # call-seq: initialize(host = nil, port)
129
- def initialize(host_or_port, port = nil)
130
- if port
131
- @host = host_or_port
132
- @port = port
133
- else
134
- @host = nil
135
- @port = host_or_port
136
- end
137
- @handle = nil
138
- end
139
-
140
- attr_reader :handle
141
-
142
- def listen
143
- @handle = TCPServer.new(@host, @port)
144
- end
145
-
146
- def accept
147
- unless @handle.nil?
148
- sock = @handle.accept
149
- trans = Socket.new
150
- trans.handle = sock
151
- trans
152
- end
153
- end
154
-
155
- def close
156
- @handle.close unless @handle.nil? or @handle.closed?
157
- @handle = nil
158
- end
159
-
160
- def closed?
161
- @handle.nil? or @handle.closed?
162
- end
163
-
164
- alias to_io handle
165
- end
166
- deprecate_class! :TServerSocket => ServerSocket
167
- end
136
+ end
@@ -0,0 +1,60 @@
1
+ # encoding: ascii-8bit
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+ #
20
+
21
+ require 'socket'
22
+
23
+ module Thrift
24
+ class UNIXServerSocket < BaseServerTransport
25
+ def initialize(path)
26
+ @path = path
27
+ @handle = nil
28
+ end
29
+
30
+ attr_accessor :handle
31
+
32
+ def listen
33
+ @handle = ::UNIXServer.new(@path)
34
+ end
35
+
36
+ def accept
37
+ unless @handle.nil?
38
+ sock = @handle.accept
39
+ trans = UNIXSocket.new(nil)
40
+ trans.handle = sock
41
+ trans
42
+ end
43
+ end
44
+
45
+ def close
46
+ if @handle
47
+ @handle.close unless @handle.closed?
48
+ @handle = nil
49
+ # UNIXServer doesn't delete the socket file, so we have to do it ourselves
50
+ File.delete(@path)
51
+ end
52
+ end
53
+
54
+ def closed?
55
+ @handle.nil? or @handle.closed?
56
+ end
57
+
58
+ alias to_io handle
59
+ end
60
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: ascii-8bit
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+ #
20
+
21
+ require 'socket'
22
+
23
+ module Thrift
24
+ class UNIXSocket < Socket
25
+ def initialize(path, timeout=nil)
26
+ @path = path
27
+ @timeout = timeout
28
+ @desc = @path # for read()'s error
29
+ @handle = nil
30
+ end
31
+
32
+ def open
33
+ begin
34
+ @handle = ::UNIXSocket.new(@path)
35
+ rescue StandardError
36
+ raise TransportException.new(TransportException::NOT_OPEN, "Could not open UNIX socket at #{@path}")
37
+ end
38
+ end
39
+ end
40
+ end
data/lib/thrift/types.rb CHANGED
@@ -1,3 +1,22 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
1
20
  require 'set'
2
21
 
3
22
  module Thrift
@@ -16,7 +35,6 @@ module Thrift
16
35
  SET = 14
17
36
  LIST = 15
18
37
  end
19
- deprecate_module! :TType => Types
20
38
 
21
39
  class << self
22
40
  attr_accessor :type_checking
@@ -76,8 +94,8 @@ module Thrift
76
94
  CALL = 1
77
95
  REPLY = 2
78
96
  EXCEPTION = 3
97
+ ONEWAY = 4
79
98
  end
80
- deprecate_module! :TMessageType => MessageTypes
81
99
  end
82
100
 
83
101
  Thrift.type_checking = false if Thrift.type_checking.nil?
data/lib/thrift.rb CHANGED
@@ -1,28 +1,59 @@
1
- #
2
- # Copyright (c) 2006- Facebook
3
- # Distributed under the Apache Software License
4
- #
5
- # See accompanying file LICENSE or visit the Thrift site at:
6
- # http://developers.facebook.com/thrift/
7
- #
8
- # Author: Mark Slee <mcslee@facebook.com>
9
- #
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
10
19
 
11
20
  $:.unshift File.dirname(__FILE__)
12
21
 
13
- module Thrift
14
- # prevent the deprecation layer from being loaded if you require 'thrift'
15
- DEPRECATION = false unless const_defined? :DEPRECATION
16
- end
17
-
18
- require 'thrift/deprecation'
22
+ require 'thrift/core_ext'
19
23
  require 'thrift/exceptions'
20
24
  require 'thrift/types'
21
25
  require 'thrift/processor'
22
26
  require 'thrift/client'
23
27
  require 'thrift/struct'
24
- require 'thrift/protocol'
25
- require 'thrift/protocol/binaryprotocol'
26
- require 'thrift/transport'
28
+
29
+ # serializer
30
+ require 'thrift/serializer/serializer'
31
+ require 'thrift/serializer/deserializer'
32
+
33
+ # protocol
34
+ require 'thrift/protocol/base_protocol'
35
+ require 'thrift/protocol/binary_protocol'
36
+ require 'thrift/protocol/binary_protocol_accelerated'
37
+ require 'thrift/protocol/compact_protocol'
38
+
39
+ # transport
40
+ require 'thrift/transport/base_transport'
41
+ require 'thrift/transport/base_server_transport'
27
42
  require 'thrift/transport/socket'
28
- require 'thrift/server'
43
+ require 'thrift/transport/server_socket'
44
+ require 'thrift/transport/unix_socket'
45
+ require 'thrift/transport/unix_server_socket'
46
+ require 'thrift/transport/buffered_transport'
47
+ require 'thrift/transport/framed_transport'
48
+ require 'thrift/transport/http_client_transport'
49
+ require 'thrift/transport/io_stream_transport'
50
+ require 'thrift/transport/memory_buffer_transport'
51
+
52
+ # server
53
+ require 'thrift/server/base_server'
54
+ require 'thrift/server/nonblocking_server'
55
+ require 'thrift/server/simple_server'
56
+ require 'thrift/server/threaded_server'
57
+ require 'thrift/server/thread_pool_server'
58
+
59
+ require 'thrift/thrift_native'
@@ -0,0 +1,121 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ require File.dirname(__FILE__) + "/../spec/spec_helper.rb"
21
+
22
+ require "benchmark"
23
+ # require "ruby-prof"
24
+
25
+ obj = Fixtures::COMPACT_PROTOCOL_TEST_STRUCT
26
+
27
+ HOW_MANY = 1_000
28
+
29
+ binser = Thrift::Serializer.new
30
+ bin_data = binser.serialize(obj)
31
+ bindeser = Thrift::Deserializer.new
32
+ accel_bin_ser = Thrift::Serializer.new(Thrift::BinaryProtocolAcceleratedFactory.new)
33
+ accel_bin_deser = Thrift::Deserializer.new(Thrift::BinaryProtocolAcceleratedFactory.new)
34
+
35
+ compact_ser = Thrift::Serializer.new(Thrift::CompactProtocolFactory.new)
36
+ compact_data = compact_ser.serialize(obj)
37
+ compact_deser = Thrift::Deserializer.new(Thrift::CompactProtocolFactory.new)
38
+
39
+ Benchmark.bm(60) do |reporter|
40
+ reporter.report("binary protocol, write") do
41
+ HOW_MANY.times do
42
+ binser.serialize(obj)
43
+ end
44
+ end
45
+
46
+ reporter.report("accelerated binary protocol, write") do
47
+ HOW_MANY.times do
48
+ accel_bin_ser.serialize(obj)
49
+ end
50
+ end
51
+
52
+ reporter.report("compact protocol, write") do
53
+ # RubyProf.start
54
+ HOW_MANY.times do
55
+ compact_ser.serialize(obj)
56
+ end
57
+ # result = RubyProf.stop
58
+ # printer = RubyProf::GraphHtmlPrinter.new(result)
59
+ # file = File.open("profile.html", "w+")
60
+ # printer.print(file, 0)
61
+ # file.close
62
+ end
63
+
64
+ reporter.report("binary protocol, read") do
65
+ HOW_MANY.times do
66
+ bindeser.deserialize(obj, bin_data)
67
+ end
68
+ end
69
+
70
+ reporter.report("accelerated binary protocol, read") do
71
+ HOW_MANY.times do
72
+ accel_bin_deser.deserialize(obj, bin_data)
73
+ end
74
+ end
75
+
76
+ reporter.report("compact protocol, read") do
77
+ HOW_MANY.times do
78
+ compact_deser.deserialize(obj, compact_data)
79
+ end
80
+ end
81
+
82
+
83
+ # f = File.new("/tmp/testfile", "w")
84
+ # proto = Thrift::BinaryProtocolAccelerated.new(Thrift::IOStreamTransport.new(Thrift::MemoryBufferTransport.new, f))
85
+ # reporter.report("accelerated binary protocol, write (to disk)") do
86
+ # HOW_MANY.times do
87
+ # obj.write(proto)
88
+ # end
89
+ # f.flush
90
+ # end
91
+ # f.close
92
+ #
93
+ # f = File.new("/tmp/testfile", "r")
94
+ # proto = Thrift::BinaryProtocolAccelerated.new(Thrift::IOStreamTransport.new(f, Thrift::MemoryBufferTransport.new))
95
+ # reporter.report("accelerated binary protocol, read (from disk)") do
96
+ # HOW_MANY.times do
97
+ # obj.read(proto)
98
+ # end
99
+ # end
100
+ # f.close
101
+ #
102
+ # f = File.new("/tmp/testfile", "w")
103
+ # reporter.report("compact protocol, write (to disk)") do
104
+ # proto = Thrift::CompactProtocol.new(Thrift::IOStreamTransport.new(Thrift::MemoryBufferTransport.new, f))
105
+ # HOW_MANY.times do
106
+ # obj.write(proto)
107
+ # end
108
+ # f.flush
109
+ # end
110
+ # f.close
111
+ #
112
+ # f = File.new("/tmp/testfile", "r")
113
+ # reporter.report("compact protocol, read (from disk)") do
114
+ # proto = Thrift::CompactProtocol.new(Thrift::IOStreamTransport.new(f, Thrift::MemoryBufferTransport.new))
115
+ # HOW_MANY.times do
116
+ # obj.read(proto)
117
+ # end
118
+ # end
119
+ # f.close
120
+
121
+ end
@@ -0,0 +1,43 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ require "spec/spec_helper"
21
+
22
+ path, factory_class = ARGV
23
+
24
+ factory = eval(factory_class).new
25
+
26
+ deser = Thrift::Deserializer.new(factory)
27
+
28
+ cpts = CompactProtoTestStruct.new
29
+ CompactProtoTestStruct.constants.each do |const|
30
+ cpts.instance_variable_set("@#{const}", nil)
31
+ end
32
+
33
+ data = File.read(path)
34
+
35
+ deser.deserialize(cpts, data)
36
+
37
+ if cpts == Fixtures::COMPACT_PROTOCOL_TEST_STRUCT
38
+ puts "Object verified successfully!"
39
+ else
40
+ puts "Object failed verification! Expected #{Fixtures::COMPACT_PROTOCOL_TEST_STRUCT.inspect} but got #{cpts.inspect}"
41
+
42
+ puts cpts.differences(Fixtures::COMPACT_PROTOCOL_TEST_STRUCT)
43
+ end