Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions impl/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>de.huxhorn.sulky</groupId>
<artifactId>de.huxhorn.sulky.ulid</artifactId>
<groupId>com.github.f4b6a3</groupId>
<artifactId>ulid-creator</artifactId>
</dependency>
<dependency>
<groupId>com.cronutils</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,23 @@
*/
package io.serverlessworkflow.impl;

import de.huxhorn.sulky.ulid.ULID;
import java.security.SecureRandom;
import java.util.concurrent.atomic.AtomicReference;
import com.github.f4b6a3.ulid.UlidFactory;
import java.util.concurrent.ThreadLocalRandom;

/**
* A {@link WorkflowInstanceIdFactory} implementation that generates Monotonic ULIDs as workflow
* instance IDs.
*/
public class MonotonicUlidWorkflowInstanceIdFactory implements WorkflowInstanceIdFactory {

private final ULID ulid;
private final AtomicReference<ULID.Value> currentUlid;
private final UlidFactory factory;

public MonotonicUlidWorkflowInstanceIdFactory() {
this.ulid = new ULID(new SecureRandom());
this.currentUlid = new AtomicReference<>(ulid.nextValue());
factory = UlidFactory.newMonotonicInstance(() -> ThreadLocalRandom.current().nextLong());
}

@Override
public String get() {
return currentUlid
.getAndUpdate(previousUlid -> ulid.nextMonotonicValue(previousUlid))
.toString();
return factory.create().toString();
Comment thread
ricardozanini marked this conversation as resolved.
}
}
8 changes: 4 additions & 4 deletions impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<packaging>pom</packaging>
<properties>
<version.com.h2database>2.4.240</version.com.h2database>
<version.de.huxhorn.sulky>8.3.0</version.de.huxhorn.sulky>
<version.com.github.f4b6a3>5.2.4</version.com.github.f4b6a3>
<version.jakarta.ws.rs>4.0.0</version.jakarta.ws.rs>
<version.net.thisptr>1.6.2</version.net.thisptr>
<version.org.glassfish.jersey>4.0.2</version.org.glassfish.jersey>
Expand Down Expand Up @@ -136,9 +136,9 @@
<version>${version.net.thisptr}</version>
</dependency>
<dependency>
<groupId>de.huxhorn.sulky</groupId>
<artifactId>de.huxhorn.sulky.ulid</artifactId>
<version>${version.de.huxhorn.sulky}</version>
<groupId>com.github.f4b6a3</groupId>
<artifactId>ulid-creator</artifactId>
<version>${version.com.github.f4b6a3}</version>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.impl.test;

import static io.serverlessworkflow.api.WorkflowReader.readWorkflowFromClasspath;
import static org.assertj.core.api.Assertions.assertThat;

import io.serverlessworkflow.impl.WorkflowApplication;
import io.serverlessworkflow.impl.WorkflowDefinition;
import io.serverlessworkflow.impl.WorkflowInstance;
import java.io.IOException;
import java.util.Map;
import org.junit.jupiter.api.Test;

public class WorkflowInstanceIdTest {

@Test
void testWorkflowInstanceHasValidUlidId() throws IOException {
try (WorkflowApplication application = WorkflowApplication.builder().build()) {
WorkflowDefinition definition =
application.workflowDefinition(
readWorkflowFromClasspath("workflows-samples/simple-expression.yaml"));

WorkflowInstance instance = definition.instance(Map.of());
String id = instance.id();

// Verify ULID format: 26 characters, Crockford Base32
assertThat(id).hasSize(26);
assertThat(id).matches("[0-7][0-9A-HJKMNP-TV-Z]{25}");

// Verify uniqueness across instances
String id2 = definition.instance(Map.of()).id();
assertThat(id).isNotEqualTo(id2);
}
}
}
Loading