# Path: coilmq/scheduler.py
# class FavorReliableSubscriberScheduler(SubscriberPriorityScheduler):
#     """
#     A random delivery scheduler which prefers reliable subscribers.
#     """
# 
#     def choice(self, subscribers, message):
#         """
#         Choose a random connection, favoring those that are reliable from
#         subscriber pool to deliver specified message.
# 
#         @param subscribers: Collection of subscribed connections to destination. 
#         @type subscribers: C{list} of L{coilmq.server.StompConnection}
# 
#         @param message: The message to be delivered. 
#         @type message: L{stompclient.frame.Frame}
# 
#         @return: A random subscriber from the list or None if list is empty.
#         @rtype: L{coilmq.server.StompConnection}
#         """
#         if not subscribers:
#             return None
#         reliable_subscribers = [
#             s for s in subscribers if s.reliable_subscriber]
#         if reliable_subscribers:
#             return random.choice(reliable_subscribers)
#         else:
#             return random.choice(subscribers)
# 
# Path: tests/mock.py
# class MockConnection(object):
# 
#     def __init__(self):
#         self.frames = []
#         self.reliable_subscriber = False
# 
#     def send_frame(self, frame):
#         self.frames.append(frame)
# 
#     def reset(self):
#         self.frames = []


import unittest
from coilmq.scheduler import FavorReliableSubscriberScheduler
from tests.mock import MockConnection
"""
Tests for the scheduler implementation.
"""


__authors__ = ['"Hans Lellelid" <hans@xmpl.org>']
__copyright__ = "Copyright 2009 Hans Lellelid"
__license__ = """Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License."""


class QueueDeliverySchedulerTest(unittest.TestCase):
    """ Tests for various message delivery schedulers. """

    def test_favorReliable(self):
        """ Test the favor reliable delivery scheduler. """

        sched = FavorReliableSubscriberScheduler()


# Path: coilmq/scheduler.py
# class FavorReliableSubscriberScheduler(SubscriberPriorityScheduler):
#     """
#     A random delivery scheduler which prefers reliable subscribers.
#     """
# 
#     def choice(self, subscribers, message):
#         """
#         Choose a random connection, favoring those that are reliable from
#         subscriber pool to deliver specified message.
# 
#         @param subscribers: Collection of subscribed connections to destination. 
#         @type subscribers: C{list} of L{coilmq.server.StompConnection}
# 
#         @param message: The message to be delivered. 
#         @type message: L{stompclient.frame.Frame}
# 
#         @return: A random subscriber from the list or None if list is empty.
#         @rtype: L{coilmq.server.StompConnection}
#         """
#         if not subscribers:
#             return None
#         reliable_subscribers = [
#             s for s in subscribers if s.reliable_subscriber]
#         if reliable_subscribers:
#             return random.choice(reliable_subscribers)
#         else:
#             return random.choice(subscribers)
# 
# Path: tests/mock.py
# class MockConnection(object):
# 
#     def __init__(self):
#         self.frames = []
#         self.reliable_subscriber = False
# 
#     def send_frame(self, frame):
#         self.frames.append(frame)
# 
#     def reset(self):
#         self.frames = []


# Path: tests/test_scheduler.py
import unittest
from coilmq.scheduler import FavorReliableSubscriberScheduler
from tests.mock import MockConnection

"""
Tests for the scheduler implementation.
"""


__authors__ = ['"Hans Lellelid" <hans@xmpl.org>']
__copyright__ = "Copyright 2009 Hans Lellelid"
__license__ = """Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License."""


class QueueDeliverySchedulerTest(unittest.TestCase):
    """ Tests for various message delivery schedulers. """

    def test_favorReliable(self):
        """ Test the favor reliable delivery scheduler. """

        sched = FavorReliableSubscriberScheduler()


        conn1 = MockConnection()