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.



1570
1571
1572
1573
1574
1575
1576
1577
1578
# File 'lib/mdk_runtime.rb', line 1570

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.



1563
1564
1565
# File 'lib/mdk_runtime.rb', line 1563

def dispatcher
  @dispatcher
end

#expectIdxObject

Returns the value of attribute expectIdx.



1563
1564
1565
# File 'lib/mdk_runtime.rb', line 1563

def expectIdx
  @expectIdx
end

#originatorObject

Returns the value of attribute originator.



1563
1564
1565
# File 'lib/mdk_runtime.rb', line 1563

def originator
  @originator
end

#resolvedObject

Returns the value of attribute resolved.



1563
1564
1565
# File 'lib/mdk_runtime.rb', line 1563

def resolved
  @resolved
end

#resolverObject

Returns the value of attribute resolver.



1563
1564
1565
# File 'lib/mdk_runtime.rb', line 1563

def resolver
  @resolver
end

#sentObject

Returns the value of attribute sent.



1563
1564
1565
# File 'lib/mdk_runtime.rb', line 1563

def sent
  @sent
end

#stateObject

Returns the value of attribute state.



1563
1564
1565
# File 'lib/mdk_runtime.rb', line 1563

def state
  @state
end

#urlObject

Returns the value of attribute url.



1563
1564
1565
# File 'lib/mdk_runtime.rb', line 1563

def url
  @url
end

Instance Method Details

#__init_fields__Object



1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
# File 'lib/mdk_runtime.rb', line 1780

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



1702
1703
1704
1705
1706
1707
# File 'lib/mdk_runtime.rb', line 1702

def _getClass()
    
    return "mdk_runtime.FakeWSActor"

    nil
end

#_getField(name) ⇒ Object



1709
1710
1711
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
# File 'lib/mdk_runtime.rb', line 1709

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



1740
1741
1742
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
# File 'lib/mdk_runtime.rb', line 1740

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.



1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
# File 'lib/mdk_runtime.rb', line 1608

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.



1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
# File 'lib/mdk_runtime.rb', line 1654

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.



1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
# File 'lib/mdk_runtime.rb', line 1685

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



1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
# File 'lib/mdk_runtime.rb', line 1590

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



1583
1584
1585
1586
1587
1588
# File 'lib/mdk_runtime.rb', line 1583

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

    nil
end

#onStopObject

The Actor should begin shutting down.



1773
1774
1775
1776
1777
1778
# File 'lib/mdk_runtime.rb', line 1773

def onStop()
    
    nil

    nil
end

#rejectObject

Simulate the remote peer rejecting the socket connect.



1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
# File 'lib/mdk_runtime.rb', line 1624

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.



1640
1641
1642
1643
1644
1645
1646
1647
1648
# File 'lib/mdk_runtime.rb', line 1640

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().



1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
# File 'lib/mdk_runtime.rb', line 1669

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