How to setup Spring Data Solr with EmbeddedSolrServer and multicore support? - spring-data-solr

I'm using Spring Data Solr to implement the search module in my project. To enable multicore support, I simply instantiate a HttpSolrServer and then declare a java-based Spring configuration class with #EnableSolrRepositores(multicoreSupport=true). Everything works perfectly, until when I try to write integration test for Solr related codes and schema.
I want to use EmbeddedSolrServer for testing so that the tests can run without depending on an external Solr server, but I can't find a way to configure correctly. Please advise.

This can at this time not be done directly due to DATASOLR-203.
Once the issue mentioned above is resolved you can do it as follows:
#Configuration
#EnableSolrRepositories(multicoreSupport = true)
static class SolrConfiguration {
#Bean
SolrServer solrServer() throws FileNotFoundException {
String solrHome = ResourceUtils.getURL("classpath:your/path/here").getPath();
CoreContainer container = CoreContainer.createAndLoad(solrHome, new File(solrHome + "/solr.xml"));
return new EmbeddedSolrServer(container, null);
}
}

Related

LettuceConnectionFactory with SentinelTopologyProvider

I am using lettuce through the spring boot API org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory .
My bean is configured as
#Bean
public LettuceConnectionFactory lettuceSentinelConnectionFactory() {
RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration(mastername, new HashSet<>(sentinelnodes));
return new LettuceConnectionFactory(sentinelConfig);
}
This works fine, except for reconnecting after topology changes, resulting in exceptions.
io.lettuce.core.RedisCommandExecutionException: READONLY You can't write against a read only slave.
Some bugreports seem to confirm this behaviour .
With great interest I read that lettuce implements a dynamic topology discoverer for sentinels SentinelTopologyProvider, which should fix the issue elegantly.
However I am unable to make the LettuceConnectionFactory use this dynamic SentinelTopologyProvider, and googling did not return anything neither.
Can anyone give a hint or some sample code on how to write this code?

Grails Dashboard says I have no Services

