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

mpochatkin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new b60fed3ff2 IGNITE-21812 Add automatic product version resolve (#3776)
b60fed3ff2 is described below

commit b60fed3ff2265755c78d6217c806104d0e35ced6
Author: Vadim Pakhnushev <8614891+valep...@users.noreply.github.com>
AuthorDate: Thu May 16 18:06:44 2024 +0300

    IGNITE-21812 Add automatic product version resolve (#3776)
---
 .../ignite/internal/properties/IgniteProductVersion.java     |  2 +-
 .../org/apache/ignite/internal/eventlog/ItEventLogTest.java  |  3 ++-
 .../apache/ignite/internal/eventlog/api/IgniteEvents.java    |  1 -
 .../apache/ignite/internal/eventlog/event/EventBuilder.java  | 11 +++--------
 .../ignite/internal/eventlog/event/EventBuilderTest.java     |  3 ++-
 .../ignite/internal/eventlog/event/IgniteEventsTest.java     | 12 +++++++-----
 .../ignite/internal/rest/ItInitializedClusterRestTest.java   |  8 ++------
 .../internal/rest/ItNotInitializedClusterRestTest.java       |  7 ++-----
 8 files changed, 19 insertions(+), 28 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/properties/IgniteProductVersion.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/properties/IgniteProductVersion.java
index 5b85c4137a..3753d6ad1f 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/properties/IgniteProductVersion.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/properties/IgniteProductVersion.java
@@ -52,7 +52,7 @@ public class IgniteProductVersion implements Serializable {
      *     <li>3.1.3-SNAPSHOT</li>
      * </ul>
      */
-    private static final Pattern VERSION_PATTERN = Pattern.compile(
+    public static final Pattern VERSION_PATTERN = Pattern.compile(
             
"(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<maintenance>\\d+)(?:\\.(?<patch>\\d+))?(?:-(?<preRelease>[0-9A-Za-z]+))?"
     );
 
diff --git 
a/modules/eventlog/src/integrationTest/java/org/apache/ignite/internal/eventlog/ItEventLogTest.java
 
b/modules/eventlog/src/integrationTest/java/org/apache/ignite/internal/eventlog/ItEventLogTest.java
index e662a7eee1..2b3c02598a 100644
--- 
a/modules/eventlog/src/integrationTest/java/org/apache/ignite/internal/eventlog/ItEventLogTest.java
+++ 
b/modules/eventlog/src/integrationTest/java/org/apache/ignite/internal/eventlog/ItEventLogTest.java
@@ -33,6 +33,7 @@ import org.apache.ignite.InitParametersBuilder;
 import org.apache.ignite.client.BasicAuthenticator;
 import org.apache.ignite.client.IgniteClient;
 import org.apache.ignite.internal.ClusterPerClassIntegrationTest;
+import org.apache.ignite.internal.properties.IgniteProductVersion;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 
@@ -90,7 +91,7 @@ class ItEventLogTest extends ClusterPerClassIntegrationTest {
         String expectedEventJsonPattern = "\\{"
                 + "\"type\":\"USER_AUTHENTICATED\","
                 + "\"timestamp\":\\d*,"
-                + "\"productVersion\":\".*\","
+                + "\"productVersion\":\"" + 
IgniteProductVersion.VERSION_PATTERN.pattern() + "\","
                 + "\"user\":\\{\"username\":\"" + USERNAME + 
"\",\"authenticationProvider\":\"" + PROVIDER_NAME + "\"},"
                 + "\"fields\":\\{}"
                 + "}";
diff --git 
a/modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/api/IgniteEvents.java
 
b/modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/api/IgniteEvents.java
index 1c0dd86222..12f0a23c78 100644
--- 
a/modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/api/IgniteEvents.java
+++ 
b/modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/api/IgniteEvents.java
@@ -45,7 +45,6 @@ public final class IgniteEvents implements EventFactory {
                 .type(type)
                 .user(user)
                 .timestamp(System.currentTimeMillis())
-                .productVersion("3.0.0")
                 .build();
     }
 
diff --git 
a/modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/event/EventBuilder.java
 
b/modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/event/EventBuilder.java
index 220a608a62..bc62c8e0e6 100644
--- 
a/modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/event/EventBuilder.java
+++ 
b/modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/event/EventBuilder.java
@@ -18,25 +18,20 @@
 package org.apache.ignite.internal.eventlog.event;
 
 import java.util.Map;
-import java.util.regex.Pattern;
 import org.apache.ignite.internal.eventlog.api.Event;
 import org.apache.ignite.internal.eventlog.api.EventFactory;
 import 
org.apache.ignite.internal.eventlog.event.exception.InvalidEventTypeException;
 import 
org.apache.ignite.internal.eventlog.event.exception.InvalidProductVersionException;
 import 
org.apache.ignite.internal.eventlog.event.exception.MissingEventTypeException;
 import 
org.apache.ignite.internal.eventlog.event.exception.MissingEventUserException;
+import org.apache.ignite.internal.properties.IgniteProductVersion;
 
 /**
  * The event builder that should be used only where the {@link EventFactory} 
is not enough to create an event. For example, in tests, where
  * you want to put some special event. In all other cases, use {@link 
EventFactory} to create events.
  */
 public class EventBuilder {
-    // TODO: https://issues.apache.org/jira/browse/IGNITE-21812
-    private static final String DEFAULT_VERSION = "3.0.0";
-
-    private static final Pattern SEMVER_REGEX = Pattern.compile(
-            "(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<maintenance>\\d+)"
-                    + 
"((?<snapshot>-SNAPSHOT)|-(?<alpha>alpha\\d+)|--(?<beta>beta\\d+)|---(?<ea>ea\\d+))?");
+    private static final String DEFAULT_VERSION = 
IgniteProductVersion.CURRENT_VERSION.toString();
 
     private String type;
 
@@ -107,7 +102,7 @@ public class EventBuilder {
             productVersion = DEFAULT_VERSION;
         }
 
-        if (!SEMVER_REGEX.matcher(productVersion).matches()) {
+        if 
(!IgniteProductVersion.VERSION_PATTERN.matcher(productVersion).matches()) {
             throw new InvalidProductVersionException(productVersion);
         }
 
diff --git 
a/modules/eventlog/src/test/java/org/apache/ignite/internal/eventlog/event/EventBuilderTest.java
 
b/modules/eventlog/src/test/java/org/apache/ignite/internal/eventlog/event/EventBuilderTest.java
index 44556ae0c0..59b694c17a 100644
--- 
a/modules/eventlog/src/test/java/org/apache/ignite/internal/eventlog/event/EventBuilderTest.java
+++ 
b/modules/eventlog/src/test/java/org/apache/ignite/internal/eventlog/event/EventBuilderTest.java
@@ -28,6 +28,7 @@ import 
org.apache.ignite.internal.eventlog.event.exception.InvalidEventTypeExcep
 import 
org.apache.ignite.internal.eventlog.event.exception.InvalidProductVersionException;
 import 
org.apache.ignite.internal.eventlog.event.exception.MissingEventTypeException;
 import 
org.apache.ignite.internal.eventlog.event.exception.MissingEventUserException;
+import org.apache.ignite.internal.properties.IgniteProductVersion;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
@@ -84,7 +85,7 @@ class EventBuilderTest {
 
         assertEquals(EVENT_TYPE, event.getType());
         assertThat(event.getTimestamp(), greaterThan(0L));
-        assertEquals("3.0.0", event.getProductVersion());
+        assertEquals(IgniteProductVersion.CURRENT_VERSION.toString(), 
event.getProductVersion());
         assertEquals(EventUser.system(), event.getUser());
         assertEquals(Map.of(), event.getFields());
     }
diff --git 
a/modules/eventlog/src/test/java/org/apache/ignite/internal/eventlog/event/IgniteEventsTest.java
 
b/modules/eventlog/src/test/java/org/apache/ignite/internal/eventlog/event/IgniteEventsTest.java
index 7819288b34..fcae17a3b8 100644
--- 
a/modules/eventlog/src/test/java/org/apache/ignite/internal/eventlog/event/IgniteEventsTest.java
+++ 
b/modules/eventlog/src/test/java/org/apache/ignite/internal/eventlog/event/IgniteEventsTest.java
@@ -24,15 +24,17 @@ import static org.hamcrest.Matchers.equalTo;
 import java.util.stream.Stream;
 import org.apache.ignite.internal.eventlog.api.Event;
 import org.apache.ignite.internal.eventlog.api.IgniteEvents;
+import org.apache.ignite.internal.properties.IgniteProductVersion;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.MethodSource;
 
 class IgniteEventsTest {
-    private static String USER = "test_user";
-    private static String PROVIDER = "test_provider";
+    private static final String USER = "test_user";
 
-    static Stream<Arguments> events() {
+    private static final String PROVIDER = "test_provider";
+
+    private static Stream<Arguments> events() {
         Event connectionClosedEvent = 
IgniteEvents.CONNECTION_CLOSED.create(EventUser.of(USER, PROVIDER));
         Event connectionEstablishedEvent = 
IgniteEvents.USER_AUTHENTICATED.create(EventUser.of(USER, PROVIDER));
 
@@ -41,7 +43,7 @@ class IgniteEventsTest {
                         connectionClosedEvent,
                         Event.builder()
                                 .type("CONNECTION_CLOSED")
-                                .productVersion("3.0.0")
+                                
.productVersion(IgniteProductVersion.CURRENT_VERSION.toString())
                                 
.timestamp(connectionClosedEvent.getTimestamp())
                                 .user(EventUser.of(USER, PROVIDER))
                                 .build()
@@ -50,7 +52,7 @@ class IgniteEventsTest {
                         connectionEstablishedEvent,
                         Event.builder()
                                 .type("USER_AUTHENTICATED")
-                                .productVersion("3.0.0")
+                                
.productVersion(IgniteProductVersion.CURRENT_VERSION.toString())
                                 
.timestamp(connectionEstablishedEvent.getTimestamp())
                                 .user(EventUser.of(USER, PROVIDER))
                                 .build()
diff --git 
a/modules/rest/src/integrationTest/java/org/apache/ignite/internal/rest/ItInitializedClusterRestTest.java
 
b/modules/rest/src/integrationTest/java/org/apache/ignite/internal/rest/ItInitializedClusterRestTest.java
index 0cce5e8cbc..8591d23f52 100644
--- 
a/modules/rest/src/integrationTest/java/org/apache/ignite/internal/rest/ItInitializedClusterRestTest.java
+++ 
b/modules/rest/src/integrationTest/java/org/apache/ignite/internal/rest/ItInitializedClusterRestTest.java
@@ -31,6 +31,7 @@ import com.typesafe.config.Config;
 import com.typesafe.config.ConfigFactory;
 import java.io.IOException;
 import java.net.http.HttpResponse;
+import org.apache.ignite.internal.properties.IgniteProductVersion;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.DisplayName;
 import org.junit.jupiter.api.Test;
@@ -40,11 +41,6 @@ import org.junit.jupiter.api.TestInfo;
  * Test for the REST endpoints in case cluster is initialized.
  */
 public class ItInitializedClusterRestTest extends AbstractRestTestBase {
-    /** <a href="https://semver.org";>semver</a> compatible regex. */
-    private static final String IGNITE_SEMVER_REGEX =
-            "(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<maintenance>\\d+)"
-                    + 
"((?<snapshot>-SNAPSHOT)|-(?<alpha>alpha\\d+)|--(?<beta>beta\\d+)|---(?<ea>ea\\d+))?";
-
     @BeforeEach
     @Override
     void setUp(TestInfo testInfo) throws IOException, InterruptedException {
@@ -249,6 +245,6 @@ public class ItInitializedClusterRestTest extends 
AbstractRestTestBase {
         // Then
         assertThat(response.statusCode(), is(200));
         // And version is a semver
-        assertThat(response.body(), matchesRegex(IGNITE_SEMVER_REGEX));
+        assertThat(response.body(), 
matchesRegex(IgniteProductVersion.VERSION_PATTERN));
     }
 }
diff --git 
a/modules/rest/src/integrationTest/java/org/apache/ignite/internal/rest/ItNotInitializedClusterRestTest.java
 
b/modules/rest/src/integrationTest/java/org/apache/ignite/internal/rest/ItNotInitializedClusterRestTest.java
index 70e74a3085..03d6d6443d 100644
--- 
a/modules/rest/src/integrationTest/java/org/apache/ignite/internal/rest/ItNotInitializedClusterRestTest.java
+++ 
b/modules/rest/src/integrationTest/java/org/apache/ignite/internal/rest/ItNotInitializedClusterRestTest.java
@@ -30,6 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertAll;
 import com.typesafe.config.Config;
 import com.typesafe.config.ConfigFactory;
 import java.net.http.HttpResponse;
+import org.apache.ignite.internal.properties.IgniteProductVersion;
 import org.apache.ignite.internal.rest.api.Problem;
 import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
 import org.junit.jupiter.api.DisplayName;
@@ -41,10 +42,6 @@ import org.junit.jupiter.api.extension.ExtendWith;
  */
 @ExtendWith(WorkDirectoryExtension.class)
 public class ItNotInitializedClusterRestTest extends AbstractRestTestBase {
-    /** <a href="https://semver.org";>semver</a> compatible regex. */
-    private static final String IGNITE_SEMVER_REGEX =
-            
"(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<maintenance>\\d+)((?<snapshot>-SNAPSHOT)|-(?<alpha>alpha\\d+)|--(?<beta>beta\\d+))?";
-
     @Test
     @DisplayName("Node configuration is available when the cluster in not 
initialized")
     void nodeConfiguration() throws Exception {
@@ -116,7 +113,7 @@ public class ItNotInitializedClusterRestTest extends 
AbstractRestTestBase {
         // Then.
         assertThat(response.statusCode(), is(200));
         // And version is a semver.
-        assertThat(response.body(), matchesRegex(IGNITE_SEMVER_REGEX));
+        assertThat(response.body(), 
matchesRegex(IgniteProductVersion.VERSION_PATTERN));
     }
 
     @Test

Reply via email to