rapns 3.3.2-java → 3.4.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. data/CHANGELOG.md +7 -0
  2. data/README.md +19 -21
  3. data/bin/rapns +14 -13
  4. data/lib/generators/templates/rapns.rb +8 -4
  5. data/lib/rapns.rb +7 -0
  6. data/lib/rapns/TODO +3 -0
  7. data/lib/rapns/apns/feedback.rb +4 -2
  8. data/lib/rapns/app.rb +3 -1
  9. data/lib/rapns/configuration.rb +8 -1
  10. data/lib/rapns/daemon.rb +3 -1
  11. data/lib/rapns/daemon/apns/app_runner.rb +3 -2
  12. data/lib/rapns/daemon/apns/certificate_expired_error.rb +20 -0
  13. data/lib/rapns/daemon/apns/connection.rb +26 -0
  14. data/lib/rapns/daemon/apns/delivery.rb +2 -1
  15. data/lib/rapns/daemon/apns/delivery_handler.rb +2 -2
  16. data/lib/rapns/daemon/app_runner.rb +50 -28
  17. data/lib/rapns/daemon/batch.rb +100 -0
  18. data/lib/rapns/daemon/delivery.rb +6 -10
  19. data/lib/rapns/daemon/delivery_handler.rb +14 -12
  20. data/lib/rapns/daemon/delivery_handler_collection.rb +33 -0
  21. data/lib/rapns/daemon/feeder.rb +3 -5
  22. data/lib/rapns/daemon/gcm/delivery.rb +5 -4
  23. data/lib/rapns/daemon/gcm/delivery_handler.rb +2 -2
  24. data/lib/rapns/daemon/store/active_record.rb +23 -2
  25. data/lib/rapns/deprecation.rb +7 -6
  26. data/lib/rapns/logger.rb +1 -1
  27. data/lib/rapns/notification.rb +5 -3
  28. data/lib/rapns/reflection.rb +1 -1
  29. data/lib/rapns/version.rb +1 -1
  30. data/lib/tasks/cane.rake +1 -1
  31. data/lib/tasks/test.rake +8 -3
  32. data/spec/unit/apns/app_spec.rb +4 -4
  33. data/spec/unit/apns_feedback_spec.rb +1 -1
  34. data/spec/unit/configuration_spec.rb +12 -6
  35. data/spec/unit/daemon/apns/app_runner_spec.rb +6 -4
  36. data/spec/unit/daemon/apns/certificate_expired_error_spec.rb +11 -0
  37. data/spec/unit/daemon/apns/connection_spec.rb +46 -10
  38. data/spec/unit/daemon/apns/delivery_handler_spec.rb +24 -18
  39. data/spec/unit/daemon/apns/delivery_spec.rb +11 -12
  40. data/spec/unit/daemon/apns/feedback_receiver_spec.rb +16 -16
  41. data/spec/unit/daemon/app_runner_shared.rb +27 -10
  42. data/spec/unit/daemon/app_runner_spec.rb +48 -28
  43. data/spec/unit/daemon/batch_spec.rb +160 -0
  44. data/spec/unit/daemon/delivery_handler_collection_spec.rb +37 -0
  45. data/spec/unit/daemon/delivery_handler_shared.rb +20 -11
  46. data/spec/unit/daemon/feeder_spec.rb +12 -12
  47. data/spec/unit/daemon/gcm/app_runner_spec.rb +4 -2
  48. data/spec/unit/daemon/gcm/delivery_handler_spec.rb +18 -10
  49. data/spec/unit/daemon/gcm/delivery_spec.rb +47 -17
  50. data/spec/unit/daemon/interruptible_sleep_spec.rb +3 -3
  51. data/spec/unit/daemon/reflectable_spec.rb +1 -1
  52. data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +1 -1
  53. data/spec/unit/daemon/store/active_record_spec.rb +87 -10
  54. data/spec/unit/daemon_spec.rb +6 -6
  55. data/spec/unit/deprecation_spec.rb +2 -2
  56. data/spec/unit/logger_spec.rb +33 -17
  57. data/spec/unit/notification_shared.rb +7 -3
  58. data/spec/unit/upgraded_spec.rb +8 -14
  59. data/spec/unit_spec_helper.rb +9 -1
  60. metadata +53 -44
  61. data/lib/rapns/daemon/delivery_queue.rb +0 -42
  62. data/lib/rapns/daemon/delivery_queue_18.rb +0 -44
  63. data/lib/rapns/daemon/delivery_queue_19.rb +0 -42
  64. data/spec/acceptance/gcm_upgrade_spec.rb +0 -34
  65. data/spec/acceptance_spec_helper.rb +0 -85
  66. data/spec/unit/daemon/delivery_queue_spec.rb +0 -29
