Class: Quark::MdkRuntime::FakeWSActor

Inherits:
DatawireQuarkCore::QuarkObject show all
Extended by:
DatawireQuarkCore::Static
Defined in:
lib/mdk_runtime.rb

Overview

WSActor implementation for testing purposes.

Constant Summary

Constants included from DatawireQuarkCore::Static

DatawireQuarkCore::Static::Unassigned

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DatawireQuarkCore::Static

_lazy_statics, static, unlazy_statics

Methods inherited from DatawireQuarkCore::QuarkObject

#to_s

Constructor Details

#initialize(originator, resolver, url) ⇒ FakeWSActor

Returns a new instance of FakeWSActor.



1573
1574
1575
1576
1577
1578
1579
1580
1581
# File 'lib/mdk_runtime.rb', line 1573

def initialize(originator, resolver, url)
    
    self.__init_fields__
    (self).url = url
    (self).originator = originator
    (self).resolver = resolver

    nil
end

Instance Attribute Details

#dispatcherObject

Returns the value of attribute dispatcher.



1566
1567
1568
# File 'lib/mdk_runtime.rb', line 1566

def dispatcher
  @dispatcher
end

#expectIdxObject

Returns the value of attribute expectIdx.



1566
1567
1568
# File 'lib/mdk_runtime.rb', line 1566

def expectIdx
  @expectIdx
end

#originatorObject

Returns the value of attribute originator.



1566
1567
1568
# File 'lib/mdk_runtime.rb', line 1566

def originator
  @originator
end

#resolvedObject

Returns the value of attribute resolved.



1566
1567
1568
# File 'lib/mdk_runtime.rb', line 1566

def resolved
  @resolved
end

#resolverObject

Returns the value of attribute resolver.



1566
1567
1568
# File 'lib/mdk_runtime.rb', line 1566

def resolver
  @resolver
end

#sentObject

Returns the value of attribute sent.



1566
1567
1568
# File 'lib/mdk_runtime.rb', line 1566

def sent
  @sent
end

#stateObject

Returns the value of attribute state.



1566
1567
1568
# File 'lib/mdk_runtime.rb', line 1566

def state
  @state
end

#urlObject

Returns the value of attribute url.



1566
1567
1568
# File 'lib/mdk_runtime.rb', line 1566

def url
  @url
end

Instance Method Details

#__init_fields__Object



1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
# File 'lib/mdk_runtime.rb', line 1783

def __init_fields__()
    
    self.url = nil
    self.resolver = nil
    self.resolved = false
    self.dispatcher = nil
    self.originator = nil
    self.sent = ::DatawireQuarkCore::List.new([])
    self.state = "CONNECTING"
    self.expectIdx = 0

    nil
end

#_getClassObject



1705
1706
1707
1708
1709
1710
# File 'lib/mdk_runtime.rb', line 1705

def _getClass()
    
    return "mdk_runtime.FakeWSActor"

    nil
end

#_getField(name) ⇒ Object



1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
# File 'lib/mdk_runtime.rb', line 1712

def _getField(name)
    
    if ((name) == ("url"))
        return (self).url
    end
    if ((name) == ("resolver"))
        return (self).resolver
    end
    if ((name) == ("resolved"))
        return (self).resolved
    end
    if ((name) == ("dispatcher"))
        return (self).dispatcher
    end
    if ((name) == ("originator"))
        return (self).originator
    end
    if ((name) == ("sent"))
        return (self).sent
    end
    if ((name) == ("state"))
        return (self).state
    end
    if ((name) == ("expectIdx"))
        return (self).expectIdx
    end
    return nil

    nil
end

#_setField(name, value) ⇒ Object



1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
# File 'lib/mdk_runtime.rb', line 1743

def _setField(name, value)
    
    if ((name) == ("url"))
        (self).url = ::DatawireQuarkCore.cast(value) { ::String }
    end
    if ((name) == ("resolver"))
        (self).resolver = ::DatawireQuarkCore.cast(value) { ::Quark.mdk_runtime.promise.PromiseResolver }
    end
    if ((name) == ("resolved"))
        (self).resolved = ::DatawireQuarkCore.cast(value) { ::Object }
    end
    if ((name) == ("dispatcher"))
        (self).dispatcher = ::DatawireQuarkCore.cast(value) { ::Quark.mdk_runtime.actors.MessageDispatcher }
    end
    if ((name) == ("originator"))
        (self).originator = ::DatawireQuarkCore.cast(value) { ::Quark.mdk_runtime.actors.Actor }
    end
    if ((name) == ("sent"))
        (self).sent = ::DatawireQuarkCore.cast(value) { ::DatawireQuarkCore::List }
    end
    if ((name) == ("state"))
        (self).state = ::DatawireQuarkCore.cast(value) { ::String }
    end
    if ((name) == ("expectIdx"))
        (self).expectIdx = ::DatawireQuarkCore.cast(value) { ::Integer }
    end

    nil
