right_agent 0.13.5 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/right_agent/actors/agent_manager.rb +1 -32
- data/lib/right_agent/agent.rb +243 -230
- data/lib/right_agent/dispatched_cache.rb +4 -5
- data/lib/right_agent/dispatcher.rb +146 -157
- data/lib/right_agent/pid_file.rb +1 -1
- data/lib/right_agent/platform.rb +14 -14
- data/lib/right_agent/scripts/agent_controller.rb +2 -4
- data/lib/right_agent/sender.rb +214 -223
- data/lib/right_agent/serialize/secure_serializer.rb +2 -2
- data/right_agent.gemspec +3 -3
- data/spec/agent_spec.rb +50 -171
- data/spec/dispatched_cache_spec.rb +13 -19
- data/spec/dispatcher_spec.rb +192 -254
- data/spec/sender_spec.rb +212 -168
- metadata +7 -4
data/right_agent.gemspec
CHANGED
@@ -24,8 +24,8 @@ require 'rubygems'
|
|
24
24
|
|
25
25
|
Gem::Specification.new do |spec|
|
26
26
|
spec.name = 'right_agent'
|
27
|
-
spec.version = '0.
|
28
|
-
spec.date = '2012-10-
|
27
|
+
spec.version = '0.14.0'
|
28
|
+
spec.date = '2012-10-01'
|
29
29
|
spec.authors = ['Lee Kirchhoff', 'Raphael Simon', 'Tony Spataro']
|
30
30
|
spec.email = 'lee@rightscale.com'
|
31
31
|
spec.homepage = 'https://github.com/rightscale/right_agent'
|
@@ -40,7 +40,7 @@ Gem::Specification.new do |spec|
|
|
40
40
|
spec.add_dependency('right_support', ['>= 2.4.1', '< 3.0'])
|
41
41
|
spec.add_dependency('right_amqp', '~> 0.4')
|
42
42
|
spec.add_dependency('json', ['~> 1.4'])
|
43
|
-
spec.add_dependency('eventmachine', '
|
43
|
+
spec.add_dependency('eventmachine', ['>= 0.12.10', '< 2.0'])
|
44
44
|
spec.add_dependency('right_popen', '~> 1.0.11')
|
45
45
|
spec.add_dependency('msgpack', '0.4.4')
|
46
46
|
spec.add_dependency('net-ssh', '~> 2.0')
|
data/spec/agent_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright (c) 2009-
|
2
|
+
# Copyright (c) 2009-2012 RightScale Inc
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -240,14 +240,7 @@ describe RightScale::Agent do
|
|
240
240
|
@agent.tags.should include("sample_tag_1")
|
241
241
|
@agent.tags.should include("sample_tag_2")
|
242
242
|
end
|
243
|
-
|
244
|
-
it "for threadpool_size" do
|
245
|
-
@agent = RightScale::Agent.new(:threadpool_size => 5, :identity => @identity)
|
246
|
-
flexmock(@agent).should_receive(:load_actors).and_return(true)
|
247
|
-
@agent.run
|
248
|
-
@agent.dispatcher.em.threadpool_size.should == 5
|
249
|
-
end
|
250
|
-
|
243
|
+
|
251
244
|
end
|
252
245
|
|
253
246
|
describe "" do
|
@@ -312,7 +305,7 @@ describe RightScale::Agent do
|
|
312
305
|
@broker.should_receive(:subscribe).with(hsh(:name => @identity), nil, hsh(:brokers => nil), Proc).
|
313
306
|
and_return(@broker_ids.first(1)).once
|
314
307
|
@agent.run
|
315
|
-
@agent.instance_variable_get(:@
|
308
|
+
@agent.instance_variable_get(:@remaining_queue_setup).should == {@identity => @broker_ids.last(1)}
|
316
309
|
@sender.should_receive(:send_push).with("/registrar/connect", {:agent_identity => @identity, :host => "123",
|
317
310
|
:port => 2, :id => 1, :priority => 1}).once
|
318
311
|
@agent.__send__(:check_status)
|
@@ -422,188 +415,104 @@ describe RightScale::Agent do
|
|
422
415
|
end
|
423
416
|
|
424
417
|
describe "Handling messages" do
|
425
|
-
|
418
|
+
|
426
419
|
it "should use dispatcher to handle requests" do
|
427
420
|
run_in_em do
|
428
421
|
request = RightScale::Request.new("/foo/bar", "payload")
|
429
422
|
@broker.should_receive(:subscribe).with(hsh(:name => @identity), nil, Hash, Proc).
|
430
423
|
and_return(@broker_ids).and_yield(@broker_id, request, @header).once
|
431
|
-
@dispatcher.should_receive(:dispatch).with(request
|
424
|
+
@dispatcher.should_receive(:dispatch).with(request).once
|
432
425
|
@agent.run
|
433
426
|
end
|
434
427
|
end
|
435
428
|
|
436
|
-
it "should
|
429
|
+
it "should publish result from dispatched request to response queue" do
|
437
430
|
run_in_em do
|
438
|
-
|
431
|
+
request = RightScale::Request.new("/foo/bar", "payload")
|
439
432
|
@broker.should_receive(:subscribe).with(hsh(:name => @identity), nil, Hash, Proc).
|
440
|
-
and_return(@broker_ids).and_yield(@broker_id,
|
441
|
-
|
433
|
+
and_return(@broker_ids).and_yield(@broker_id, request, @header).once
|
434
|
+
result = flexmock("result")
|
435
|
+
@dispatcher.should_receive(:dispatch).with(request).and_return(result).once
|
436
|
+
@broker.should_receive(:publish).with(hsh(:name => "response"), result,
|
437
|
+
hsh(:persistent => true, :mandatory => true)).once
|
442
438
|
@agent.run
|
443
439
|
end
|
444
440
|
end
|
445
441
|
|
446
|
-
it "should
|
442
|
+
it "should not publish result from dispatched request if there is none" do
|
447
443
|
run_in_em do
|
448
|
-
|
444
|
+
request = RightScale::Request.new("/foo/bar", "payload")
|
449
445
|
@broker.should_receive(:subscribe).with(hsh(:name => @identity), nil, Hash, Proc).
|
450
|
-
and_return(@broker_ids).and_yield(@broker_id,
|
451
|
-
@
|
452
|
-
@
|
446
|
+
and_return(@broker_ids).and_yield(@broker_id, request, @header).once
|
447
|
+
@dispatcher.should_receive(:dispatch).with(request).and_return(nil).once
|
448
|
+
@broker.should_receive(:publish).never
|
453
449
|
@agent.run
|
454
450
|
end
|
455
451
|
end
|
456
452
|
|
457
|
-
it "should ignore
|
453
|
+
it "should ignore dispatcher duplicate request errors" do
|
458
454
|
run_in_em do
|
459
|
-
request = RightScale::
|
455
|
+
request = RightScale::Request.new("/foo/bar", "payload")
|
460
456
|
@broker.should_receive(:subscribe).with(hsh(:name => @identity), nil, Hash, Proc).
|
461
457
|
and_return(@broker_ids).and_yield(@broker_id, request, @header).once
|
462
|
-
@dispatcher.should_receive(:dispatch).
|
463
|
-
@header.should_receive(:ack).once
|
458
|
+
@dispatcher.should_receive(:dispatch).and_raise(RightScale::Dispatcher::DuplicateRequest).once
|
464
459
|
@agent.run
|
465
460
|
end
|
466
461
|
end
|
467
462
|
|
468
|
-
it "should
|
463
|
+
it "should use sender to handle results" do
|
469
464
|
run_in_em do
|
470
|
-
|
465
|
+
result = RightScale::Result.new("token", "to", "results", "from")
|
471
466
|
@broker.should_receive(:subscribe).with(hsh(:name => @identity), nil, Hash, Proc).
|
472
|
-
and_return(@broker_ids).and_yield(@broker_id,
|
473
|
-
@
|
474
|
-
@agent.run
|
475
|
-
end
|
476
|
-
end
|
477
|
-
|
478
|
-
end
|
479
|
-
|
480
|
-
describe "Tuning heartbeat" do
|
481
|
-
|
482
|
-
it "should tune heartbeat for all broker connections" do
|
483
|
-
run_in_em do
|
484
|
-
@log.should_receive(:info).with(/\[start\] Agent #{@identity} starting; time: .*$/).once
|
485
|
-
@log.should_receive(:info).with(/Reconnecting each broker to tune heartbeat to 45/).once
|
486
|
-
@log.should_receive(:info).with(/Tuned heartbeat to 45 seconds for broker/).twice
|
487
|
-
@agent = RightScale::Agent.new(:user => "me", :identity => @identity)
|
488
|
-
flexmock(@agent).should_receive(:load_actors).and_return(true)
|
489
|
-
flexmock(@agent).should_receive(:update_configuration).with(:heartbeat => 45).and_return(true).once
|
490
|
-
@agent.run
|
491
|
-
@broker.should_receive(:heartbeat=).with(45).once
|
492
|
-
@broker.should_receive(:connect).with("123", 1, 0, 0, true, Proc).and_yield(@broker_id).once
|
493
|
-
@broker.should_receive(:connect).with("123", 2, 1, 1, true, Proc).and_yield(@broker_id2).once
|
494
|
-
flexmock(@agent).should_receive(:setup_queues).with([@broker_id]).once
|
495
|
-
flexmock(@agent).should_receive(:setup_queues).with([@broker_id2]).once
|
496
|
-
@agent.tune_heartbeat(45).should be_nil
|
497
|
-
end
|
498
|
-
end
|
499
|
-
|
500
|
-
it "should tune heartbeat for all broker connections as deferred task" do
|
501
|
-
run_in_em do
|
502
|
-
@log.should_receive(:info).with(/\[start\] Agent #{@identity} starting; time: .*$/).once
|
503
|
-
@log.should_receive(:info).with(/Reconnecting each broker to tune heartbeat to 45/).once
|
504
|
-
@log.should_receive(:info).with(/Tuned heartbeat to 45 seconds for broker/).twice
|
505
|
-
@agent = RightScale::Agent.new(:user => "me", :identity => @identity)
|
506
|
-
flexmock(@agent).should_receive(:load_actors).and_return(true)
|
507
|
-
flexmock(@agent).should_receive(:update_configuration).with(:heartbeat => 45).and_return(true).once
|
508
|
-
@agent.run
|
509
|
-
@broker.should_receive(:heartbeat=).with(45).once
|
510
|
-
@broker.should_receive(:connect).with("123", 1, 0, 0, true, Proc).and_yield(@broker_id).once
|
511
|
-
@broker.should_receive(:connect).with("123", 2, 1, 1, true, Proc).and_yield(@broker_id2).once
|
512
|
-
flexmock(@agent).should_receive(:setup_queues).with([@broker_id]).once
|
513
|
-
flexmock(@agent).should_receive(:setup_queues).with([@broker_id2]).once
|
514
|
-
flexmock(@agent).should_receive(:finish_setup)
|
515
|
-
@agent.defer_task { @agent.tune_heartbeat(45).should be_nil }
|
516
|
-
@agent.__send__(:check_status)
|
517
|
-
@agent.instance_variable_get(:@deferred_tasks).should == []
|
518
|
-
end
|
519
|
-
end
|
520
|
-
|
521
|
-
it "should disable heartbeat for all broker connections" do
|
522
|
-
run_in_em do
|
523
|
-
@log.should_receive(:info).with(/\[start\] Agent #{@identity} starting; time: .*$/).once
|
524
|
-
@log.should_receive(:info).with(/Reconnecting each broker to tune heartbeat to 0/).once
|
525
|
-
@log.should_receive(:info).with(/Disabled heartbeat for broker/).twice
|
526
|
-
@agent = RightScale::Agent.new(:user => "me", :identity => @identity)
|
527
|
-
flexmock(@agent).should_receive(:load_actors).and_return(true)
|
528
|
-
flexmock(@agent).should_receive(:update_configuration).with(:heartbeat => 0).and_return(true).once
|
467
|
+
and_return(@broker_ids).and_yield(@broker_id, result, @header).once
|
468
|
+
@sender.should_receive(:handle_response).with(result).once
|
529
469
|
@agent.run
|
530
|
-
@broker.should_receive(:heartbeat=).with(0).once
|
531
|
-
@broker.should_receive(:connect).with("123", 1, 0, 0, true, Proc).and_yield(@broker_id).once
|
532
|
-
@broker.should_receive(:connect).with("123", 2, 1, 1, true, Proc).and_yield(@broker_id2).once
|
533
|
-
flexmock(@agent).should_receive(:setup_queues).with([@broker_id]).once
|
534
|
-
flexmock(@agent).should_receive(:setup_queues).with([@broker_id2]).once
|
535
|
-
@agent.tune_heartbeat(0).should be_nil
|
536
470
|
end
|
537
471
|
end
|
538
472
|
|
539
|
-
it "should
|
473
|
+
it "should notify sender when a message is received" do
|
540
474
|
run_in_em do
|
541
|
-
|
542
|
-
@
|
543
|
-
|
544
|
-
@
|
545
|
-
@
|
546
|
-
flexmock(@agent).should_receive(:load_actors).and_return(true)
|
547
|
-
flexmock(@agent).should_receive(:update_configuration).with(:heartbeat => 45).and_return(true).once
|
475
|
+
result = RightScale::Result.new("token", "to", "results", "from")
|
476
|
+
@broker.should_receive(:subscribe).with(hsh(:name => @identity), nil, Hash, Proc).
|
477
|
+
and_return(@broker_ids).and_yield(@broker_id, result, @header).once
|
478
|
+
@sender.should_receive(:handle_response).with(result).once
|
479
|
+
@sender.should_receive(:message_received).once
|
548
480
|
@agent.run
|
549
|
-
@broker.should_receive(:heartbeat=).with(45).once
|
550
|
-
@broker.should_receive(:connect).with("123", 1, 0, 0, true, Proc).and_raise(Exception).once
|
551
|
-
@broker.should_receive(:connect).with("123", 2, 1, 1, true, Proc).and_yield(@broker_id2).once
|
552
|
-
flexmock(@agent).should_receive(:setup_queues).with([@broker_id]).never
|
553
|
-
flexmock(@agent).should_receive(:setup_queues).with([@broker_id2]).once
|
554
|
-
@agent.tune_heartbeat(45).should == "Failed to tune heartbeat for brokers [\"#{@broker_id}\"]"
|
555
481
|
end
|
556
482
|
end
|
557
483
|
|
558
|
-
it "should
|
484
|
+
it "should ignore and ack unrecognized messages" do
|
559
485
|
run_in_em do
|
560
|
-
|
561
|
-
@
|
562
|
-
|
563
|
-
@
|
564
|
-
@
|
565
|
-
flexmock(@agent).should_receive(:load_actors).and_return(true)
|
566
|
-
flexmock(@agent).should_receive(:update_configuration).with(:heartbeat => 45).and_return(true).once
|
486
|
+
request = RightScale::Stats.new(nil, nil)
|
487
|
+
@broker.should_receive(:subscribe).with(hsh(:name => @identity), nil, Hash, Proc).
|
488
|
+
and_return(@broker_ids).and_yield(@broker_id, request, @header).once
|
489
|
+
@dispatcher.should_receive(:dispatch).never
|
490
|
+
@header.should_receive(:ack).once
|
567
491
|
@agent.run
|
568
|
-
@broker.should_receive(:heartbeat=).with(45).once
|
569
|
-
@broker.should_receive(:connect).with("123", 1, 0, 0, true, Proc).and_yield(@broker_id).once
|
570
|
-
@broker.should_receive(:connect).with("123", 2, 1, 1, true, Proc).and_yield(@broker_id2).once
|
571
|
-
@broker.should_receive(:connection_status).with({:one_off => 60, :brokers => [@broker_id]}, Proc).and_yield(:failed)
|
572
|
-
@broker.should_receive(:connection_status).with({:one_off => 60, :brokers => [@broker_id2]}, Proc).and_yield(:connected)
|
573
|
-
flexmock(@agent).should_receive(:setup_queues).with([@broker_id]).never
|
574
|
-
flexmock(@agent).should_receive(:setup_queues).with([@broker_id2]).once
|
575
|
-
@agent.tune_heartbeat(45).should be_nil
|
576
492
|
end
|
577
493
|
end
|
578
494
|
|
579
|
-
it "should
|
495
|
+
it "should ack if request dispatch fails" do
|
580
496
|
run_in_em do
|
581
|
-
|
582
|
-
@log.should_receive(:
|
583
|
-
@
|
584
|
-
|
585
|
-
@
|
586
|
-
|
587
|
-
flexmock(@agent).should_receive(:update_configuration).with(:heartbeat => 45).and_return(true).once
|
497
|
+
request = RightScale::Request.new("/foo/bar", "payload")
|
498
|
+
@log.should_receive(:error).with(/Failed to dispatch request/, Exception, :trace).once
|
499
|
+
@broker.should_receive(:subscribe).with(hsh(:name => @identity), nil, Hash, Proc).
|
500
|
+
and_return(@broker_ids).and_yield(@broker_id, request, @header).once
|
501
|
+
@dispatcher.should_receive(:dispatch).and_raise(Exception)
|
502
|
+
@header.should_receive(:ack).once
|
588
503
|
@agent.run
|
589
|
-
@broker.should_receive(:heartbeat=).with(45).once
|
590
|
-
@broker.should_receive(:connect).with("123", 1, 0, 0, true, Proc).and_yield(@broker_id).once
|
591
|
-
@broker.should_receive(:connect).with("123", 2, 1, 1, true, Proc).and_yield(@broker_id2).once
|
592
|
-
flexmock(@agent).should_receive(:setup_queues).with([@broker_id]).and_raise(Exception)
|
593
|
-
flexmock(@agent).should_receive(:setup_queues).with([@broker_id2]).once
|
594
|
-
@agent.tune_heartbeat(45).should be_nil
|
595
504
|
end
|
596
505
|
end
|
597
506
|
|
598
|
-
it "should
|
507
|
+
it "should ack if response delivery fails" do
|
599
508
|
run_in_em do
|
600
|
-
|
601
|
-
@
|
602
|
-
|
603
|
-
|
509
|
+
result = RightScale::Result.new("token", "to", "results", "from")
|
510
|
+
@log.should_receive(:error).with(/Failed to deliver response/, Exception, :trace).once
|
511
|
+
@broker.should_receive(:subscribe).with(hsh(:name => @identity), nil, Hash, Proc).
|
512
|
+
and_return(@broker_ids).and_yield(@broker_id, result, @header).once
|
513
|
+
@sender.should_receive(:handle_response).and_raise(Exception)
|
514
|
+
@header.should_receive(:ack).once
|
604
515
|
@agent.run
|
605
|
-
@broker.should_receive(:heartbeat=).with(45).once
|
606
|
-
@agent.tune_heartbeat(45).should =~ /Failed tuning broker connection heartbeat/
|
607
516
|
end
|
608
517
|
end
|
609
518
|
|
@@ -651,33 +560,8 @@ describe RightScale::Agent do
|
|
651
560
|
end
|
652
561
|
end
|
653
562
|
|
654
|
-
it "should wait to terminate if there are recent dispatches" do
|
655
|
-
@sender.should_receive(:terminate).and_return([0, 20]).once
|
656
|
-
@dispatcher.should_receive(:dispatch_age).and_return(20).and_return(@timer).once
|
657
|
-
flexmock(EM::Timer).should_receive(:new).with(10, Proc).once
|
658
|
-
run_in_em do
|
659
|
-
@agent = RightScale::Agent.new(:user => "me", :identity => @identity)
|
660
|
-
flexmock(@agent).should_receive(:load_actors).and_return(true)
|
661
|
-
@agent.run
|
662
|
-
@agent.terminate
|
663
|
-
end
|
664
|
-
end
|
665
|
-
|
666
|
-
it "should wait to terminate if there are recent unfinished requests or recent dispatches" do
|
667
|
-
@sender.should_receive(:terminate).and_return([1, 21]).once
|
668
|
-
@dispatcher.should_receive(:dispatch_age).and_return(22).once
|
669
|
-
flexmock(EM::Timer).should_receive(:new).with(9, Proc).and_return(@timer).once
|
670
|
-
run_in_em do
|
671
|
-
@agent = RightScale::Agent.new(:user => "me", :identity => @identity)
|
672
|
-
flexmock(@agent).should_receive(:load_actors).and_return(true)
|
673
|
-
@agent.run
|
674
|
-
@agent.terminate
|
675
|
-
end
|
676
|
-
end
|
677
|
-
|
678
563
|
it "should log that terminating and then log the reason for waiting to terminate" do
|
679
564
|
@sender.should_receive(:terminate).and_return([1, 21]).once
|
680
|
-
@dispatcher.should_receive(:dispatch_age).and_return(22).once
|
681
565
|
flexmock(EM::Timer).should_receive(:new).with(9, Proc).and_return(@timer).once
|
682
566
|
run_in_em do
|
683
567
|
@agent = RightScale::Agent.new(:user => "me", :identity => @identity)
|
@@ -691,7 +575,6 @@ describe RightScale::Agent do
|
|
691
575
|
|
692
576
|
it "should not log reason for waiting to terminate if no need to wait" do
|
693
577
|
@sender.should_receive(:terminate).and_return([0, nil]).twice
|
694
|
-
@dispatcher.should_receive(:dispatch_age).and_return(nil).once
|
695
578
|
@broker.should_receive(:close).once
|
696
579
|
flexmock(EM::Timer).should_receive(:new).with(0, Proc).never
|
697
580
|
run_in_em do
|
@@ -707,7 +590,6 @@ describe RightScale::Agent do
|
|
707
590
|
it "should continue with termination after waiting and log that continuing" do
|
708
591
|
@sender.should_receive(:terminate).and_return([1, 10]).twice
|
709
592
|
@sender.should_receive(:dump_requests).and_return(["request"]).once
|
710
|
-
@dispatcher.should_receive(:dispatch_age).and_return(10).once
|
711
593
|
@broker.should_receive(:close).once
|
712
594
|
flexmock(EM::Timer).should_receive(:new).with(20, Proc).and_return(@timer).and_yield.once
|
713
595
|
run_in_em do
|
@@ -725,7 +607,6 @@ describe RightScale::Agent do
|
|
725
607
|
it "should execute block after all brokers have been closed" do
|
726
608
|
@sender.should_receive(:terminate).and_return([1, 10]).twice
|
727
609
|
@sender.should_receive(:dump_requests).and_return(["request"]).once
|
728
|
-
@dispatcher.should_receive(:dispatch_age).and_return(10).once
|
729
610
|
@broker.should_receive(:close).and_yield.once
|
730
611
|
flexmock(EM::Timer).should_receive(:new).with(20, Proc).and_return(@timer).and_yield.once
|
731
612
|
run_in_em do
|
@@ -741,7 +622,6 @@ describe RightScale::Agent do
|
|
741
622
|
it "should stop EM if no block specified" do
|
742
623
|
@sender.should_receive(:terminate).and_return([1, 10]).twice
|
743
624
|
@sender.should_receive(:dump_requests).and_return(["request"]).once
|
744
|
-
@dispatcher.should_receive(:dispatch_age).and_return(10).once
|
745
625
|
@broker.should_receive(:close).and_yield.once
|
746
626
|
flexmock(EM::Timer).should_receive(:new).with(20, Proc).and_return(@timer).and_yield.once
|
747
627
|
run_in_em(stop_event_loop = false) do
|
@@ -762,7 +642,6 @@ describe RightScale::Agent do
|
|
762
642
|
|
763
643
|
it "should terminate immediately if called a second time but should still execute block" do
|
764
644
|
@sender.should_receive(:terminate).and_return([1, 10]).once
|
765
|
-
@dispatcher.should_receive(:dispatch_age).and_return(10).once
|
766
645
|
flexmock(EM::Timer).should_receive(:new).with(20, Proc).and_return(@timer).once
|
767
646
|
@timer.should_receive(:cancel).once
|
768
647
|
@periodic_timer.should_receive(:cancel).once
|
@@ -54,43 +54,37 @@ describe "RightScale::DispatchedCache" do
|
|
54
54
|
context "store" do
|
55
55
|
|
56
56
|
it "should store request token" do
|
57
|
-
@cache.store(@token1
|
57
|
+
@cache.store(@token1)
|
58
58
|
@cache.instance_variable_get(:@cache)[@token1].should == @now.to_i
|
59
59
|
@cache.instance_variable_get(:@lru).should == [@token1]
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should update lru list when store to existing entry" do
|
63
|
-
@cache.store(@token1
|
63
|
+
@cache.store(@token1)
|
64
64
|
@cache.instance_variable_get(:@cache)[@token1].should == @now.to_i
|
65
65
|
@cache.instance_variable_get(:@lru).should == [@token1]
|
66
|
-
@cache.store(@token2
|
66
|
+
@cache.store(@token2)
|
67
67
|
@cache.instance_variable_get(:@cache)[@token2].should == @now.to_i
|
68
68
|
@cache.instance_variable_get(:@lru).should == [@token1, @token2]
|
69
69
|
flexmock(Time).should_receive(:now).and_return(@now += 10)
|
70
|
-
@cache.store(@token1
|
70
|
+
@cache.store(@token1)
|
71
71
|
@cache.instance_variable_get(:@cache)[@token1].should == @now.to_i
|
72
72
|
@cache.instance_variable_get(:@lru).should == [@token2, @token1]
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should remove old cache entries when store new one" do
|
76
|
-
@cache.store(@token1
|
77
|
-
@cache.store(@token2
|
76
|
+
@cache.store(@token1)
|
77
|
+
@cache.store(@token2)
|
78
78
|
@cache.instance_variable_get(:@cache).keys.should =~ [@token1, @token2]
|
79
79
|
@cache.instance_variable_get(:@lru).should == [@token1, @token2]
|
80
80
|
flexmock(Time).should_receive(:now).and_return(@now += RightScale::DispatchedCache::MAX_AGE + 1)
|
81
|
-
@cache.store(@token3
|
81
|
+
@cache.store(@token3)
|
82
82
|
@cache.instance_variable_get(:@cache).keys.should == [@token3]
|
83
83
|
@cache.instance_variable_get(:@lru).should == [@token3]
|
84
84
|
end
|
85
85
|
|
86
|
-
it "should not store anything if this is a shared queue request" do
|
87
|
-
@cache.store(@token1, "shared")
|
88
|
-
@cache.instance_variable_get(:@cache)[@token1].should be_nil
|
89
|
-
@cache.instance_variable_get(:@lru).should be_empty
|
90
|
-
end
|
91
|
-
|
92
86
|
it "should not store anything if token is nil" do
|
93
|
-
@cache.store(nil
|
87
|
+
@cache.store(nil)
|
94
88
|
@cache.instance_variable_get(:@cache).should be_empty
|
95
89
|
@cache.instance_variable_get(:@lru).should be_empty
|
96
90
|
end
|
@@ -100,8 +94,8 @@ describe "RightScale::DispatchedCache" do
|
|
100
94
|
context "serviced_by" do
|
101
95
|
|
102
96
|
it "should return who request was serviced by and make it the most recently used" do
|
103
|
-
@cache.store(@token1
|
104
|
-
@cache.store(@token2
|
97
|
+
@cache.store(@token1)
|
98
|
+
@cache.store(@token2)
|
105
99
|
@cache.instance_variable_get(:@lru).should == [@token1, @token2]
|
106
100
|
@cache.serviced_by(@token1).should == @agent_id
|
107
101
|
@cache.instance_variable_get(:@lru).should == [@token2, @token1]
|
@@ -109,7 +103,7 @@ describe "RightScale::DispatchedCache" do
|
|
109
103
|
|
110
104
|
it "should return nil if request was not previously serviced" do
|
111
105
|
@cache.serviced_by(@token1).should be_nil
|
112
|
-
@cache.store(@token1
|
106
|
+
@cache.store(@token1)
|
113
107
|
@cache.serviced_by(@token1).should == @agent_id
|
114
108
|
@cache.serviced_by(@token2).should be_nil
|
115
109
|
end
|
@@ -123,9 +117,9 @@ describe "RightScale::DispatchedCache" do
|
|
123
117
|
end
|
124
118
|
|
125
119
|
it "should return total and max age" do
|
126
|
-
@cache.store(@token1
|
120
|
+
@cache.store(@token1)
|
127
121
|
flexmock(Time).should_receive(:now).and_return(@now += 10)
|
128
|
-
@cache.store(@token2
|
122
|
+
@cache.store(@token2)
|
129
123
|
@cache.stats.should == {
|
130
124
|
"local total" => 2,
|
131
125
|
"local max age" => "10 sec"
|