In the process of trying to troubleshoot my Grails SQL Issue, I just realized that the default Grails Splash page says I have 0 Services. I figured this is a separate issue so I made a new question. I'm on Grails 3.3.9. See attached picture. I'm using default scaffolded code here so my index page is calling my list method in the Service. What am I missing here? Service below (excuse my ignorance, I'm coming from Grails 2.3.11):
package TSTSupport
import grails.gorm.services.Service
import grails.gorm.transactions.Transactional
#Service(TST_Customer)
#Transactional
interface TST_CustomerService {
TST_Customer get(Serializable id)
List<TST_Customer> list(Map args)
Long count()
void delete(Serializable id)
TST_Customer save(TST_Customer TST_Customer)
}
Thanks to #JeffScottBrown, I realized that in Grails 3.3.9, the generate-all command creates a gorm data service which is different from a regular service (which is why Grails says I have 0 services). Using create-service is the way to go if you want the actual dashboard to recognize your services.

Set parameter to JUnit5 extension

I wonder how to configure an extension by a test.
Scenario:
The test provides a value that should be used inside the extension.
Current Solution:
The value is defined as field inside the test and used by the extension thru scanning all declared fields and pick the correct one (reflection).
Problem:
This solution is very indirect. People using this extension must know about extension internals and declare the correct fields (type and value). Errors can lead the developer into the right direction, but its a bit of pain by try/error.
Is there a way to use e.g. annotation with value to configure a junit5 extension?
You may either provide configuration parameters and access them via the ExtensionContext at runtime or since 5.1 there's a programmatic way to register customized extension instances via #RegisterExtension.
Example copied from the JUnit 5 User-Guide:
#RegisterExtension
static WebServerExtension server = WebServerExtension.builder()
.enableSecurity(false)
.build();
#Test
void getProductList() {
WebClient webClient = new WebClient();
String serverUrl = server.getServerUrl();
// Use WebClient to connect to web server using serverUrl and verify response
assertEquals(200, webClient.get(serverUrl + "/products").getResponseStatus());
}

How to create multiple ManagedScheduledExecutorService resources in Jaxrs

I'm developing a service using WebSphere Liberty (wlp) and JAX-RS.
I want to run multiple schedulers in my service to do different tasks periodically.
I have installed concurrent-1.0 feature and defined an instance of
#Resource(name ="DefaultManagedScheduledExecutorService")
private ManagedScheduledExecutorService myScheduler;
in my init class which implements ServletContextListener
How I can create some more instances in some other classes?
I can find pointers for ManagedExecutorService like:
http://www.adam-bien.com/roller/abien/entry/injecting_an_executorservice_with_java
I have tried same with ManagedScheduledExecutorService but it didn't work.
But I'm unable to get much info for ManagedScheduledExecutorService resource.
Please provide any links or pointers which could be useful here.
The injection example you have currently is making use of the Default ManagedScheduledExecutorService which is available once you turn on the concurrent-1.0 feature.
To configure additional ManagedScheduledExecutorService's, you can simply define more in your server.xml configuration like this:
<managedScheduledExecutorService jndiName="concurrent/exec1"/>
<managedScheduledExecutorService jndiName="concurrent/exec2"/>
<managedScheduledExecutorService jndiName="concurrent/exec3"/>
However, there is really no reason you should need additional ManagedScheduledExecutorService's unless they are going to have different context service configurations applied for different tasks. For example:
<managedScheduledExecutorService jndiName="concurrent/classloaderExec">
<contextService>
<classloaderContext/>
</contextService>
</managedScheduledExecutorService>
<managedScheduledExecutorService jndiName="concurrent/jeeMetadataExec">
<contextService>
<jeeMetadataContext/>
</contextService>
</managedScheduledExecutorService>
If you simply want to schedule different tasks, say myHourlyTask and myDailyTask, you can still do that with the same ManagedScheduledExecutorService resource:
myScheduler.scheduleAtFixedRate(myHourlyTask, 0, 1, TimeUnit.HOURS);
myScheduler.scheduleAtFixedRate(myDailyTask, 0, 1, TimeUnit.DAYS);
To declare and use ManagedScheduledExecutorService default resource instance in any non-resource class:
/** The scheduler. */
private ManagedScheduledExecutorService monkeyScheduler;
try {
monkeyScheduler = (ManagedScheduledExecutorService)
new InitialContext().lookup("java:comp/DefaultManagedScheduledExecutorService");
} catch (NamingException e) {
e.printStackTrace();
}
Check this page Configuring managed scheduled executors for details how to configure managed executor.
You should be able to use one executor, just call multiple executor.schedule* methods for your different tasks.

ServiceLoader issue in WebLogic12c

I have been trying to refactor our Activiti implementation into using CDI but ran into a number of problems. I've spent way too much time trying to resolve this already, but I just can't let it go...I think I've pinned the problem down now, setting up a clean structured war without involving Activiti and have been able to reproduce what I think is the main problem.
Basically I have jar1 and jar2, both CDI enabled by including META-INF/beans.xml. Both jars specify a class in META-INF/services/test.TheTest pointing to implementations local to respective jar. jar1 depends on jar2. Also, both jars point to an implementation of javax.enterprise.inject.spi.Extension, triggering the scenario. In each implementation of Extension, I have a method like:
public void afterDeploymentValidation(
#Observes AfterDeploymentValidation event, BeanManager beanManager) {
System.out.println("In jar1 extension");
ServiceLoader<TheTest> loader = ServiceLoader.load(TheTest.class);
Iterator<TheTest> serviceIterator = loader.iterator();
List<TheTest> discoveredLookups = new ArrayList<TheTest>();
while (serviceIterator.hasNext()) {
TheTest serviceInstance = (TheTest) serviceIterator.next();
discoveredLookups.add(serviceInstance);
System.out.println(serviceInstance.getClass().getName());
}
}
Now, my problem is that the ServiceLoader does not see any implementations in either case when running WebLogic12c. The same code works perfectly fine in both Jboss 7.1.1 and Glassfish , listing both implementations of the test.TheTest interface.
Is it fair to assume that this is indeed a problem in WebLogic 12c or am I doing something wrong? Please bare in mind that I am simply trying to emulate the production setup we use when incorporating Activiti.
Regards,
/Petter
There is a Classloader Analysis Tool provided with WLS, have you seen if this will help with the diagnosis of your issue.
You can access this tool by going to ip:port/wls-cat/index.jsp
Where port will be the port of the managed server where your application is deployed.