@@ -1,44 +0,0 @@
1
- module Rapns
2
- module Daemon
3
- class DeliveryQueue18
4
- def push(obj)
5
- Thread.critical = true
6
- @queue.push obj
7
- @num_notifications += 1
8
- begin
9
- t = @waiting.shift
10
- t.wakeup if t
11
- rescue ThreadError
12
- retry
13
- ensure
14
- Thread.critical = false
15
- end
16
- begin
17
- t.run if t
18
- rescue ThreadError
19
- end
20
- end
21
-
22
- def pop
23
- while (Thread.critical = true; @queue.empty?)
24
- @waiting.push Thread.current
25
- Thread.stop
26
- end
27
- @queue.shift
28
- ensure
29
- Thread.critical = false
30
- end
31
-
32
- protected
33
-
34
- def synchronize
35
- Thread.critical = true
36
- begin
37
- yield
38
- ensure
39
- Thread.critical = false
40
- end
41
- end
42
- end
43
- end
44
- end
@@ -1,42 +0,0 @@
1
- module Rapns
2
- module Daemon
3
- class DeliveryQueue19
4
- def initialize
5
- @mutex = Mutex.new
6
- end
7
-
8
- def push(notification)
9
- @mutex.synchronize do
10
- @num_notifications += 1
11
- @queue.push(notification)
12
-
13
- begin
14
- t = @waiting.shift
15
- t.wakeup if t
16
- rescue ThreadError
17
- retry
18
- end
19
- end
20
- end
21
-
22
- def pop
23
- @mutex.synchronize do
24
- while true
25
- if @queue.empty?
26
- @waiting.push Thread.current
27
- @mutex.sleep
28
- else
29
- return @queue.shift
30
- end
31
- end
32
- end
33
- end
34
-
35
- protected
36
-
37
- def synchronize(&blk)
38
- @mutex.synchronize(&blk)
39
- end
40
- end
41
- end
42
- end
@@ -1,34 +0,0 @@
1
- require 'acceptance_spec_helper'
2
-
3
- describe 'GCM upgrade' do
4
- before do
5
- setup_rails
6
- generate
7
- migrate('create_rapns_notifications', 'create_rapns_feedback',
8
- 'add_alert_is_json_to_rapns_notifications', 'add_app_to_rapns',
9
- 'create_rapns_apps')
10
-
11
- as_test_rails_db do
12
- now = Time.now.to_s(:db)
13
- ActiveRecord::Base.connection.execute <<-SQL
14
- INSERT INTO rapns_apps (key, environment, certificate, created_at, updated_at)
15
- VALUES ('test', 'development', 'c3rt', '#{now}', '#{now}')
16
- SQL
17
-
18
- ActiveRecord::Base.connection.execute <<-SQL
19
- INSERT INTO rapns_notifications (app, device_token, created_at, updated_at)
20
- VALUES ('test', 't0k3n', '#{now}', '#{now}')
21
- SQL
22
- end
23
-
24
- migrate('add_gcm')
25
- end
26
-
27
- it 'associates apps and notifications' do
28
- as_test_rails_db do
29
- app = Rapns::Apns::App.first
30
- app.name.should == 'test'
31
- app.notifications.count.should == 1
32
- end
33
- end
34
- end
@@ -1,85 +0,0 @@
1
- require 'unit_spec_helper'
2
- require 'fileutils'
3
-
4
- ENV['RAILS_ENV'] = 'test'
5
- require 'bundler'
6
- Bundler.require(:default)
7
-
8
- TMP_DIR = '/tmp'
9
- RAILS_DIR = File.join(TMP_DIR, 'rapns_test')
10
- if ENV['TRAVIS']
11
- TRAVIS_BRANCH = 'master'
12
- RAPNS_ROOT = 'git://github.com/ileitch/rapns.git'
13
- else
14
- RAPNS_ROOT = File.expand_path(__FILE__ + '/../../')
15
- end
16
-
17
- def setup_rails
18
- return if $rails_is_setup
19
- `rm -rf #{RAILS_DIR}`
20
- FileUtils.mkdir_p(RAILS_DIR)
21
- cmd("bundle exec rails new #{RAILS_DIR} --skip-bundle")
22
- branch = `git branch | grep '\*'`.split(' ').last
23
- in_test_rails do
24
- cmd('echo "gem \'rake\'" >> Gemfile')
25
- if ENV['TRAVIS']
26
- cmd("echo \"gem 'rapns', :git => '#{RAPNS_ROOT}', :branch => '#{TRAVIS_BRANCH}'\" >> Gemfile")
27
- else
28
- cmd("echo \"gem 'rapns', :git => '#{RAPNS_ROOT}', :branch => '#{branch}'\" >> Gemfile")
29
- end
30
-
31
- cmd("bundle install")
32
- end
33
- end
34
-
35
- def as_test_rails_db(env='development')
36
- orig_config = ActiveRecord::Base.connection_config
37
- begin
38
- in_test_rails do
39
- config = YAML.load_file('config/database.yml')
40
- ActiveRecord::Base.establish_connection(config[env])
41
- yield
42
- end
43
- ensure
44
- ActiveRecord::Base.establish_connection(orig_config)
45
- end
46
- end
47
-
48
- def cmd(str, echo = true)
49
- puts "* #{str.strip}" if echo
50
- retval = Bundler.with_clean_env { `#{str}` }
51
- puts retval.strip if echo && retval.strip != ""
52
- retval
53
- end
54
-
55
- def generate
56
- in_test_rails { cmd('bundle exec rails g rapns') }
57
- end
58
-
59
- def migrate(*migrations)
60
- in_test_rails do
61
- if migrations.present?
62
- migrations.each do |name|
63
- migration = Dir.entries('db/migrate').find { |entry| entry =~ /#{name}/ }
64
- version = migration.split('_').first
65
- cmd("bundle exec rake db:migrate VERSION=#{version} RAILS_ENV=development")
66
- end
67
- else
68
- cmd('bundle exec rake db:migrate RAILS_ENV=development')
69
- end
70
- end
71
- end
72
-
73
- def in_test_rails
74
- pwd = Dir.pwd
75
- begin
76
- Dir.chdir(RAILS_DIR)
77
- yield
78
- ensure
79
- Dir.chdir(pwd)
80
- end
81
- end
82
-
83
- def runner(str)
84
- in_test_rails { cmd("rails runner -e test '#{str}'").strip }
85
- end
@@ -1,29 +0,0 @@
1
- require "unit_spec_helper"
2
-
3
- describe Rapns::Daemon::DeliveryQueue do
4
- let(:queue) { Rapns::Daemon::DeliveryQueue.new }
5
-
6
- it 'behaves likes a normal qeue' do
7
- obj = stub
8
- queue.push obj
9
- queue.pop.should == obj
10
- end
11
-
12
- it 'returns false if notifications have not all been processed' do
13
- queue.push stub
14
- queue.notifications_processed?.should be_false
15
- end
16
-
17
- it 'returns false if the queue is empty but notifications have not all been processed' do
18
- queue.push stub
19
- queue.pop
20
- queue.notifications_processed?.should be_false
21
- end
22
-
23
- it 'returns true if all notifications have been processed' do
24
- queue.push stub
25
- queue.pop
26
- queue.notification_processed
27
- queue.notifications_processed?.should be_true
28
- end
29
- end