Navigation Menu

Skip to content

Commit

Permalink
Add tests for EngineNode's status detections for service-provider node
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 30, 2015
1 parent b435819 commit 3c4237f
Showing 1 changed file with 138 additions and 14 deletions.
152 changes: 138 additions & 14 deletions test/unit/test_engine_node.rb
Expand Up @@ -88,25 +88,149 @@ def sender_role
end
end

class ToServiceProvider < self
def node(params)
EngineNode.new(params)
class BufferedEngineNode < EngineNode
private
def create_buffer
[0]
end
end

class NotBufferedEngineNode < EngineNode
private
def create_buffer
[]
end
end

data(:same_role => {
"live" => true,
"role" => Droonga::NodeRole::SERVICE_PROVIDER,
})
def test_forwardable(state)
assert_true(EngineNode.new(:name => "node29:2929/droonga",
:state => state).forwardable?)
end

data(:same_role => {
data(:dead => {
"live" => false,
"role" => Droonga::NodeRole::SERVICE_PROVIDER,
},
:to_absorb_source => {
"live" => true,
"role" => Droonga::NodeRole::ABSORB_SOURCE,
},
:to_absorb_destination => {
"live" => true,
"role" => Droonga::NodeRole::ABSORB_DESTINATION,
})
def test_not_forwardable(state)
assert_false(EngineNode.new(:name => "node29:2929/droonga",
:state => state).forwardable?)
end

data(:same_role_with_no_unprocessed_message => {
:state => {
"live" => true,
"role" => Droonga::NodeRole::SERVICE_PROVIDER,
})
def test_forwardable(state)
assert_true(node(:name => "node29:2929/droonga",
:state => state).forwardable?)
end
},
:class => NotBufferedEngineNode,
})
def test_readable(data)
assert_true(data[:class].new(:name => "node29:2929/droonga",
:state => data[:state]).readable?)
end

data(:dead => { "live" => false })
def test_not_forwardable(state)
assert_false(node(:name => "node29:2929/droonga",
:state => state).forwardable?)
end
data(:dead => {
:state => {
"live" => false,
"role" => Droonga::NodeRole::SERVICE_PROVIDER,
},
:class => NotBufferedEngineNode,
},
:have_unprocessed_message_in_other_node => {
:state => {
"live" => true,
"role" => Droonga::NodeRole::SERVICE_PROVIDER,
"have_unprocessed_messages" => true,
},
:class => NotBufferedEngineNode,
},
:have_unprocessed_message => {
:state => {
"live" => true,
"role" => Droonga::NodeRole::SERVICE_PROVIDER,
},
:class => BufferedEngineNode,
},
:to_absorb_source => {
:state => {
"live" => true,
"role" => Droonga::NodeRole::ABSORB_SOURCE,
},
:class => NotBufferedEngineNode,
},
:to_absorb_destination => {
:state => {
"live" => true,
"role" => Droonga::NodeRole::ABSORB_DESTINATION,
},
:class => NotBufferedEngineNode,
})
def test_not_readable(data)
assert_false(data[:class].new(:name => "node29:2929/droonga",
:state => data[:state]).readable?)
end

data(:same_role => {
"live" => true,
"role" => Droonga::NodeRole::SERVICE_PROVIDER,
},
:to_absorb_source => {
"live" => true,
"role" => Droonga::NodeRole::ABSORB_SOURCE,
},
:to_absorb_destination => {
"live" => true,
"role" => Droonga::NodeRole::ABSORB_DESTINATION,
},
:to_dead => {
"live" => false,
"role" => Droonga::NodeRole::SERVICE_PROVIDER,
},
:to_node_have_unprocessed_message => {
"live" => true,
"role" => Droonga::NodeRole::SERVICE_PROVIDER,
"have_unprocessed_messages" => true,
})
def test_writable(state)
assert_true(EngineNode.new(:name => "node29:2929/droonga",
:state => state).writable?)
end

data(:dead => {
:state => {
"live" => false,
},
:expected => "dead",
},
:readable => {
:state => {
"live" => true,
"role" => Droonga::NodeRole::SERVICE_PROVIDER,
},
:expected => "active",
},
:not_readable_but_writable => {
:state => {
"live" => true,
"role" => Droonga::NodeRole::ABSORB_SOURCE,
},
:expected => "inactive",
})
def test_status(data)
assert_equal(data[:expected],
EngineNode.new(:name => "node29:2929/droonga",
:state => data[:state]).status)
end
end
end

0 comments on commit 3c4237f

Please sign in to comment.