Merge lp:~makyo/juju-gui/sub-rel-counter-1107999 into lp:juju-gui/experimental

Proposed by Madison Scott-Clary
Status: Merged
Merged at revision: 355
Proposed branch: lp:~makyo/juju-gui/sub-rel-counter-1107999
Merge into: lp:juju-gui/experimental
Diff against target: 144 lines (+52/-34)
2 files modified
app/views/topology/relation.js (+3/-5)
test/test_environment_view.js (+49/-29)
To merge this branch: bzr merge lp:~makyo/juju-gui/sub-rel-counter-1107999
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+145217@code.launchpad.net

Description of the change

Correctly count subordinate relations

Subordinate relations were not being properly counted with the new comparison when it came to new services or relations. This was due to object inequality after a component's update method was called. Comparison switched to service modelIds, and test added.

https://codereview.appspot.com/7234048/

To post a comment you must log in.
Revision history for this message
Madison Scott-Clary (makyo) wrote :
Download full text (5.8 KiB)

Reviewers: mp+145217_code.launchpad.net,

Message:
Please take a look.

Description:
Correctly count subordinate relations

Subordinate relations were not being properly counted with the new
comparison when it came to new services or relations. This was due to
object inequality after a component's update method was called.
Comparison switched to service modelIds, and test added.

https://code.launchpad.net/~makyo/juju-gui/sub-rel-counter-1107999/+merge/145217

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/7234048/

Affected files:
   A [revision details]
   M app/views/topology/relation.js
   M test/test_environment_view.js

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: test/test_environment_view.js
=== modified file 'test/test_environment_view.js'
--- test/test_environment_view.js 2013-01-25 12:05:33 +0000
+++ test/test_environment_view.js 2013-01-28 18:14:07 +0000
@@ -193,7 +193,7 @@
          db: db,
          env: env
        });
