Class MockService

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

    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​(Executor executor,
                           com.yahoo.filedistribution.fileacquirer.FileAcquirer fileAcquirer,
                           MockserviceConfig config,
                           com.yahoo.jdisc.Metric metric)
                    throws InterruptedException,
                           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 - used to create threads
        fileAcquirer - used to fetch file from config
        config - the mock config for this service
        Throws:
        InterruptedException - if unable to get data file within timeout
        IOException - if unable to create handler due to some IO errors
    • Method Detail

      • createHandler

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