Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module deployments are deduplicated when static merge deployments(#338) #1035

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private void addStaticBiz(List<BizArchive> bizArchives) throws IOException {

for (BizArchive bizArchive : bizArchives) {
Biz biz = ArkClient.getBizFactoryService().createBiz(bizArchive);
ArkClient.getBizManagerService().registerBiz(biz);
ArkClient.getBizManagerService().registerBizIfAbsent(biz);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void processStaticBizFromClasspath(PipelineContext pipelineContext) throw
List<BizArchive> bizArchives = executableArchive.getBizArchives();
for (BizArchive bizArchive : bizArchives) {
Biz biz = bizFactoryService.createBiz(bizArchive);
bizManagerService.registerBiz(biz);
bizManagerService.registerBizIfAbsent(biz);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,20 @@
public ConcurrentHashMap<String, ConcurrentHashMap<String, Biz>> getBizRegistration() {
return bizRegistration;
}

@Override
public boolean registerBizIfAbsent(Biz biz) {
AssertUtils.assertNotNull(biz, "Biz must not be null.");
AssertUtils.isTrue(biz.getBizState() == BizState.RESOLVED, "BizState must be RESOLVED.");
if (getBiz(biz.getBizName(), biz.getBizVersion()) == null) {
bizRegistration.putIfAbsent(biz.getBizName(), new ConcurrentHashMap<>(16));
synchronized (bizRegistration.get(biz.getBizName())) {
if (getBiz(biz.getBizName(), biz.getBizVersion()) == null) {
ConcurrentHashMap<String, Biz> bizCache = bizRegistration.get(biz.getBizName());
return bizCache.put(biz.getBizVersion(), biz) == null;
}
}

Check warning on line 236 in sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/biz/BizManagerServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/biz/BizManagerServiceImpl.java#L236

Added line #L236 was not covered by tests
}
return false;

Check warning on line 238 in sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/biz/BizManagerServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/biz/BizManagerServiceImpl.java#L238

Added line #L238 was not covered by tests
}
Comment on lines +226 to +239
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Thread safety concern in double-checked locking implementation.

The synchronized block locks on a ConcurrentHashMap value which could potentially be replaced by another thread, leading to synchronization issues. Consider using a more robust synchronization approach.

Here's a suggested implementation that addresses this concern:

     @Override
     public boolean registerBizIfAbsent(Biz biz) {
         AssertUtils.assertNotNull(biz, "Biz must not be null.");
         AssertUtils.isTrue(biz.getBizState() == BizState.RESOLVED, "BizState must be RESOLVED.");
-        if (getBiz(biz.getBizName(), biz.getBizVersion()) == null) {
-            bizRegistration.putIfAbsent(biz.getBizName(), new ConcurrentHashMap<>(16));
-            synchronized (bizRegistration.get(biz.getBizName())) {
-                if (getBiz(biz.getBizName(), biz.getBizVersion()) == null) {
-                    ConcurrentHashMap<String, Biz> bizCache = bizRegistration.get(biz.getBizName());
-                    return bizCache.put(biz.getBizVersion(), biz) == null;
-                }
-            }
+        String bizName = biz.getBizName();
+        String bizVersion = biz.getBizVersion();
+        
+        // Create the version map if absent
+        bizRegistration.putIfAbsent(bizName, new ConcurrentHashMap<>(16));
+        ConcurrentHashMap<String, Biz> bizCache = bizRegistration.get(bizName);
+        
+        // Use putIfAbsent for atomic check-then-act
+        return bizCache.putIfAbsent(bizVersion, biz) == null;
         }
-        return false;
     }

The suggested implementation:

  1. Eliminates the need for explicit synchronization by leveraging ConcurrentHashMap's atomic operations
  2. Reduces redundant getBiz calls
  3. Maintains thread safety while improving performance
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public boolean registerBizIfAbsent(Biz biz) {
AssertUtils.assertNotNull(biz, "Biz must not be null.");
AssertUtils.isTrue(biz.getBizState() == BizState.RESOLVED, "BizState must be RESOLVED.");
if (getBiz(biz.getBizName(), biz.getBizVersion()) == null) {
bizRegistration.putIfAbsent(biz.getBizName(), new ConcurrentHashMap<>(16));
synchronized (bizRegistration.get(biz.getBizName())) {
if (getBiz(biz.getBizName(), biz.getBizVersion()) == null) {
ConcurrentHashMap<String, Biz> bizCache = bizRegistration.get(biz.getBizName());
return bizCache.put(biz.getBizVersion(), biz) == null;
}
}
}
return false;
}
public boolean registerBizIfAbsent(Biz biz) {
AssertUtils.assertNotNull(biz, "Biz must not be null.");
AssertUtils.isTrue(biz.getBizState() == BizState.RESOLVED, "BizState must be RESOLVED.");
String bizName = biz.getBizName();
String bizVersion = biz.getBizVersion();
// Create the version map if absent
bizRegistration.putIfAbsent(bizName, new ConcurrentHashMap<>(16));
ConcurrentHashMap<String, Biz> bizCache = bizRegistration.get(bizName);
// Use putIfAbsent for atomic check-then-act
return bizCache.putIfAbsent(bizVersion, biz) == null;
}

💡 Codebase verification

Add concurrent test cases for registerBizIfAbsent method

The current test suite (BizManagerServiceTest.java) lacks concurrent testing for the registerBizIfAbsent method, while the codebase already has examples of concurrent testing patterns in ClassLoaderConcurrencyTest.java. Consider adding test cases that:

  • Use multiple threads to register the same biz simultaneously
  • Verify that only one registration succeeds
  • Follow the concurrent testing pattern from ClassLoaderConcurrencyTest.java using CountDownLatch and ThreadPoolExecutor
🔗 Analysis chain

Consider adding unit tests for concurrent scenarios.

The new method handles concurrent registration attempts, but there are no visible tests verifying this behavior.

Let's check for existing concurrent tests:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for test files related to BizManagerServiceImpl
fd -e java -e groovy "BizManagerServiceImpl.*Test" 

# Search for concurrent testing patterns
rg -i "concurrent|thread|async" -A 5 -B 5 "BizManagerServiceImpl.*Test"

Length of output: 194


Script:

#!/bin/bash
# Let's try a broader search for test files related to BizManager
fd -e java -e groovy "BizManager.*Test"

# Search for any test files in the same directory as BizManagerServiceImpl
fd -e java -e groovy ".*Test" sofa-ark-parent/core-impl/container/src/test/

# Let's also check if there are any test files that might test concurrent behavior
rg -i "concurrent.*test|thread.*test" sofa-ark-parent/core-impl/container/src/test/

Length of output: 5464


Script:

#!/bin/bash
# Let's examine the content of BizManagerServiceTest.java to see if it has any concurrent testing
cat sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/service/biz/BizManagerServiceTest.java

# Also check ClassLoaderConcurrencyTest.java as it might have patterns we can follow
cat sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/service/classloader/ClassLoaderConcurrencyTest.java

Length of output: 10909

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
*/
package com.alipay.sofa.ark.container.pipeline;

import com.alipay.sofa.ark.api.ArkClient;
import com.alipay.sofa.ark.container.model.BizModel;
import com.alipay.sofa.ark.loader.DirectoryBizArchive;
import com.alipay.sofa.ark.loader.JarBizArchive;
import com.alipay.sofa.ark.spi.archive.BizArchive;
import com.alipay.sofa.ark.spi.archive.ExecutableArchive;
import com.alipay.sofa.ark.spi.archive.PluginArchive;
import com.alipay.sofa.ark.spi.model.Biz;
import com.alipay.sofa.ark.spi.model.Plugin;
import com.alipay.sofa.ark.spi.pipeline.PipelineContext;
import com.alipay.sofa.ark.spi.service.biz.BizFactoryService;
Expand All @@ -31,16 +33,17 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockedStatic;

import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

import static com.alipay.sofa.ark.api.ArkConfigs.getStringValue;
import static com.alipay.sofa.ark.api.ArkConfigs.setSystemProperty;
import static com.alipay.sofa.ark.spi.constant.Constants.CONFIG_SERVER_ADDRESS;
import static com.alipay.sofa.ark.spi.constant.Constants.MASTER_BIZ;
import static com.alipay.sofa.ark.spi.constant.Constants.*;
import static java.util.Arrays.asList;
import static org.mockito.Mockito.*;

Expand Down Expand Up @@ -152,13 +155,25 @@ public void testProcess() throws Exception {

@Test
public void testProcessStaticBizFromClasspath() throws Exception {

BizArchive bizArchive = mock(BizArchive.class);
when(executableArchive.getBizArchives()).thenReturn(asList(bizArchive));

handleArchiveStage.processStaticBizFromClasspath(pipelineContext);
verify(bizFactoryService, times(1)).createBiz((bizArchive));
verify(bizManagerService, times(1)).registerBiz(null);
MockedStatic<ArkClient> arkClientMockedStatic = mockStatic(ArkClient.class);
arkClientMockedStatic.when(ArkClient::getBizManagerService).thenReturn(bizManagerService);
try {
BizArchive bizArchive = mock(BizArchive.class);
Manifest manifest = new Manifest();
Attributes mainAttributes = manifest.getMainAttributes();
mainAttributes.putValue(ARK_BIZ_NAME, "biz1");
mainAttributes.putValue(ARK_BIZ_VERSION, "0.0.1");
when(bizArchive.getManifest()).thenReturn(manifest);
ConcurrentHashMap<String, ConcurrentHashMap<String, Biz>> map = new ConcurrentHashMap<>();
when(bizManagerService.getBizRegistration()).thenReturn(map);
when(executableArchive.getBizArchives()).thenReturn(asList(bizArchive));

handleArchiveStage.processStaticBizFromClasspath(pipelineContext);
verify(bizFactoryService, times(1)).createBiz((bizArchive));
verify(bizManagerService, times(1)).registerBizIfAbsent(null);
Comment on lines +171 to +173
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix incorrect test data: Biz object is null

The test is verifying registerBizIfAbsent(null), which doesn't properly test the deduplication logic. The Biz object should be created from the mocked BizArchive.

Apply this diff to fix the test:

-            handleArchiveStage.processStaticBizFromClasspath(pipelineContext);
-            verify(bizFactoryService, times(1)).createBiz((bizArchive));
-            verify(bizManagerService, times(1)).registerBizIfAbsent(null);
+            Biz mockBiz = mock(Biz.class);
+            when(bizFactoryService.createBiz(bizArchive)).thenReturn(mockBiz);
+            
+            handleArchiveStage.processStaticBizFromClasspath(pipelineContext);
+            
+            verify(bizFactoryService, times(1)).createBiz(bizArchive);
+            verify(bizManagerService, times(1)).registerBizIfAbsent(mockBiz);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
handleArchiveStage.processStaticBizFromClasspath(pipelineContext);
verify(bizFactoryService, times(1)).createBiz((bizArchive));
verify(bizManagerService, times(1)).registerBizIfAbsent(null);
Biz mockBiz = mock(Biz.class);
when(bizFactoryService.createBiz(bizArchive)).thenReturn(mockBiz);
handleArchiveStage.processStaticBizFromClasspath(pipelineContext);
verify(bizFactoryService, times(1)).createBiz(bizArchive);
verify(bizManagerService, times(1)).registerBizIfAbsent(mockBiz);

}finally {
arkClientMockedStatic.close();
}
Comment on lines +158 to +176
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance test coverage for deduplication scenarios

The test should verify the actual deduplication behavior by testing scenarios where:

  1. A Biz doesn't exist (should register)
  2. A Biz already exists (should skip registration)

Consider adding these test cases:

+    @Test
+    public void testProcessStaticBizFromClasspathWithExistingBiz() throws Exception {
+        MockedStatic<ArkClient> arkClientMockedStatic = mockStatic(ArkClient.class);
+        arkClientMockedStatic.when(ArkClient::getBizManagerService).thenReturn(bizManagerService);
+        try {
+            // Setup existing biz
+            ConcurrentHashMap<String, ConcurrentHashMap<String, Biz>> map = new ConcurrentHashMap<>();
+            ConcurrentHashMap<String, Biz> versionMap = new ConcurrentHashMap<>();
+            Biz existingBiz = mock(Biz.class);
+            when(existingBiz.getBizName()).thenReturn("biz1");
+            when(existingBiz.getBizVersion()).thenReturn("0.0.1");
+            versionMap.put("0.0.1", existingBiz);
+            map.put("biz1", versionMap);
+            when(bizManagerService.getBizRegistration()).thenReturn(map);
+
+            // Setup new biz with same name and version
+            BizArchive bizArchive = mock(BizArchive.class);
+            Manifest manifest = new Manifest();
+            Attributes mainAttributes = manifest.getMainAttributes();
+            mainAttributes.putValue(ARK_BIZ_NAME, "biz1");
+            mainAttributes.putValue(ARK_BIZ_VERSION, "0.0.1");
+            when(bizArchive.getManifest()).thenReturn(manifest);
+            when(executableArchive.getBizArchives()).thenReturn(asList(bizArchive));
+
+            Biz newBiz = mock(Biz.class);
+            when(bizFactoryService.createBiz(bizArchive)).thenReturn(newBiz);
+
+            handleArchiveStage.processStaticBizFromClasspath(pipelineContext);
+
+            // Verify biz was created but not registered due to existing registration
+            verify(bizFactoryService, times(1)).createBiz(bizArchive);
+            verify(bizManagerService, times(1)).registerBizIfAbsent(newBiz);
+            verify(bizManagerService, never()).registerBiz(any());
+        } finally {
+            arkClientMockedStatic.close();
+        }
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
MockedStatic<ArkClient> arkClientMockedStatic = mockStatic(ArkClient.class);
arkClientMockedStatic.when(ArkClient::getBizManagerService).thenReturn(bizManagerService);
try {
BizArchive bizArchive = mock(BizArchive.class);
Manifest manifest = new Manifest();
Attributes mainAttributes = manifest.getMainAttributes();
mainAttributes.putValue(ARK_BIZ_NAME, "biz1");
mainAttributes.putValue(ARK_BIZ_VERSION, "0.0.1");
when(bizArchive.getManifest()).thenReturn(manifest);
ConcurrentHashMap<String, ConcurrentHashMap<String, Biz>> map = new ConcurrentHashMap<>();
when(bizManagerService.getBizRegistration()).thenReturn(map);
when(executableArchive.getBizArchives()).thenReturn(asList(bizArchive));
handleArchiveStage.processStaticBizFromClasspath(pipelineContext);
verify(bizFactoryService, times(1)).createBiz((bizArchive));
verify(bizManagerService, times(1)).registerBizIfAbsent(null);
}finally {
arkClientMockedStatic.close();
}
MockedStatic<ArkClient> arkClientMockedStatic = mockStatic(ArkClient.class);
arkClientMockedStatic.when(ArkClient::getBizManagerService).thenReturn(bizManagerService);
try {
BizArchive bizArchive = mock(BizArchive.class);
Manifest manifest = new Manifest();
Attributes mainAttributes = manifest.getMainAttributes();
mainAttributes.putValue(ARK_BIZ_NAME, "biz1");
mainAttributes.putValue(ARK_BIZ_VERSION, "0.0.1");
when(bizArchive.getManifest()).thenReturn(manifest);
ConcurrentHashMap<String, ConcurrentHashMap<String, Biz>> map = new ConcurrentHashMap<>();
when(bizManagerService.getBizRegistration()).thenReturn(map);
when(executableArchive.getBizArchives()).thenReturn(asList(bizArchive));
handleArchiveStage.processStaticBizFromClasspath(pipelineContext);
verify(bizFactoryService, times(1)).createBiz((bizArchive));
verify(bizManagerService, times(1)).registerBizIfAbsent(null);
}finally {
arkClientMockedStatic.close();
}
@Test
public void testProcessStaticBizFromClasspathWithExistingBiz() throws Exception {
MockedStatic<ArkClient> arkClientMockedStatic = mockStatic(ArkClient.class);
arkClientMockedStatic.when(ArkClient::getBizManagerService).thenReturn(bizManagerService);
try {
// Setup existing biz
ConcurrentHashMap<String, ConcurrentHashMap<String, Biz>> map = new ConcurrentHashMap<>();
ConcurrentHashMap<String, Biz> versionMap = new ConcurrentHashMap<>();
Biz existingBiz = mock(Biz.class);
when(existingBiz.getBizName()).thenReturn("biz1");
when(existingBiz.getBizVersion()).thenReturn("0.0.1");
versionMap.put("0.0.1", existingBiz);
map.put("biz1", versionMap);
when(bizManagerService.getBizRegistration()).thenReturn(map);
// Setup new biz with same name and version
BizArchive bizArchive = mock(BizArchive.class);
Manifest manifest = new Manifest();
Attributes mainAttributes = manifest.getMainAttributes();
mainAttributes.putValue(ARK_BIZ_NAME, "biz1");
mainAttributes.putValue(ARK_BIZ_VERSION, "0.0.1");
when(bizArchive.getManifest()).thenReturn(manifest);
when(executableArchive.getBizArchives()).thenReturn(asList(bizArchive));
Biz newBiz = mock(Biz.class);
when(bizFactoryService.createBiz(bizArchive)).thenReturn(newBiz);
handleArchiveStage.processStaticBizFromClasspath(pipelineContext);
// Verify biz was created but not registered due to existing registration
verify(bizFactoryService, times(1)).createBiz(bizArchive);
verify(bizManagerService, times(1)).registerBizIfAbsent(newBiz);
verify(bizManagerService, never()).registerBiz(any());
} finally {
arkClientMockedStatic.close();
}
}

Comment on lines +158 to +176
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Test implementation needs improvement

Several issues need to be addressed:

  1. The verification registerBizIfAbsent(null) on line 173 appears incorrect as we're creating a biz archive and factory but not verifying the actual biz object.
  2. The test doesn't verify the deduplication behavior which is the main objective of this PR.
  3. Missing verification of manifest attributes usage.

Consider refactoring the test like this:

 @Test
 public void testProcessStaticBizFromClasspath() throws Exception {
     MockedStatic<ArkClient> arkClientMockedStatic = mockStatic(ArkClient.class);
     arkClientMockedStatic.when(ArkClient::getBizManagerService).thenReturn(bizManagerService);
     try {
         BizArchive bizArchive = mock(BizArchive.class);
         Manifest manifest = new Manifest();
         Attributes mainAttributes = manifest.getMainAttributes();
         mainAttributes.putValue(ARK_BIZ_NAME, "biz1");
         mainAttributes.putValue(ARK_BIZ_VERSION, "0.0.1");
         when(bizArchive.getManifest()).thenReturn(manifest);
         ConcurrentHashMap<String, ConcurrentHashMap<String, Biz>> map = new ConcurrentHashMap<>();
         when(bizManagerService.getBizRegistration()).thenReturn(map);
         when(executableArchive.getBizArchives()).thenReturn(asList(bizArchive));
+        // Create and configure mock Biz
+        Biz mockBiz = mock(Biz.class);
+        when(mockBiz.getBizName()).thenReturn("biz1");
+        when(mockBiz.getBizVersion()).thenReturn("0.0.1");
+        when(bizFactoryService.createBiz(bizArchive)).thenReturn(mockBiz);
 
         handleArchiveStage.processStaticBizFromClasspath(pipelineContext);
-        verify(bizFactoryService, times(1)).createBiz((bizArchive));
-        verify(bizManagerService, times(1)).registerBizIfAbsent(null);
+        verify(bizFactoryService, times(1)).createBiz(bizArchive);
+        verify(bizManagerService, times(1)).registerBizIfAbsent(mockBiz);
+        
+        // Test deduplication
+        handleArchiveStage.processStaticBizFromClasspath(pipelineContext);
+        // Should still be called only once total
+        verify(bizManagerService, times(1)).registerBizIfAbsent(mockBiz);
     }finally {
         arkClientMockedStatic.close();
     }
 }

This refactored version:

  1. Properly creates and verifies a mock Biz object
  2. Tests the deduplication behavior by calling the method twice
  3. Verifies that registration happens only once
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
MockedStatic<ArkClient> arkClientMockedStatic = mockStatic(ArkClient.class);
arkClientMockedStatic.when(ArkClient::getBizManagerService).thenReturn(bizManagerService);
try {
BizArchive bizArchive = mock(BizArchive.class);
Manifest manifest = new Manifest();
Attributes mainAttributes = manifest.getMainAttributes();
mainAttributes.putValue(ARK_BIZ_NAME, "biz1");
mainAttributes.putValue(ARK_BIZ_VERSION, "0.0.1");
when(bizArchive.getManifest()).thenReturn(manifest);
ConcurrentHashMap<String, ConcurrentHashMap<String, Biz>> map = new ConcurrentHashMap<>();
when(bizManagerService.getBizRegistration()).thenReturn(map);
when(executableArchive.getBizArchives()).thenReturn(asList(bizArchive));
handleArchiveStage.processStaticBizFromClasspath(pipelineContext);
verify(bizFactoryService, times(1)).createBiz((bizArchive));
verify(bizManagerService, times(1)).registerBizIfAbsent(null);
}finally {
arkClientMockedStatic.close();
}
MockedStatic<ArkClient> arkClientMockedStatic = mockStatic(ArkClient.class);
arkClientMockedStatic.when(ArkClient::getBizManagerService).thenReturn(bizManagerService);
try {
BizArchive bizArchive = mock(BizArchive.class);
Manifest manifest = new Manifest();
Attributes mainAttributes = manifest.getMainAttributes();
mainAttributes.putValue(ARK_BIZ_NAME, "biz1");
mainAttributes.putValue(ARK_BIZ_VERSION, "0.0.1");
when(bizArchive.getManifest()).thenReturn(manifest);
ConcurrentHashMap<String, ConcurrentHashMap<String, Biz>> map = new ConcurrentHashMap<>();
when(bizManagerService.getBizRegistration()).thenReturn(map);
when(executableArchive.getBizArchives()).thenReturn(asList(bizArchive));
// Create and configure mock Biz
Biz mockBiz = mock(Biz.class);
when(mockBiz.getBizName()).thenReturn("biz1");
when(mockBiz.getBizVersion()).thenReturn("0.0.1");
when(bizFactoryService.createBiz(bizArchive)).thenReturn(mockBiz);
handleArchiveStage.processStaticBizFromClasspath(pipelineContext);
verify(bizFactoryService, times(1)).createBiz(bizArchive);
verify(bizManagerService, times(1)).registerBizIfAbsent(mockBiz);
// Test deduplication
handleArchiveStage.processStaticBizFromClasspath(pipelineContext);
// Should still be called only once total
verify(bizManagerService, times(1)).registerBizIfAbsent(mockBiz);
}finally {
arkClientMockedStatic.close();
}

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,6 @@ public interface BizManagerService {

ConcurrentHashMap<String, ConcurrentHashMap<String, Biz>> getBizRegistration();

boolean registerBizIfAbsent(Biz biz);

}
Loading