nonnative 1.27.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +38 -0
  3. data/.config/cucumber.yml +1 -0
  4. data/.editorconfig +24 -0
  5. data/.gitignore +11 -0
  6. data/.rubocop.yml +87 -0
  7. data/.ruby-version +1 -0
  8. data/Gemfile +8 -0
  9. data/Gemfile.lock +202 -0
  10. data/LICENSE +24 -0
  11. data/Makefile +27 -0
  12. data/README.md +366 -0
  13. data/Rakefile +4 -0
  14. data/bin/console +15 -0
  15. data/bin/setup +9 -0
  16. data/lib/nonnative.rb +89 -0
  17. data/lib/nonnative/before.rb +11 -0
  18. data/lib/nonnative/close_all_socket_pair.rb +9 -0
  19. data/lib/nonnative/command.rb +54 -0
  20. data/lib/nonnative/configuration.rb +80 -0
  21. data/lib/nonnative/configuration_process.rb +7 -0
  22. data/lib/nonnative/configuration_proxy.rb +13 -0
  23. data/lib/nonnative/configuration_server.rb +19 -0
  24. data/lib/nonnative/delay_socket_pair.rb +12 -0
  25. data/lib/nonnative/error.rb +6 -0
  26. data/lib/nonnative/fault_injection_proxy.rb +78 -0
  27. data/lib/nonnative/grpc_server.rb +44 -0
  28. data/lib/nonnative/http_client.rb +53 -0
  29. data/lib/nonnative/http_server.rb +40 -0
  30. data/lib/nonnative/invalid_data_socket_pair.rb +11 -0
  31. data/lib/nonnative/manual.rb +3 -0
  32. data/lib/nonnative/no_proxy.rb +17 -0
  33. data/lib/nonnative/observability.rb +13 -0
  34. data/lib/nonnative/pool.rb +60 -0
  35. data/lib/nonnative/port.rb +44 -0
  36. data/lib/nonnative/proxy.rb +13 -0
  37. data/lib/nonnative/proxy_factory.rb +18 -0
  38. data/lib/nonnative/server.rb +41 -0
  39. data/lib/nonnative/service.rb +26 -0
  40. data/lib/nonnative/socket_pair.rb +53 -0
  41. data/lib/nonnative/socket_pair_factory.rb +22 -0
  42. data/lib/nonnative/start_error.rb +6 -0
  43. data/lib/nonnative/startup.rb +7 -0
  44. data/lib/nonnative/stop_error.rb +6 -0
  45. data/lib/nonnative/timeout.rb +21 -0
  46. data/lib/nonnative/version.rb +5 -0
  47. data/nonnative.gemspec +42 -0
  48. data/sonar-project.properties +4 -0
  49. metadata +340 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '0384f1153315ed00bbf2c15405150a102b5fa7c7fac9548eac6ee2c03e6e821e'
