示例#1
0
    def testParsing(self):
        files = [
            'test/local_cluster.yaml',
            'test/migration_1.yaml',
            'test/migration_2.yaml',
            'test/migration_3.yaml',
            'examples/cluster.yaml',
            'examples/local_cluster.yaml',
            'examples/standalone.yaml'
        ]
        for f in files:
            print
            filepath = paths.path(f)
            with open(filepath) as specfile:

                loaded_representation = yaml.load(specfile)
                timestamp = timestamper.from_seconds(os.path.getmtime(filepath))

                helper_loaded_configuration = try_load_file(filepath)
                manually_loaded_configuration = Configuration(loaded_representation, timestamp)

                self.assertEqual(manually_loaded_configuration.representation(),
                                 helper_loaded_configuration.representation())

                self.assertEqual(manually_loaded_configuration.timestamp,
                                 helper_loaded_configuration.timestamp)

                self.assertEqual(Configuration(helper_loaded_configuration.representation(), helper_loaded_configuration.timestamp).representation(),
                                 helper_loaded_configuration.representation())
 def testClient(self):
     cfg_filepath = 'test/local_cluster.yaml'
     cfg = configuration.try_load_file(paths.path(cfg_filepath))
     coordinator_server = CoordinatorServer(cfg.master_coordinator_id, paths.path(cfg_filepath))
     coordinator_server_task = coio.stackless.tasklet(coordinator_server.serve)()
     coio.stackless.schedule()
     self.new_configuration = None
     self.new_timestamp = None
     client = CoordinatorClient(coordinators=[cfg.master_coordinator], callbacks=[self.callback])
     client.start()
     for i in xrange(0, 1000):
         coio.sleep(0.01)
         if self.new_configuration or self.new_timestamp:
             break
     assert cfg.representation() == self.new_configuration.representation()
     print 'Fetched configuration: ', self.new_configuration
     print 'Timestamp: ', self.new_timestamp
     coordinator_server_task.kill()
 def testPersistence(self):
     files = [
         'test/local_cluster.yaml',
         'test/migration_1.yaml',
         'test/migration_2.yaml',
         'test/migration_3.yaml',
         'examples/cluster.yaml',
         'examples/local_cluster.yaml',
         'examples/standalone.yaml'
     ]
     for f in files:
         configuration_directory = self.tempdir()
         cache = ConfigurationCache(configuration_directory, 'test')
         filepath = paths.path(f)
         cfg = configuration.try_load_file(filepath)
         for i in xrange(0, 10):
             cfg.timestamp = timestamper.now()
             cache.cache_configuration(cfg)
             read_configuration = cache.get_configuration()
             self.assertEqual(read_configuration.representation(), cfg.representation())
             self.assertEqual(read_configuration.timestamp, cfg.timestamp)