loggregator_emitter 0.0.4.pre → 0.0.5.pre

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- loggregator_emitter (0.0.4.pre)
4
+ loggregator_emitter (0.0.5.pre)
5
5
  loggregator_messages (~> 0.0.1.pre)
6
6
 
7
7
  GEM
@@ -13,14 +13,29 @@ module LoggregatorEmitter
13
13
  end
14
14
 
15
15
  def emit(app_id, message)
16
- s = UDPSocket.new
17
- s.do_not_reverse_lookup = true
16
+ lm = create_log_message(app_id, message, LogMessage::MessageType::OUT)
17
+ send_message(lm)
18
+ end
19
+
20
+ def emit_error(app_id, message)
21
+ lm = create_log_message(app_id, message, LogMessage::MessageType::ERR)
22
+ send_message(lm)
23
+ end
24
+
25
+ private
26
+ def create_log_message(app_id, message, type)
18
27
  lm = LogMessage.new()
19
28
  lm.timestamp = Time.now.to_i
20
29
  lm.message = message
21
30
  lm.app_id = app_id
22
31
  lm.source_type = @source_type
23
- lm.message_type = LogMessage::MessageType::OUT
32
+ lm.message_type = type
33
+ lm
34
+ end
35
+
36
+ def send_message(lm)
37
+ s = UDPSocket.new
38
+ s.do_not_reverse_lookup = true
24
39
 
25
40
  result = lm.encode.buf
26
41
  result.unpack("C*")
@@ -28,7 +43,6 @@ module LoggregatorEmitter
28
43
  s.sendmsg_nonblock(result, 0, @sockaddr_in)
29
44
  end
30
45
 
31
- private
32
46
  def valid_source_type?(source_type)
33
47
  LogMessage::SourceType.constants.each do |name|
34
48
  if LogMessage::SourceType.const_get(name) == source_type
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "loggregator_emitter"
5
- spec.version = '0.0.4.pre'
5
+ spec.version = '0.0.5.pre'
6
6
  spec.authors = ["Pivotal"]
7
7
  spec.email = ["cf-eng@pivotallabs.com"]
8
8
  spec.description = "Library to emit data to Loggregator"
@@ -22,7 +22,7 @@ describe LoggregatorEmitter do
22
22
  end
23
23
  end
24
24
 
25
- describe 'Writing to Sockets' do
25
+ describe 'Sending To STDOUT' do
26
26
  before(:each) do
27
27
  @emitter = LoggregatorEmitter::Emitter.new('0.0.0.0:12345', LogMessage::SourceType::CLOUD_CONTROLLER)
28
28
  end
@@ -43,6 +43,36 @@ describe LoggregatorEmitter do
43
43
  expect(message.message).to eq 'Hello there!'
44
44
  expect(message.app_id).to eq "my_app_id"
45
45
  expect(message.source_type).to eq LogMessage::SourceType::CLOUD_CONTROLLER
46
+ expect(message.message_type).to eq LogMessage::MessageType::OUT
47
+
48
+
49
+ message = messages[1]
50
+ expect(message.message).to eq 'Hello again!'
51
+ end
52
+ end
53
+
54
+ describe 'Sending To STDOUT' do
55
+ before(:each) do
56
+ @emitter = LoggregatorEmitter::Emitter.new('0.0.0.0:12345', LogMessage::SourceType::CLOUD_CONTROLLER)
57
+ end
58
+
59
+ it 'successfully writes protobuffer to a socket' do
60
+ server = FakeLoggregatorServer.new(12345)
61
+ server.start
62
+
63
+ @emitter.emit_error("my_app_id", 'Hello there!')
64
+ @emitter.emit_error("my_app_id", 'Hello again!')
65
+
66
+ server.stop(2)
67
+
68
+ messages = server.messages
69
+
70
+ expect(messages.length).to eq 2
71
+ message = messages[0]
72
+ expect(message.message).to eq 'Hello there!'
73
+ expect(message.app_id).to eq "my_app_id"
74
+ expect(message.source_type).to eq LogMessage::SourceType::CLOUD_CONTROLLER
75
+ expect(message.message_type).to eq LogMessage::MessageType::ERR
46
76
 
47
77
  message = messages[1]
48
78
  expect(message.message).to eq 'Hello again!'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loggregator_emitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.pre
4
+ version: 0.0.5.pre
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors: