This is an automated email from the ASF dual-hosted git repository.

epugh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr-mcp.git


The following commit(s) were added to refs/heads/main by this push:
     new 88fa114  refactor: replace mutable Date with Instant in DTO records 
(#113)
88fa114 is described below

commit 88fa114e221b8ead488fff27b4305681b62dbc6f
Author: Aditya Parikh <[email protected]>
AuthorDate: Tue Aug 18 16:54:49 2026 -0400

    refactor: replace mutable Date with Instant in DTO records (#113)
    
    Replace java.util.Date with java.time.Instant in SolrMetrics,
    SolrHealthStatus, and CollectionCreationResult records to achieve
    true immutability. Date is mutable and can be modified through
    record accessors, breaking the immutability contract of records.
    
    - Update Dtos.java: Date -> Instant, simplify @JsonFormat annotations
    - Update CollectionService.java: new Date() -> Instant.now()
    - Update CollectionServiceIntegrationTest.java: adapt timestamp assertion
    
    Closes #15
    
    Signed-off-by: Aditya Parikh <[email protected]>
    Signed-off-by: adityamparikh <[email protected]>
    Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
    Co-authored-by: Eric Pugh <[email protected]>
---
 .../apache/solr/mcp/server/collection/CollectionService.java   | 10 +++++-----
 src/main/java/org/apache/solr/mcp/server/collection/Dtos.java  |  8 ++++----
 .../server/collection/CollectionServiceIntegrationTest.java    |  2 +-
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git 
a/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java 
b/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java
index 091ceb2..b034776 100644
--- a/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java
+++ b/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java
@@ -25,8 +25,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import io.micrometer.observation.annotation.Observed;
 import io.modelcontextprotocol.spec.McpSchema.CompleteRequest;
 import java.io.IOException;
+import java.time.Instant;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 import java.util.Locale;
 import org.apache.solr.client.solrj.SolrClient;
@@ -525,7 +525,7 @@ public class CollectionService {
                QueryResponse statsResponse = 
solrClient.query(actualCollection, new 
SolrQuery(ALL_DOCUMENTS_QUERY).setRows(0));
 
                return new SolrMetrics(buildIndexStats(lukeResponse), 
buildQueryStats(statsResponse),
-                               fetchCacheMetrics(actualCollection), 
fetchHandlerMetrics(actualCollection), new Date());
+                               fetchCacheMetrics(actualCollection), 
fetchHandlerMetrics(actualCollection), Instant.now());
        }
 
        /**
@@ -1069,10 +1069,10 @@ public class CollectionService {
                                        new 
SolrQuery(ALL_DOCUMENTS_QUERY).setRows(0));
 
                        return new SolrHealthStatus(true, null, 
pingResponse.getElapsedTime(),
-                                       
statsResponse.getResults().getNumFound(), new Date(), actualCollection, null, 
null);
+                                       
statsResponse.getResults().getNumFound(), Instant.now(), actualCollection, 
null, null);
 
                } catch (Exception e) {
-                       return new SolrHealthStatus(false, e.getMessage(), 
null, null, new Date(), actualCollection, null, null);
+                       return new SolrHealthStatus(false, e.getMessage(), 
null, null, Instant.now(), actualCollection, null, null);
                }
        }
 
@@ -1136,7 +1136,7 @@ public class CollectionService {
                CollectionAdminRequest.createCollection(name, 
effectiveConfigSet, effectiveShards, effectiveRf)
                                .process(solrClient);
 
-               return new CollectionCreationResult(name, true, "Collection 
created successfully", new Date());
+               return new CollectionCreationResult(name, true, "Collection 
created successfully", Instant.now());
        }
 
        /**
diff --git a/src/main/java/org/apache/solr/mcp/server/collection/Dtos.java 
b/src/main/java/org/apache/solr/mcp/server/collection/Dtos.java
index 13a898e..7a37799 100644
--- a/src/main/java/org/apache/solr/mcp/server/collection/Dtos.java
+++ b/src/main/java/org/apache/solr/mcp/server/collection/Dtos.java
@@ -19,7 +19,7 @@ package org.apache.solr.mcp.server.collection;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonInclude;
-import java.util.Date;
+import java.time.Instant;
 
 /**
  * Data Transfer Objects (DTOs) for the Apache Solr MCP Server.
@@ -104,7 +104,7 @@ record SolrMetrics(
                HandlerStats handlerStats,
 
                /** Timestamp when these metrics were collected, formatted as 
ISO 8601 */
-               @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = 
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") Date timestamp) {
+               @JsonFormat(shape = JsonFormat.Shape.STRING) Instant timestamp) 
{
 }
 
 /**
@@ -464,7 +464,7 @@ record SolrHealthStatus(
                Long totalDocuments,
 
                /** Timestamp when this health check was performed, formatted 
as ISO 8601 */
-               @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = 
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") Date lastChecked,
+               @JsonFormat(shape = JsonFormat.Shape.STRING) Instant 
lastChecked,
 
                /** Name of the collection that was checked */
                String collection,
@@ -497,5 +497,5 @@ record CollectionCreationResult(
                String message,
 
                /** Timestamp when the collection was created, formatted as ISO 
8601 */
-               @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = 
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") Date createdAt) {
+               @JsonFormat(shape = JsonFormat.Shape.STRING) Instant createdAt) 
{
 }
diff --git 
a/src/test/java/org/apache/solr/mcp/server/collection/CollectionServiceIntegrationTest.java
 
b/src/test/java/org/apache/solr/mcp/server/collection/CollectionServiceIntegrationTest.java
index e915012..4cad9b0 100644
--- 
a/src/test/java/org/apache/solr/mcp/server/collection/CollectionServiceIntegrationTest.java
+++ 
b/src/test/java/org/apache/solr/mcp/server/collection/CollectionServiceIntegrationTest.java
@@ -173,7 +173,7 @@ class CollectionServiceIntegrationTest {
                assertEquals((long) DOC_COUNT, status.totalDocuments(), "Health 
check should report indexed document count");
 
                assertNotNull(status.lastChecked());
-               assertTrue(System.currentTimeMillis() - 
status.lastChecked().getTime() < 5000);
+               assertTrue(java.time.Duration.between(status.lastChecked(), 
java.time.Instant.now()).toMillis() < 5000);
        }
 
        @Test

Reply via email to