DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Event-Driven Fractals
  • Easily Update and Reload SSL for a Server and an HTTP Client
  • Writing a Chat With Akka
  • Snowflake Data Processing With Snowpark DataFrames

Trending

  • Multi-Tenancy With Keycloak, Angular, and SpringBoot
  • Five Tools for Data Scientists to 10X their Productivity
  • Selecting the Right Automated Tests
  • Breaking Free From the Cloud With Kamal: Just Enough Orchestration for Your Apps
  1. DZone
  2. Coding
  3. Languages
  4. SOLR With Scala: Basic Introduction to Embedded SOLR

SOLR With Scala: Basic Introduction to Embedded SOLR

If you want to test methods that are creating connections with a remote Solr server, then Embedded Solr is the way to go.

Anurag Srivastava user avatar by
Anurag Srivastava
·
Apr. 11, 17 · Tutorial
Like (2)
Save
Tweet
Share
4.98K Views

Join the DZone community and get the full member experience.

Join For Free

As we discussed in our previous article about Solr with Scala and AkkaHttp, we have used Solr as a service and tried to hit the Solr service with AkkaHttp and spray routes. 

When we want to test methods that are creating connections with a remote Solr server, we have to use Embedded Solr.

What Is Embedded Solr?

Embedded Solr has the same interface as Solr without requiring an HTTP connection. When we “embed” Solr into a Java an application, it provides the exact same API that you would use if you were connecting to a remote Solr instance. We can use embedded Solr for in-memory testing because when we implement test cases, it should not depend on any external resources.

How to Use Embedded Solr

When we wish to use Embedded Solr, we have to follow some basic steps for creating an interface with it.

  1. Add the Solr-Core dependency.
  2. Follow this predefined directory structure:
    solr
      |-test_embedded //name of configuration folder
             |-conf
                 |-lang
                 |-currency.xml
                 |-elevate.xml         
                 |-managed-schema
                 |-param-.json
                 |-protword.txt
                 |-solrconfig.xml
                 |-stopwords.txt
                 |-synonyms.txt
             |-data (Optional if not created than it will create automatically)
             |-core.properties
      |-solr.xml
  3. Now, we are ready to start Embedded Solr in the test set-up. It will shut down it after completes testing.
    override def before() = {
     val container = new CoreContainer()
     container.load()
     server = new EmbeddedSolrServer(container, "test_embedded")
    }
    
    test("test embedded solr"){
      val solrInputDocument = new SolrInputDocument()
      solrInputDocument.addField("id", 1)
      solrInputDocument.addField("name", "test")
      server.add("test_embedded",solrInputDocument)
    
      val parameter = new SolrQuery()
      parameter.set("q", "*:*")
      val result = server.query("test_embedded",parameter)
      val docList = result.getResults()
      val doc = docList.get(0)
      assert(doc.getFirstValue("name").toString().toLowerCase().contains("test"));
    }
    
    override def afterAll(): Unit = {
     server.close
    }

This is a basic code example for testing Embedded Solr. If test case passes successfully, we are ready to test the services. For more examples and code, please refer to the Knoldus GitHub page.

Scala (programming language)

Published at DZone with permission of Anurag Srivastava, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Event-Driven Fractals
  • Easily Update and Reload SSL for a Server and an HTTP Client
  • Writing a Chat With Akka
  • Snowflake Data Processing With Snowpark DataFrames

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: