Class MockService

  • All Implemented Interfaces:
    com.yahoo.jdisc.handler.RequestHandler, com.yahoo.jdisc.SharedResource

    @Beta
    public class MockService
    extends LoggingRequestHandler
    This is a generic http handler that can be used to mock a service when testing your application on jDISC. Configuration and necessary files are given to the handle in its configuration. Example config:
     <handler id="MockService">
         <config name="container.handler.test.mockservice">
             <file>myresponses.txt</file>
         </config>
         <binding>http://*\/my/service/path1/*</binding>
     </handler>
     
    The file formats supported out of the box is text, see MockService.TextFileHandler. for descriptions of the format.
    Author:
    Ulf Lilleengen
    • Constructor Detail

      • MockService

        public MockService​(java.util.concurrent.Executor executor,
                           com.yahoo.container.logging.AccessLog accessLog,
                           com.yahoo.filedistribution.fileacquirer.FileAcquirer fileAcquirer,
                           MockserviceConfig config,
                           com.yahoo.jdisc.Metric metric)
                    throws java.lang.InterruptedException,
                           java.io.IOException
        Create a mock service that mocks an external service using data provided via file distribution. A custom handler can be created by subclassing and overriding the createHandler method.
        Parameters:
        executor - An Executor used to create threads.
        accessLog - An AccessLog where requests will be logged.
        fileAcquirer - A FileAcquirer which is used to fetch file from config.
        config - A MockserviceConfig for this service.
        Throws:
        java.lang.InterruptedException - if unable to get data file within timeout.
        java.io.IOException - if unable to create handler due to some IO errors.
    • Method Detail

      • createHandler

        protected MockServiceHandler createHandler​(java.io.File dataFile)
                                            throws java.io.IOException
        Create a handler for a file. Override this method to handle a custom file syntax of your own.
        Parameters:
        dataFile - A file to read.
        Returns:
        a MockServiceHandler used to handle requests.
        Throws:
        java.io.IOException - if errors occured when loading the file