- var tmp_data = {
+ var addSubordinate = {
          result: [
            ['service', 'add', {
              'subordinate': true,
@@ -206,7 +206,20 @@
              'endpoints':
               [['wordpress', {'role': 'server', 'name': 'juju-info'}],
                ['puppet2', {'role': 'client', 'name': 'juju-info'}]],
- 'id': 'relation-0000000007'
+ 'id': 'new-relation-0000000008'
+ }]
+ ],
+ op: 'delta'
+ };
+ var addRelation = {
+ result: [
+ ['relation', 'add', {
+ 'interface': 'juju-info',
+ 'scope': 'container',
+ 'endpoints':
+ [['mediawiki', {'role': 'server', 'name': 'juju-info'}],
+ ['puppet', {'role': 'client', 'name': 'juju-info'}]],
+ 'id': 'new-relation-0000000009'
            }]
          ],
          op: 'delta'
@@ -216,21 +229,28 @@

        var relationModule = view.topo.modules.RelationModule;

- function validateRelationCount(serviceNode, module) {
+ function validateRelationCount(serviceNode, module, count) {
          var service = d3.select(serviceNode.getDOMNode()).datum();
- return module.subordinateRelationsForService(service).length === 1;
+ return module.subordinateRelationsForService(service)
+ .length === count;
        }

        container.all('.subordinate.service').each(function(service) {
- validateRelationCount(service, relationModule).should.equal(true);
+ validateRelationCount(service, relationModule,
1).should.equal(true);
        });

- db.on_delta({ data: tmp_data });
- view.render();
+ db.on_delta({ data: addSubordinate });
+ view.update();

        container.all('.subordinate.service').each(function(service) {
- validateRelationCount(service, relationModule).should.equal(true);
+ validateRelationCount...

Read more...

Revision history for this message
Brad Crittenden (bac) wrote :

Land as is. Thanks.

https://codereview.appspot.com/7234048/diff/1/app/views/topology/relation.js
File app/views/topology/relation.js (right):

https://codereview.appspot.com/7234048/diff/1/app/views/topology/relation.js#newcode257
app/views/topology/relation.js:257:
vis.selectAll('.service.subordinate')
Hurrah for simplicity

https://codereview.appspot.com/7234048/

Revision history for this message
Nicola Larosa (teknico) wrote :

Land as is.

Very nice, thanks.

https://codereview.appspot.com/7234048/

Revision history for this message
Madison Scott-Clary (makyo) wrote :

*** Submitted:

Correctly count subordinate relations

Subordinate relations were not being properly counted with the new
comparison when it came to new services or relations. This was due to
object inequality after a component's update method was called.
Comparison switched to service modelIds, and test added.

R=bac, teknico
CC=
https://codereview.appspot.com/7234048

https://codereview.appspot.com/7234048/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/views/topology/relation.js'
2--- app/views/topology/relation.js 2013-01-24 19:29:08 +0000
3+++ app/views/topology/relation.js 2013-01-28 18:20:25 +0000
4@@ -254,10 +254,7 @@
5 var vis = topo.vis;
6 var self = this;
7
8- vis.selectAll('.service')
9- .filter(function(d) {
10- return d.subordinate;
11- })
12+ vis.selectAll('.service.subordinate')
13 .selectAll('.sub-rel-block tspan')
14 .text(function(d) {
15 return self.subordinateRelationsForService(d).length;
16@@ -771,7 +768,8 @@
17 */
18 subordinateRelationsForService: function(service) {
19 return this.relations.filter(function(relation) {
20- return (relation.source === service || relation.target === service) &&
21+ return (relation.source.modelId() === service.modelId() ||
22+ relation.target.modelId() === service.modelId()) &&
23 relation.isSubordinate;
24 });
25 },
26
27=== modified file 'test/test_environment_view.js'
28--- test/test_environment_view.js 2013-01-25 12:05:33 +0000
29+++ test/test_environment_view.js 2013-01-28 18:20:25 +0000
30@@ -193,7 +193,7 @@
31 db: db,
32 env: env
33 });
34- var tmp_data = {
35+ var addSubordinate = {
36 result: [
37 ['service', 'add', {
38 'subordinate': true,
39@@ -206,7 +206,20 @@
40 'endpoints':
41 [['wordpress', {'role': 'server', 'name': 'juju-info'}],
42 ['puppet2', {'role': 'client', 'name': 'juju-info'}]],
43- 'id': 'relation-0000000007'
44+ 'id': 'new-relation-0000000008'
45+ }]
46+ ],
47+ op: 'delta'
48+ };
49+ var addRelation = {
50+ result: [
51+ ['relation', 'add', {
52+ 'interface': 'juju-info',
53+ 'scope': 'container',
54+ 'endpoints':
55+ [['mediawiki', {'role': 'server', 'name': 'juju-info'}],
56+ ['puppet', {'role': 'client', 'name': 'juju-info'}]],
57+ 'id': 'new-relation-0000000009'
58 }]
59 ],
60 op: 'delta'
61@@ -216,21 +229,28 @@
62
63 var relationModule = view.topo.modules.RelationModule;
64
65- function validateRelationCount(serviceNode, module) {
66+ function validateRelationCount(serviceNode, module, count) {
67 var service = d3.select(serviceNode.getDOMNode()).datum();
68- return module.subordinateRelationsForService(service).length === 1;
69+ return module.subordinateRelationsForService(service)
70+ .length === count;
71 }
72
73 container.all('.subordinate.service').each(function(service) {
74- validateRelationCount(service, relationModule).should.equal(true);
75+ validateRelationCount(service, relationModule, 1).should.equal(true);
76 });
77
78- db.on_delta({ data: tmp_data });
79- view.render();
80+ db.on_delta({ data: addSubordinate });
81+ view.update();
82
83 container.all('.subordinate.service').each(function(service) {
84- validateRelationCount(service, relationModule).should.equal(true);
85+ validateRelationCount(service, relationModule, 1).should.equal(true);
86 });
87+
88+ db.on_delta({ data: addRelation });
89+ view.update();
90+
91+ validateRelationCount(container.one('.subordinate.service'),
92+ relationModule, 2).should.equal(true);
93 });
94
95 it('must not duplicate nodes when services are added', function() {
96@@ -238,27 +258,27 @@
97 container: container,
98 db: db,
99 env: env
100- }),
101- tmp_data = {
102- result: [
103- ['service', 'add', {
104- 'subordinate': true,
105- 'charm': 'cs:precise/puppet-2',
106- 'id': 'puppet2'
107- }],
108- ['service', 'add', {
109- 'charm': 'cs:precise/mysql-6',
110- 'id': 'mysql2'
111- }],
112- ['unit', 'add', {
113- 'machine': 0,
114- 'agent-state': 'started',
115- 'public-address': '192.168.122.222',
116- 'id': 'mysql2/0'
117- }]
118- ],
119- op: 'delta'
120- };
121+ });
122+ var tmp_data = {
123+ result: [
124+ ['service', 'add', {
125+ 'subordinate': true,
126+ 'charm': 'cs:precise/puppet-2',
127+ 'id': 'puppet2'
128+ }],
129+ ['service', 'add', {
130+ 'charm': 'cs:precise/mysql-6',
131+ 'id': 'mysql2'
132+ }],
133+ ['unit', 'add', {
134+ 'machine': 0,
135+ 'agent-state': 'started',
136+ 'public-address': '192.168.122.222',
137+ 'id': 'mysql2/0'
138+ }]
139+ ],
140+ op: 'delta'
141+ };
142 view.render();
143
144 db.on_delta({ data: tmp_data });

Subscribers

People subscribed via source and target branches