4
+ data.tar.gz: d09d8785d1f1a0a81806f3b6740e1b835125884bc1e7b2f192ae8bb8586d8acd
5
+ SHA512:
6
+ metadata.gz: b6cf1fad64114a39e7c00090a1dedd00d5c7c4f80344668ef5234e68836c6055a9b5aa839dd6639882effc16d03e142a5ba0db6f18154d05617906ae4492f877
7
+ data.tar.gz: 8050865795030f35bb222314905bb4ae981efce1ee21bcad13a9ead4a6d992163439e8b3900aea566d1244cc2438e3a42f711a909a41b55b849e1379af423cb1
@@ -0,0 +1,38 @@
1
+ version: 2.1
2
+ orbs:
3
+ sonarcloud: sonarsource/sonarcloud@1.0.1
4
+
5
+ jobs:
6
+ build:
7
+ docker:
8
+ - image: circleci/ruby:2.7
9
+ environment:
10
+ BUNDLE_JOBS: "3"
11
+ BUNDLE_PATH: vendor/bundle
12
+ BUNDLE_RETRY: "3"
13
+ steps:
14
+ - checkout
15
+ - restore_cache:
16
+ keys:
17
+ - nonnative-gem-cache-{{ checksum "Gemfile.lock" }}
18
+ - nonnative-gem-cache-
19
+ - run: make dependencies
20
+ - save_cache:
21
+ key: nonnative-gem-cache-{{ checksum "Gemfile.lock" }}
22
+ paths:
23
+ - vendor/bundle
24
+ - run: make features
25
+ - store_test_results:
26
+ path: reports
27
+ - run: make analysis
28
+ - store_artifacts:
29
+ path: coverage
30
+ - store_artifacts:
31
+ path: features/logs
32
+ - sonarcloud/scan
33
+
34
+ workflows:
35
+ nonnative:
36
+ jobs:
37
+ - build:
38
+ context: SonarCloud
@@ -0,0 +1 @@
1
+ report: --format junit --out reports --format html --out reports/index.html --format pretty
@@ -0,0 +1,24 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ indent_style = space
7
+ insert_final_newline = true
8
+ trim_trailing_whitespace = true
9
+
10
+ [Makefile]
11
+ indent_style = tab
12
+ indent_size = 8
13
+
14
+ [*.go]
15
+ indent_style = tab
16
+ indent_size = 4
17
+
18
+ [*.rb]
19
+ indent_style = space
20
+ indent_size = 2
21
+
22
+ [*.feature]
23
+ indent_style = space
24
+ indent_size = 2
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /reports/
8
+ /tmp/
9
+ vendor
10
+ coverage
11
+ features/logs/*.log
@@ -0,0 +1,87 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+ DisplayCopNames: true
4
+
5
+ Layout/LineLength:
6
+ Max: 120
7
+
8
+ Metrics/MethodLength:
9
+ Max: 20
10
+
11
+ Metrics/BlockLength:
12
+ Max: 80
13
+
14
+ Metrics/AbcSize:
15
+ Max: 20
16
+
17
+ Style/Documentation:
18
+ Enabled: false
19
+
20
+ Lint/RaiseException:
21
+ Enabled: true
22
+
23
+ Style/HashEachMethods:
24
+ Enabled: true
25
+
26
+ Style/HashTransformKeys:
27
+ Enabled: true
28
+
29
+ Style/HashTransformValues:
30
+ Enabled: true
31
+
32
+ Lint/StructNewOverride:
33
+ Enabled: true
34
+
35
+ Layout/SpaceAroundMethodCallOperator:
36
+ Enabled: true
37
+
38
+ Style/ExponentialNotation:
39
+ Enabled: true
40
+
41
+ Layout/EmptyLinesAroundAttributeAccessor:
42
+ Enabled: true
43
+
44
+ Style/SlicingWithRange:
45
+ Enabled: true
46
+
47
+ Lint/DeprecatedOpenSSLConstant:
48
+ Enabled: true
49
+
50
+ Lint/MixedRegexpCaptureTypes:
51
+ Enabled: true
52
+
53
+ Style/RedundantRegexpCharacterClass:
54
+ Enabled: true
55
+
56
+ Style/RedundantRegexpEscape:
57
+ Enabled: true
58
+
59
+ Style/RedundantFetchBlock:
60
+ Enabled: true
61
+
62
+ Style/AccessorGrouping:
63
+ Enabled: true
64
+
65
+ Style/BisectedAttrAccessor:
66
+ Enabled: true
67
+
68
+ Style/RedundantAssignment:
69
+ Enabled: true
70
+
71
+ Lint/DuplicateElsifCondition:
72
+ Enabled: true
73
+
74
+ Style/ArrayCoercion:
75
+ Enabled: true
76
+
77
+ Style/CaseLikeIf:
78
+ Enabled: true
79
+
80
+ Style/HashAsLastArrayItem:
81
+ Enabled: true
82
+
83
+ Style/HashLikeCase:
84
+ Enabled: true
85
+
86
+ Style/RedundantFileExtensionInRequire:
87
+ Enabled: true
@@ -0,0 +1 @@
1
+ ruby-2.7.1
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in nonnative.gemspec
8
+ gemspec
@@ -0,0 +1,202 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nonnative (1.27.0)
5
+ concurrent-ruby (~> 1.0, >= 1.0.5)
6
+ cucumber (>= 4, < 5)
7
+ grpc (>= 1, < 2)
8
+ puma (~> 4.3, >= 4.3.3)
9
+ rest-client (~> 2.1)
10
+ rspec-benchmark (~> 0.6.0)
11
+ rspec-expectations (~> 3.9, >= 3.9.2)
12
+ sinatra (~> 2.0, >= 2.0.8.1)
13
+
14
+ GEM
15
+ remote: https://rubygems.org/
16
+ specs:
17
+ activesupport (6.0.3.2)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (>= 0.7, < 2)
20
+ minitest (~> 5.1)
21
+ tzinfo (~> 1.1)
22
+ zeitwerk (~> 2.2, >= 2.2.2)
23
+ ast (2.4.1)
24
+ backport (1.1.2)
25
+ benchmark (0.1.0)
26
+ benchmark-malloc (0.2.0)
27
+ benchmark-perf (0.6.0)
28
+ benchmark-trend (0.4.0)
29
+ builder (3.2.4)
30
+ concurrent-ruby (1.1.6)
31
+ cucumber (4.1.0)
32
+ builder (~> 3.2, >= 3.2.3)
33
+ cucumber-core (~> 7.1, >= 7.1.0)
34
+ cucumber-create-meta (~> 1.0.0, >= 1.0.0)
35
+ cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
36
+ cucumber-gherkin (~> 14.0, >= 14.0.1)
37
+ cucumber-html-formatter (~> 7.0, >= 7.0.0)
38
+ cucumber-messages (~> 12.2, >= 12.2.0)
39
+ cucumber-wire (~> 3.1, >= 3.1.0)
40
+ diff-lcs (~> 1.3, >= 1.3, < 1.4)
41
+ multi_test (~> 0.1, >= 0.1.2)
42
+ sys-uname (~> 1.0, >= 1.0.2)
43
+ cucumber-core (7.1.0)
44
+ cucumber-gherkin (~> 14.0, >= 14.0.1)
45
+ cucumber-messages (~> 12.2, >= 12.2.0)
46
+ cucumber-tag-expressions (~> 2.0, >= 2.0.4)
47
+ cucumber-create-meta (1.0.0)
48
+ cucumber-messages (~> 12.2, >= 12.2.0)
49
+ sys-uname (~> 1.2, >= 1.2.1)
50
+ cucumber-cucumber-expressions (10.2.1)
51
+ cucumber-gherkin (14.0.1)
52
+ cucumber-messages (~> 12.2, >= 12.2.0)
53
+ cucumber-html-formatter (7.0.0)
54
+ cucumber-messages (~> 12.2, >= 12.2.0)
55
+ cucumber-messages (12.2.0)
56
+ protobuf-cucumber (~> 3.10, >= 3.10.8)
57
+ cucumber-tag-expressions (2.0.4)
58
+ cucumber-wire (3.1.0)
59
+ cucumber-core (~> 7.1, >= 7.1.0)
60
+ cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
61
+ cucumber-messages (~> 12.2, >= 12.2.0)
62
+ diff-lcs (1.3)
63
+ docile (1.3.2)
64
+ domain_name (0.5.20190701)
65
+ unf (>= 0.0.5, < 1.0.0)
66
+ e2mmap (0.1.0)
67
+ ffi (1.13.1)
68
+ google-protobuf (3.12.2)
69
+ googleapis-common-protos-types (1.0.5)
70
+ google-protobuf (~> 3.11)
71
+ grpc (1.30.1)
72
+ google-protobuf (~> 3.12)
73
+ googleapis-common-protos-types (~> 1.0)
74
+ grpc-tools (1.30.1)
75
+ http-accept (1.7.0)
76
+ http-cookie (1.0.3)
77
+ domain_name (~> 0.5)
78
+ i18n (1.8.4)
79
+ concurrent-ruby (~> 1.0)
80
+ jaro_winkler (1.5.4)
81
+ json (2.3.0)
82
+ maruku (0.7.3)
83
+ middleware (0.1.0)
84
+ mime-types (3.3.1)
85
+ mime-types-data (~> 3.2015)
86
+ mime-types-data (3.2020.0512)
87
+ mini_portile2 (2.4.0)
88
+ minitest (5.14.1)
89
+ multi_test (0.1.2)
90
+ mustermann (1.1.1)
91
+ ruby2_keywords (~> 0.0.1)
92
+ netrc (0.11.0)
93
+ nio4r (2.5.2)
94
+ nokogiri (1.10.10)
95
+ mini_portile2 (~> 2.4.0)
96
+ parallel (1.19.2)
97
+ parser (2.7.1.4)
98
+ ast (~> 2.4.1)
99
+ protobuf-cucumber (3.10.8)
100
+ activesupport (>= 3.2)
101
+ middleware
102
+ thor
103
+ thread_safe
104
+ puma (4.3.5)
105
+ nio4r (~> 2.0)
106
+ rack (2.2.3)
107
+ rack-protection (2.0.8.1)
108
+ rack
109
+ rainbow (3.0.0)
110
+ rake (13.0.1)
111
+ regexp_parser (1.7.1)
112
+ rest-client (2.1.0)
113
+ http-accept (>= 1.7.0, < 2.0)
114
+ http-cookie (>= 1.0.2, < 2.0)
115
+ mime-types (>= 1.16, < 4.0)
116
+ netrc (~> 0.8)
117
+ reverse_markdown (2.0.0)
118
+ nokogiri
119
+ rexml (3.2.4)
120
+ rspec (3.9.0)
121
+ rspec-core (~> 3.9.0)
122
+ rspec-expectations (~> 3.9.0)
123
+ rspec-mocks (~> 3.9.0)
124
+ rspec-benchmark (0.6.0)
125
+ benchmark-malloc (~> 0.2)
126
+ benchmark-perf (~> 0.6)
127
+ benchmark-trend (~> 0.4)
128
+ rspec (>= 3.0)
129
+ rspec-core (3.9.2)
130
+ rspec-support (~> 3.9.3)
131
+ rspec-expectations (3.9.2)
132
+ diff-lcs (>= 1.2.0, < 2.0)
133
+ rspec-support (~> 3.9.0)
134
+ rspec-mocks (3.9.1)
135
+ diff-lcs (>= 1.2.0, < 2.0)
136
+ rspec-support (~> 3.9.0)
137
+ rspec-support (3.9.3)
138
+ rubocop (0.88.0)
139
+ parallel (~> 1.10)
140
+ parser (>= 2.7.1.1)
141
+ rainbow (>= 2.2.2, < 4.0)
142
+ regexp_parser (>= 1.7)
143
+ rexml
144
+ rubocop-ast (>= 0.1.0, < 1.0)
145
+ ruby-progressbar (~> 1.7)
146
+ unicode-display_width (>= 1.4.0, < 2.0)
147
+ rubocop-ast (0.2.0)
148
+ parser (>= 2.7.0.1)
149
+ ruby-progressbar (1.10.1)
150
+ ruby2_keywords (0.0.2)
151
+ simplecov (0.17.1)
152
+ docile (~> 1.1)
153
+ json (>= 1.8, < 3)
154
+ simplecov-html (~> 0.10.0)
155
+ simplecov-html (0.10.2)
156
+ sinatra (2.0.8.1)
157
+ mustermann (~> 1.0)
158
+ rack (~> 2.0)
159
+ rack-protection (= 2.0.8.1)
160
+ tilt (~> 2.0)
161
+ solargraph (0.39.12)
162
+ backport (~> 1.1)
163
+ benchmark
164
+ bundler (>= 1.17.2)
165
+ e2mmap
166
+ jaro_winkler (~> 1.5)
167
+ maruku (~> 0.7, >= 0.7.3)
168
+ nokogiri (~> 1.9, >= 1.9.1)
169
+ parser (~> 2.3)
170
+ reverse_markdown (>= 1.0.5, < 3)
171
+ rubocop (~> 0.52)
172
+ thor (~> 1.0)
173
+ tilt (~> 2.0)
174
+ yard (~> 0.9, >= 0.9.24)
175
+ sys-uname (1.2.1)
176
+ ffi (>= 1.0.0)
177
+ thor (1.0.1)
178
+ thread_safe (0.3.6)
179
+ tilt (2.0.10)
180
+ tzinfo (1.2.7)
181
+ thread_safe (~> 0.1)
182
+ unf (0.1.4)
183
+ unf_ext
184
+ unf_ext (0.0.7.7)
185
+ unicode-display_width (1.7.0)
186
+ yard (0.9.25)
187
+ zeitwerk (2.4.0)
188
+
189
+ PLATFORMS
190
+ ruby
191
+
192
+ DEPENDENCIES
193
+ bundler (~> 2.1, >= 2.1.4)
194
+ grpc-tools (>= 1, < 2)
195
+ nonnative!
196
+ rake (~> 13.0, >= 13.0.1)
197
+ rubocop (~> 0.88)
198
+ simplecov (~> 0.17.1)
199
+ solargraph (~> 0.39.11)
200
+
201
+ BUNDLED WITH
202
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org>
@@ -0,0 +1,27 @@
1
+ .PHONY: features
2
+
3
+ dependencies:
4
+ bin/setup
5
+
6
+ outdated-dependencies:
7
+ bundle outdated --only-explicit
8
+
9
+ features: clean
10
+ bundle exec cucumber --profile report --fail-fast $(feature)
11
+
12
+ analysis:
13
+ bundle exec rubocop
14
+
15
+ cleanup-analysis:
16
+ bundle exec rubocop -a
17
+
18
+ cleanup-logs:
19
+ rm -rf features/logs/*.log
20
+
21
+ cleanup-reports:
22
+ rm -rf reports
23
+
24
+ cleanup-coverage:
25
+ rm -rf coverage
26
+
27
+ clean: cleanup-logs cleanup-reports cleanup-coverage
@@ -0,0 +1,366 @@
1
+ [![CircleCI](https://circleci.com/gh/alexfalkowski/nonnative.svg?style=svg)](https://circleci.com/gh/alexfalkowski/nonnative)
2
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=alexfalkowski_nonnative&metric=alert_status)](https://sonarcloud.io/dashboard?id=alexfalkowski_nonnative)
3
+
4
+ # Nonnative
5
+
6
+ Do you love building microservices using different languages?
7
+
8
+ Do you love testing applications using [cucumber](https://cucumber.io/) with [ruby](https://www.ruby-lang.org/en/)?
9
+
10
+ Well so do I. The issue is that most languages the cucumber implementation is not always complete or you have to write a lot of code to get it working.
11
+
12
+ So why not test the way you want and build the microservice how you want. These kind of tests will make sure your application is tested properly by going end-to-end.
13
+
14
+ The way it works is it spawns processes or servers you configure and waits for it to start. Then you communicate with your microservice however you like (TCP, HTTP, gRPC, etc)
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'nonnative'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install nonnative
31
+
32
+ ## Usage
33
+
34
+ Configure nonnative with the following:
35
+
36
+ - Process/Server that you want to start.
37
+ - A timeout value.
38
+ - Port to verify.
39
+ - The class for servers.
40
+ - The file you want STDOUT to be logged to for processes.
41
+ - The strategy for processes/servers.
42
+ * Startup will start the process once.
43
+ * Before will hook into cucumbers Before and After.
44
+
45
+ ### Processes
46
+
47
+ Setup it up programmatically:
48
+
49
+ ```ruby
50
+ require 'nonnative'
51
+
52
+ Nonnative.configure do |config|
53
+ config.strategy = :startup or :before or :manual
54
+
55
+ config.process do |d|
56
+ d.name = 'start_1'
57
+ d.command = 'features/support/bin/start 12_321'
58
+ d.timeout = 0.5
59
+ d.port = 12_321
60
+ d.log = 'features/logs/12_321.log'
61
+ d.signal = 'INT' # Possible values are described in Signal.list.keys
62
+ end
63
+
64
+ config.process do |d|
65
+ d.name = 'start_2'
66
+ d.command = 'features/support/bin/start 12_322'
67
+ d.timeout = 0.5
68
+ d.port = 12_322
69
+ d.log = 'features/logs/12_322.log'
70
+ end
71
+ end
72
+ ```
73
+
74
+ Setup it up through configuration:
75
+
76
+ ```yaml
77
+ version: 1.0
78
+ strategy: manual
79
+ processes:
80
+ -
81
+ name: start_1
82
+ command: features/support/bin/start 12_321
83
+ timeout: 5
84
+ port: 12321
85
+ log: features/logs/12_321.log
86
+ signal: INT # Possible values are described in Signal.list.keys
87
+ -
88
+ name: start_2
89
+ command: features/support/bin/start 12_322
90
+ timeout: 5
91
+ port: 12322
92
+ log: features/logs/12_322.log
93
+ ```
94
+
95
+ Then load the file with
96
+
97
+ ```ruby
98
+ require 'nonnative'
99
+
100
+ Nonnative.load_configuration('configuration.yml')
101
+ ```
102
+
103
+ ### Servers
104
+
105
+ Define your server:
106
+
107
+ ```ruby
108
+ module Nonnative
109
+ class EchoServer < Nonnative::Server
110
+ def perform_start
111
+ @socket_server = TCPServer.new('0.0.0.0', port)
112
+
113
+ loop do
114
+ client_socket = @socket_server.accept
115
+ client_socket.puts 'Hello World!'
116
+ client_socket.close
117
+ end
118
+ rescue StandardError
119
+ end
120
+
121
+ def perform_stop
122
+ @socket_server.close
123
+ end
124
+ end
125
+ end
126
+ ```
127
+
128
+ Setup it up programmatically:
129
+
130
+ ```ruby
131
+ require 'nonnative'
132
+
133
+ Nonnative.configure do |config|
134
+ config.strategy = :manual
135
+
136
+ config.server do |s|
137
+ s.name = 'server_1'
138
+ s.klass = Nonnative::EchoServer
139
+ s.timeout = 1
140
+ s.port = 12_323
141
+ s.log = 'features/logs/server_1.log'
142
+ end
143
+
144
+ config.server do |s|
145
+ s.name = 'server_2'
146
+ s.klass = Nonnative::EchoServer
147
+ s.timeout = 1
148
+ s.port = 12_324
149
+ s.log = 'features/logs/server_2.log'
150
+ end
151
+ end
152
+ ```
153
+
154
+ Setup it up through configuration:
155
+
156
+ ```yaml
157
+ version: 1.0
158
+ strategy: manual
159
+ servers:
160
+ -
161
+ name: server_1
162
+ klass: Nonnative::EchoServer
163
+ timeout: 1
164
+ port: 12323
165
+ log: features/logs/server_1.log
166
+ -
167
+ name: server_2
168
+ klass: Nonnative::EchoServer
169
+ timeout: 1
170
+ port: 12324
171
+ log: features/logs/server_2.log
172
+ ```
173
+
174
+ Then load the file with:
175
+
176
+ ```ruby
177
+ require 'nonnative'
178
+
179
+ Nonnative.load_configuration('configuration.yml')
180
+ ```
181
+
182
+ #### HTTP
183
+
184
+ Define your server:
185
+
186
+ ```ruby
187
+ module Nonnative
188
+ module Features
189
+ class Application < Sinatra::Application
190
+ configure do
191
+ set :server_settings, log_requests: true
192
+ end
193
+
194
+ get '/hello' do
195
+ 'Hello World!'
196
+ end
197
+ end
198
+
199
+ class HTTPServer < Nonnative::HTTPServer
200
+ def app
201
+ Application.new
202
+ end
203
+ end
204
+ end
205
+ end
206
+ ```
207
+
208
+ Setup it up programmatically:
209
+
210
+ ```ruby
211
+ require 'nonnative'
212
+
213
+ Nonnative.configure do |config|
214
+ config.strategy = :manual
215
+
216
+ config.server do |s|
217
+ s.name = 'http_server_1'
218
+ s.klass = Nonnative::Features::HTTPServer
219
+ s.timeout = 1
220
+ s.port = 4567
221
+ s.log = 'features/logs/http_server_1.log'
222
+ end
223
+ end
224
+ ```
225
+
226
+ Setup it up through configuration:
227
+
228
+ ```yaml
229
+ version: 1.0
230
+ strategy: manual
231
+ servers:
232
+ -
233
+ name: http_server_1
234
+ klass: Nonnative::Features::HTTPServer
235
+ timeout: 1
236
+ port: 4567
237
+ log: features/logs/http_server_1.log
238
+ ```
239
+
240
+ Then load the file with:
241
+
242
+ ```ruby
243
+ require 'nonnative'
244
+
245
+ Nonnative.load_configuration('configuration.yml')
246
+ ```
247
+
248
+ #### gRPC
249
+
250
+ Define your server:
251
+
252
+ ```ruby
253
+ module Nonnative
254
+ module Features
255
+ class GreeterService < Greeter::Service
256
+ def say_hello(request, _call)
257
+ Nonnative::Features::HelloReply.new(message: request.name.to_s)
258
+ end
259
+ end
260
+
261
+ class GRPCServer < Nonnative::GRPCServer
262
+ def svc
263
+ GreeterService.new
264
+ end
265
+ end
266
+ end
267
+ end
268
+ ```
269
+
270
+ Setup it up programmatically:
271
+
272
+ ```ruby
273
+ require 'nonnative'
274
+
275
+ Nonnative.configure do |config|
276
+ config.strategy = :manual
277
+
278
+ config.server do |s|
279
+ s.name = 'grpc_server_1'
280
+ s.klass = Nonnative::Features::GRPCServer
281
+ s.timeout = 1
282
+ s.port = 9002
283
+ s.log = 'features/logs/grpc_server_1.log'
284
+ end
285
+ end
286
+ ```
287
+
288
+ Setup it up through configuration:
289
+
290
+ ```yaml
291
+ version: 1.0
292
+ strategy: manual
293
+ servers:
294
+ -
295
+ name: grpc_server_1
296
+ klass: Nonnative::Features::GRPCServer
297
+ timeout: 1
298
+ port: 9002
299
+ log: features/logs/grpc_server_1.log
300
+ ```
301
+
302
+ Then load the file with:
303
+
304
+ ```ruby
305
+ require 'nonnative'
306
+
307
+ Nonnative.load_configuration('configuration.yml')
308
+ ```
309
+ #### Proxies
310
+
311
+ We allow different proxies to be configured. These proxies can be used to simulate all kind of situations. The proxies that can be configured are:
312
+ - `none` (this is the default)
313
+ - `fault_injection`
314
+
315
+ Setup it up programmatically:
316
+
317
+ ```ruby
318
+ require 'nonnative'
319
+
320
+ Nonnative.configure do |config|
321
+ config.strategy = :manual
322
+
323
+ config.server do |d|
324
+ d.proxy = {
325
+ type: 'fault_injection',
326
+ port: 20_000,
327
+ log: 'features/logs/proxy_server.log',
328
+ options: {
329
+ delay: 5
330
+ }
331
+ }
332
+ end
333
+ end
334
+ ```
335
+
336
+ Setup it up through configuration:
337
+
338
+ ```yaml
339
+ version: 1.0
340
+ strategy: manual
341
+ servers:
342
+ -
343
+ proxy:
344
+ type: fault_injection
345
+ port: 20000
346
+ log: features/logs/proxy_server.log
347
+ options:
348
+ delay: 5
349
+ ```
350
+
351
+ ##### Fault Injection
352
+
353
+ The `fault_injection` proxy allows you to simulate failures by injecting them. We currently support the following:
354
+ - `close_all` - Closes the socket as soon as it connects.
355
+ - `delay` - This delays the communication between the connection. Default is 2 secs can be configured through options.
356
+ - `invalid_data` - This takes the input and rearranges it to produce invalid data.
357
+
358
+ Setup it up programmatically:
359
+
360
+ ```ruby
361
+ name = 'name of server in configuration'
362
+ server = Nonnative.pool.server_by_name(name)
363
+
364
+ server.proxy.close_all # To use close_all.
365
+ server.proxy.reset # To reset it back to a good state.
366
+ ```