Skip to content
This repository has been archived by the owner on Mar 9, 2018. It is now read-only.

Commit

Permalink
Merge pull request #109 from equinux/h2_support
Browse files Browse the repository at this point in the history
H2 support
  • Loading branch information
ileitch committed Mar 7, 2013
2 parents 2a85395 + 80ecf31 commit 65c479c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 17 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -23,6 +23,7 @@ platform :jruby do
gem 'activerecord-jdbcpostgresql-adapter'
gem 'activerecord-jdbcmysql-adapter'
gem 'activerecord-jdbcsqlite3-adapter'
gem 'activerecord-jdbch2-adapter'
gem 'jdbc-postgres'
gem 'jruby-openssl'
end
Expand Down
9 changes: 9 additions & 0 deletions config/database.yml
Expand Up @@ -37,3 +37,12 @@ jdbcmysql:
username: rapns_test
password: ""
encoding: utf8

jdbch2:
adapter: h2
url: jdbc:h2:file:/tmp/rapns_test;AUTO_SERVER=TRUE
username: rapns_test
password: ""
pool: 128
timeout: 5000
encoding: utf8
24 changes: 12 additions & 12 deletions lib/generators/templates/add_gcm.rb
Expand Up @@ -17,12 +17,12 @@ def self.up
AddGcm::Rapns::Notification.update_all :type => 'Rapns::Apns::Notification'
AddGcm::Rapns::App.update_all :type => 'Rapns::Apns::App'

change_column_null :rapns_notifications, :type, false
change_column_null :rapns_apps, :type, false
change_column_null :rapns_notifications, :device_token, true
change_column_null :rapns_notifications, :expiry, true
change_column_null :rapns_apps, :environment, true
change_column_null :rapns_apps, :certificate, true
change_column :rapns_notifications, :type, :string, :null => false
change_column :rapns_apps, :type, :string, :null => false
change_column :rapns_notifications, :device_token, :string, { :null => true, :limit => 64 }
change_column :rapns_notifications, :expiry, :integer, { :null => true, :default => 1.day.to_i }
change_column :rapns_apps, :environment, :string, :null => true
change_column :rapns_apps, :certificate, :text, :null => true

change_column :rapns_notifications, :error_description, :text
change_column :rapns_notifications, :sound, :string, :default => 'default'
Expand All @@ -47,7 +47,7 @@ def self.up
Rapns::Notification.update_all(['app_id = ?', app.id], ['app = ?', app.name])
end

change_column_null :rapns_notifications, :app_id, false
change_column :rapns_notifications, :app_id, :integer, :null => false
remove_column :rapns_notifications, :app

remove_index :rapns_notifications, :name => "index_rapns_notifications_multi"
Expand All @@ -60,10 +60,10 @@ def self.down
remove_column :rapns_notifications, :type
remove_column :rapns_apps, :type

change_column_null :rapns_notifications, :device_token, false
change_column_null :rapns_notifications, :expiry, false
change_column_null :rapns_apps, :environment, false
change_column_null :rapns_apps, :certificate, false
change_column :rapns_notifications, :device_token, :string, { :null => false, :limit => 64 }
change_column :rapns_notifications, :expiry, :integer, { :null => false, :default => 1.day.to_i }
change_column :rapns_apps, :environment, :string, :null => false
change_column :rapns_apps, :certificate, :text, :null => false

change_column :rapns_notifications, :error_description, :string
change_column :rapns_notifications, :sound, :string, :default => '1.aiff'
Expand All @@ -87,7 +87,7 @@ def self.down
Rapns::Notification.update_all(['app = ?', app.key], ['app_id = ?', app.id])
end

change_column_null :rapns_notifications, :key, false
change_column :rapns_notifications, :key, :string, :null => false
remove_column :rapns_notifications, :app_id

remove_index :rapns_notifications, :name => "index_rapns_notifications_multi"
Expand Down
2 changes: 1 addition & 1 deletion lib/rapns/daemon/database_reconnectable.rb
Expand Up @@ -54,4 +54,4 @@ def sleep_to_avoid_thrashing
end
end
end
end
end
2 changes: 2 additions & 0 deletions spec/unit/daemon/database_reconnectable_spec.rb
Expand Up @@ -32,6 +32,8 @@ def perform
ActiveRecord::JDBCError
when 'jdbcmysql'
ActiveRecord::JDBCError
when 'jdbch2'
ActiveRecord::JDBCError
else
raise "Please update #{__FILE__} for adapter #{$adapter}"
end
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/daemon/gcm/delivery_spec.rb
Expand Up @@ -38,7 +38,7 @@ def perform

it 'logs that the notification was delivered' do
response.stub(:body => JSON.dump({ 'failure' => 0 }))
logger.should_receive(:info).with("[MyApp] 1 sent to xyz")
logger.should_receive(:info).with("[MyApp] #{notification.id} sent to xyz")
perform
end

Expand Down Expand Up @@ -146,7 +146,7 @@ def perform
{ 'error' => 'NotRegistered' },
{ 'error' => 'Unavailable' }
]}}
let(:error_description) { "Failed to deliver to recipients 0, 1, 2. Errors: Unavailable, NotRegistered, Unavailable. 0, 2 will be retried as notification 2." }
let(:error_description) { "Failed to deliver to recipients 0, 1, 2. Errors: Unavailable, NotRegistered, Unavailable. 0, 2 will be retried as notification #{notification.id + 1}." }
it_should_behave_like 'an notification with some delivery failures'
end
end
Expand All @@ -160,15 +160,15 @@ def perform
{ 'message_id' => '1:000' },
{ 'error' => 'InternalServerError' }
]}}
let(:error_description) { "Failed to deliver to recipients 0, 2. Errors: Unavailable, InternalServerError. 0, 2 will be retried as notification 2." }
let(:error_description) { "Failed to deliver to recipients 0, 2. Errors: Unavailable, InternalServerError. 0, 2 will be retried as notification #{notification.id + 1}." }
it_should_behave_like 'an notification with some delivery failures'
end

describe 'an 503 response' do
before { response.stub(:code => 503) }

it 'logs a warning that the notification will be retried.' do
logger.should_receive(:warn).with("GCM responded with an Service Unavailable Error. Notification 1 will be retired after 2012-10-14 00:00:02 (retry 1).")
logger.should_receive(:warn).with("GCM responded with an Service Unavailable Error. Notification #{notification.id} will be retired after 2012-10-14 00:00:02 (retry 1).")
perform
end

Expand Down

0 comments on commit 65c479c

Please sign in to comment.