end

#acceptObject

Simulate the remote peer accepting the socket connect.



1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
# File 'lib/mdk_runtime.rb', line 1611

def accept()
    
    if (@resolved)
        ::Quark.quark.concurrent.Context.runtime().fail("Test bug. already accepted")
    else
        @resolved = true
        (self).state = "CONNECTED"
        (self).resolver.resolve(self)
    end

    nil
end

#closeObject

Simulate the remote peer closing the socket.



1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
# File 'lib/mdk_runtime.rb', line 1657

def close()
    
    if (((self).state) == ("CONNECTED"))
        (self).state = "DISCONNECTED"
        (self).dispatcher.tell(self, ::Quark.mdk_runtime.WSClosed.new(), @originator)
    else
        ::Quark.quark.concurrent.Context.runtime().fail("Test bug. Can't close already closed socket.")
    end

    nil
end

#expectTextMessageObject

Check that a message has been sent via this actor.



1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
# File 'lib/mdk_runtime.rb', line 1688

def expectTextMessage()
    
    if (!(@resolved))
        ::Quark.quark.concurrent.Context.runtime().fail("not connected yet")
        return "unreachable"
    end
    if ((@expectIdx) < (((self).sent).size))
        msg = ((self).sent)[@expectIdx]
        @expectIdx = (@expectIdx) + (1)
        return msg
    end
    ::Quark.quark.concurrent.Context.runtime().fail("no remaining message found")
    return "unreachable"

    nil
end

#onMessage(origin, message) ⇒ Object



1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
# File 'lib/mdk_runtime.rb', line 1593

def onMessage(origin, message)
    
    if ((((::Quark.quark.reflect.QuarkClass.get(::DatawireQuarkCore._getClass(message))).id) == ("quark.String")) && (((self).state) == ("CONNECTED")))
        ((self).sent) << (::DatawireQuarkCore.cast(message) { ::String })
        return
    end
    if ((((::Quark.quark.reflect.QuarkClass.get(::DatawireQuarkCore._getClass(message))).id) == ("mdk_runtime.WSClose")) && (((self).state) == ("CONNECTED")))
        self.close()
        return
    end

    nil
end

#onStart(dispatcher) ⇒ Object



1586
1587
1588
1589
1590
1591
# File 'lib/mdk_runtime.rb', line 1586

def onStart(dispatcher)
    
    (self).dispatcher = dispatcher

    nil
end

#onStopObject

The Actor should begin shutting down.



1776
1777
1778
1779
1780
1781
# File 'lib/mdk_runtime.rb', line 1776

def onStop()
    
    nil

    nil
end

#rejectObject

Simulate the remote peer rejecting the socket connect.



1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
# File 'lib/mdk_runtime.rb', line 1627

def reject()
    
    if (@resolved)
        ::Quark.quark.concurrent.Context.runtime().fail("Test bug. already accepted")
    else
        @resolved = true
        (self).resolver.reject(::Quark.mdk_runtime.WSConnectError.new("connection refused"))
    end

    nil
end

#send(message) ⇒ Object

Simulate the remote peer sending a text message to the client.



1643
1644
1645
1646
1647
1648
1649
1650
1651
# File 'lib/mdk_runtime.rb', line 1643

def send(message)
    
    if (((self).state) != ("CONNECTED"))
        ::Quark.quark.concurrent.Context.runtime().fail("Test bug. Can't send when not connected.")
    end
    (self).dispatcher.tell(self, ::Quark.mdk_runtime.WSMessage.new(message), @originator)

    nil
end

#swallowLogMessagesObject

Skip over any logged messages for purposes of expectTextMessage().



1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
# File 'lib/mdk_runtime.rb', line 1672

def swallowLogMessages()
    
    if (!(@resolved))
        ::Quark.quark.concurrent.Context.runtime().fail("not connected yet")
    end
    while (((@expectIdx) < (((self).sent).size)) && ((((((self).sent)[@expectIdx]).index("mdk_tracing.protocol.LogEvent") or -1)) != (-(1)))) do
        @expectIdx = (@expectIdx) + (1)
    end

    nil
end