Managed Resource Unit Test Failures

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Managed Resource Unit Test Failures

Michael Nilsson
I'm working on publishing a patch against trunk, adding a learning to rank contrib module.  For some reason, our unit tests that hit our config managed resources no longer seem to be recognizing the config/managed endpoint, but they were ok in 4.10.  I've pasted the code with the small test case below.  Anyone have an idea of why the ManagedResource doesn't seem to be registered?

Essentially my test just assertJQ("/config/managed", "/responseHeader/status==0"), and its @BeforeClass init() sets everything up the exact same way that SolrRestletTestBase.java does, except putting a /config/* instead of /schema/*, and uses my solrconfig which has a searchComponent that registers the managed resource.  The managed resource is just a dummy, and the only function in the component that does something is the inform(SolrCore) method.


Error:
<body>
<h2>HTTP ERROR: 404</h2>
<p>Problem accessing /solr/collection1/config/managed. Reason:
<pre>    Can not find: /solr/collection1/config/managed</pre></p>
<hr /><i><small>Powered by Jetty://</small></i>
</body>



TestManaged.java:
public class TestManaged extends RestTestBase {
  
  @BeforeClass
  public static void init() throws Exception {
    String solrconfig = "solrconfig-testend.xml";
    String schema = "schema-testend.xml";
    
    Path tempDir = createTempDir();
    Path coresDir = tempDir.resolve("cores");

    System.setProperty("coreRootDirectory", coresDir.toString());
    System.setProperty("configSetBaseDir", TEST_HOME());

    final SortedMap<ServletHolder,String> extraServlets = new TreeMap<>();
    final ServletHolder solrSchemaRestApi = new ServletHolder("SolrSchemaRestApi", ServerServlet.class);
    solrSchemaRestApi.setInitParameter("org.restlet.application", "org.apache.solr.rest.SolrSchemaRestApi");
    //extraServlets.put(solrSchemaRestApi, "/schema/*");  // '/schema/*' matches '/schema', '/schema/', and '/schema/whatever...'
    extraServlets.put(solrSchemaRestApi, "/config/*");  // '/schema/*' matches '/schema', '/schema/', and '/schema/whatever...'

    Properties props = new Properties();
    props.setProperty("name", DEFAULT_TEST_CORENAME);
    props.setProperty("config", solrconfig);
    props.setProperty("schema", schema);
    props.setProperty("configSet", "collection1");

    writeCoreProperties(coresDir.resolve("core"), props, "SolrRestletTestBase");
    createJettyAndHarness(TEST_HOME(), solrconfig, schema, "/solr", true, extraServlets);
  }


  @Test
  public void testRestManagerEndpoints() throws Exception {
    String request = "/config/managed";
    assertJQ(request, "/responseHeader/status==0");
  }

}




solrconfig-test.xml:
(Contains the SolrCoreAware searchComponent that registers the resource)

...
  <searchComponent name="managedComponent" class="org.apache.solr.testmanaged.ManagedComponent"/>

  <!-- Query request handler managing models and features -->
  <requestHandler name="/query" class="solr.SearchHandler">
    <lst name="defaults">
      <str name="wt">json</str>
      <str name="df">id</str>
    </lst>
    <arr name="last-components">
      <str>managedComponent</str>
    </arr>
  </requestHandler>
...



ManagedComponent.java:
public class ManagedComponent extends SearchComponent implements SolrCoreAware {
  
  public void inform(SolrCore core) {
    core.getRestManager().addManagedResource("/config/test", ManagedStore.class);
  }

  public void prepare(ResponseBuilder rb) throws IOException {}
  public void process(ResponseBuilder rb) throws IOException {}
  public String getDescription() { return null; }
}



ManagedStore.java:  (It is just a dummy class for the test)
public class ManagedStore extends ManagedResource implements ManagedResource.ChildResourceSupport {
  
  public ManagedStore(String resourceId, SolrResourceLoader loader, StorageIO storageIO) throws SolrException {
    super(resourceId, loader, storageIO);
  }
  
  protected void onManagedDataLoadedFromStorage(NamedList<?> managedInitArgs, Object managedData) throws SolrException { }
  
  public Object applyUpdatesToManagedData(Object updates) { return "HELLO UPDATES"; }
  
  public void doDeleteChild(BaseSolrResource endpoint, String childId) { }
  
  public void doGet(BaseSolrResource endpoint, String childId) {
    SolrQueryResponse response = endpoint.getSolrResponse();
    response.add("TEST", "HELLO GET");
  }
  
}


Reply | Threaded
Open this post in threaded view
|

Re: Managed Resource Unit Test Failures

Michael Nilsson
I found what the problem was.  In this commit (https://github.com/apache/lucene-solr/commit/5fde9e39e0d08398f1fc9988a03cb5932180c34a) Noble Paul removed support for the config managed endpoint (https://issues.apache.org/jira/browse/SOLR-6476).  One of the commits associated with this ticket mentioned "refactored bulk schema APIs and other read REST APIs to use standard RequestHandler mechanism".

What do I need to do so that way I can properly hit my /config/test endpoint?  



On Thu, Dec 17, 2015 at 5:36 PM, Michael Nilsson <[hidden email]> wrote:
I'm working on publishing a patch against trunk, adding a learning to rank contrib module.  For some reason, our unit tests that hit our config managed resources no longer seem to be recognizing the config/managed endpoint, but they were ok in 4.10.  I've pasted the code with the small test case below.  Anyone have an idea of why the ManagedResource doesn't seem to be registered?

Essentially my test just assertJQ("/config/managed", "/responseHeader/status==0"), and its @BeforeClass init() sets everything up the exact same way that SolrRestletTestBase.java does, except putting a /config/* instead of /schema/*, and uses my solrconfig which has a searchComponent that registers the managed resource.  The managed resource is just a dummy, and the only function in the component that does something is the inform(SolrCore) method.


Error:
<body>
<h2>HTTP ERROR: 404</h2>
<p>Problem accessing /solr/collection1/config/managed. Reason:
<pre>    Can not find: /solr/collection1/config/managed</pre></p>
<hr /><i><small>Powered by Jetty://</small></i>
</body>



TestManaged.java:
public class TestManaged extends RestTestBase {
  
  @BeforeClass
  public static void init() throws Exception {
    String solrconfig = "solrconfig-testend.xml";
    String schema = "schema-testend.xml";
    
    Path tempDir = createTempDir();
    Path coresDir = tempDir.resolve("cores");

    System.setProperty("coreRootDirectory", coresDir.toString());
    System.setProperty("configSetBaseDir", TEST_HOME());

    final SortedMap<ServletHolder,String> extraServlets = new TreeMap<>();
    final ServletHolder solrSchemaRestApi = new ServletHolder("SolrSchemaRestApi", ServerServlet.class);
    solrSchemaRestApi.setInitParameter("org.restlet.application", "org.apache.solr.rest.SolrSchemaRestApi");
    //extraServlets.put(solrSchemaRestApi, "/schema/*");  // '/schema/*' matches '/schema', '/schema/', and '/schema/whatever...'
    extraServlets.put(solrSchemaRestApi, "/config/*");  // '/schema/*' matches '/schema', '/schema/', and '/schema/whatever...'

    Properties props = new Properties();
    props.setProperty("name", DEFAULT_TEST_CORENAME);
    props.setProperty("config", solrconfig);
    props.setProperty("schema", schema);
    props.setProperty("configSet", "collection1");

    writeCoreProperties(coresDir.resolve("core"), props, "SolrRestletTestBase");
    createJettyAndHarness(TEST_HOME(), solrconfig, schema, "/solr", true, extraServlets);
  }


  @Test
  public void testRestManagerEndpoints() throws Exception {
    String request = "/config/managed";
    assertJQ(request, "/responseHeader/status==0");
  }

}




solrconfig-test.xml:
(Contains the SolrCoreAware searchComponent that registers the resource)

...
  <searchComponent name="managedComponent" class="org.apache.solr.testmanaged.ManagedComponent"/>

  <!-- Query request handler managing models and features -->
  <requestHandler name="/query" class="solr.SearchHandler">
    <lst name="defaults">
      <str name="wt">json</str>
      <str name="df">id</str>
    </lst>
    <arr name="last-components">
      <str>managedComponent</str>
    </arr>
  </requestHandler>
...



ManagedComponent.java:
public class ManagedComponent extends SearchComponent implements SolrCoreAware {
  
  public void inform(SolrCore core) {
    core.getRestManager().addManagedResource("/config/test", ManagedStore.class);
  }

  public void prepare(ResponseBuilder rb) throws IOException {}
  public void process(ResponseBuilder rb) throws IOException {}
  public String getDescription() { return null; }
}



ManagedStore.java:  (It is just a dummy class for the test)
public class ManagedStore extends ManagedResource implements ManagedResource.ChildResourceSupport {
  
  public ManagedStore(String resourceId, SolrResourceLoader loader, StorageIO storageIO) throws SolrException {
    super(resourceId, loader, storageIO);
  }
  
  protected void onManagedDataLoadedFromStorage(NamedList<?> managedInitArgs, Object managedData) throws SolrException { }
  
  public Object applyUpdatesToManagedData(Object updates) { return "HELLO UPDATES"; }
  
  public void doDeleteChild(BaseSolrResource endpoint, String childId) { }
  
  public void doGet(BaseSolrResource endpoint, String childId) {
    SolrQueryResponse response = endpoint.getSolrResponse();
    response.add("TEST", "HELLO GET");
  }
  
}