Skip to content

Commit

Permalink
Merge pull request #99 from rgdoliveira/sync_main
Browse files Browse the repository at this point in the history
Sync main branch with Apache main branch
  • Loading branch information
rgdoliveira authored Feb 20, 2025
2 parents 5c02957 + 472be9a commit 2fadf03
Show file tree
Hide file tree
Showing 18 changed files with 539 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public PropagationContext adaptModificationMaskForObjectType(ObjectType type, Re
Class<?> classType = classObjectType.getClassType();
String pkgName = classType.getPackage().getName();

if (classType == modifiedClass || "java.lang".equals(pkgName) || !(classType.isInterface() || modifiedClass.isInterface())) {
if (classType == modifiedClass || "java.lang".equals(pkgName)) {
if (typeBit) {
modificationMask = modificationMask.set(PropertySpecificUtil.TRAITABLE_BIT);
}
Expand Down
7 changes: 0 additions & 7 deletions drools-docs/supplemental-ui/partials/footer-scripts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,3 @@
{{#if env.SITE_SEARCH_PROVIDER}}
{{> search-scripts}}
{{/if}}

<!-- Adobe Analytics for Red Hat - DPAL (DTM Property Auto-Loader) - part 2/2 -->
<script type="text/javascript">
if (("undefined" !== typeof _satellite) && ("function" === typeof _satellite.pageBottom)) {
_satellite.pageBottom();
}
</script>
14 changes: 0 additions & 14 deletions drools-docs/supplemental-ui/partials/head-scripts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,4 @@
<!--specific language governing permissions and limitations-->
<!--under the License.-->

<!-- Adobe Analytics for Red Hat - DPAL (DTM Property Auto-Loader) - part 1/2 -->
<script id="dpal" src="https://www.redhat.com/dtm.js" type="text/javascript"></script>
<!-- Google Analytics for kie team: Global site tag (gtag.js) -->
{{#with site.keys.googleAnalytics}}
<script async src="https://www.googletagmanager.com/gtag/js?id={{this}}"></script>
<script>
window.dataLayer=window.dataLayer || [];
function gtag() {
dataLayer.push(arguments)
};
gtag('js',new Date());
gtag('config','{{this}}')
</script>
{{/with}}
<script>var uiRootPath = '{{{uiRootPath}}}'</script>
7 changes: 3 additions & 4 deletions drools-docs/supplemental-ui/partials/header-content.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
<nav class="navbar">
<div class="navbar-brand">
<div class="navbar-item">
<a href="https://www.drools.org">
<a href="https://kie.apache.org/">
<img src="{{{uiRootPath}}}/img/droolsExpertLogo.png" alt="Drools logo"/>
</a>
<a class="navbar-item" href="https://www.drools.org/learn/documentation.html">
<a class="navbar-item" href="https://kie.apache.org/">
{{site.title}}
</a>
</div>
Expand All @@ -41,9 +41,8 @@
</div>
<div id="topbar-nav" class="navbar-menu">
<div class="navbar-end">
<a class="navbar-item" href="https://docs.drools.org">Archive</a>
<div class="navbar-item">
<a class="navbar-item small-item" href="https://github.com/kiegroup/drools" title="Follow Drools on GitHub"><div class="github-icon"></div></a>
<a class="navbar-item small-item" href="https://github.com/apache/incubator-kie-drools" title="Follow Drools on GitHub"><div class="github-icon"></div></a>
<a class="navbar-item small-item" href="https://twitter.com/KieCommunity" target="_blank" title="Follow KIE Community on Twitter for more Drools tweets"><img alt="T" src="{{{uiRootPath}}}/img/twitterLogo.png"></a>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ private void jitAritmeticOperation(Class<?> operationType, AritmeticOperator ope
mv.visitInsn(DREM);
break;
}
} else if (operationType == BigDecimal.class || operationType == BigInteger.class) {
} else if (operationType == BigInteger.class) {
try {
switch (operator) {
case ADD:
Expand All @@ -891,6 +891,28 @@ private void jitAritmeticOperation(Class<?> operationType, AritmeticOperator ope
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
} else if (operationType == BigDecimal.class) {
try {
switch (operator) {
case ADD:
invokeBigDecimalArithmeticOperation("add");
break;
case SUB:
invokeBigDecimalArithmeticOperation("subtract");
break;
case MUL:
invokeBigDecimalArithmeticOperation("multiply");
break;
case DIV:
invokeBigDecimalArithmeticOperation("divide");
break;
case MOD:
invoke(operationType.getMethod("remainder", operationType));
break;
}
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
} else {
throw new RuntimeException("Unknown operation type" + operationType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -774,6 +776,11 @@ protected final void invoke(int opCode, Class<?> clazz, String methodName, Class
mv.visitMethodInsn(opCode, internalName(clazz), methodName, methodDescr(returnedType, paramsType));
}

protected final void invokeBigDecimalArithmeticOperation(String operation) throws NoSuchMethodException {
mv.visitFieldInsn(GETSTATIC, "java/math/MathContext", "DECIMAL128", "Ljava/math/MathContext;");
invoke(BigDecimal.class.getMethod(operation, BigDecimal.class, MathContext.class));
}

protected final void putStaticField(String name, Class<?> type) {
mv.visitFieldInsn(PUTSTATIC, classDescriptor(), name, classGenerator.descriptorOf(type));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ public void setEmbeddedCacheManager(DefaultCacheManager embeddedCacheManager) {

}

public DefaultCacheManager getEmbeddedCacheManager() {
return embeddedCacheManager;
}

public Configuration getCacheConfiguration() {
return cacheConfiguration;
}

// test purpose to remove GlobalState and FileStore
private static void cleanUpGlobalStateAndFileStore() {
FileUtils.deleteDirectory(Paths.get(GLOBAL_STATE_DIR));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

import org.drools.reliability.core.StorageManagerFactory;
import org.drools.reliability.core.TestableStorageManager;
import org.drools.reliability.infinispan.InfinispanStorageManager;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.drools.reliability.infinispan.EmbeddedStorageManager;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.manager.DefaultCacheManager;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -36,9 +36,6 @@
import static org.drools.reliability.test.util.TestConfigurationUtils.DROOLS_RELIABILITY_MODULE_TEST;
import static org.drools.util.Config.getConfig;

/**
* This class is a unit test for EmbeddedCacheManager methods with a fake cacheManager instead of Infinispan DefaultCacheManager.
*/
@EnabledIf("isEmbeddedInfinispan")
@ExtendWith(BeforeAllMethodExtension.class)
class EmbeddedStorageManagerTest {
Expand All @@ -47,9 +44,19 @@ class EmbeddedStorageManagerTest {
System.setProperty(INFINISPAN_STORAGE_ALLOWED_PACKAGES, "org.test.domain");
}

@BeforeEach
public void setUp() {
// Cache will be [METADATA_0, ___protobuf_metadata, ___script_cache, session_0_epDefault, session_1_epDefault]
DefaultCacheManager cacheManager = ((EmbeddedStorageManager) StorageManagerFactory.get().getStorageManager()).getEmbeddedCacheManager();
Configuration cacheConfiguration = ((EmbeddedStorageManager) StorageManagerFactory.get().getStorageManager()).getCacheConfiguration();
cacheManager.createCache(SESSION_STORAGE_PREFIX + "0_" + "epDefault", cacheConfiguration);
cacheManager.createCache(SESSION_STORAGE_PREFIX + "1_" + "epDefault", cacheConfiguration);
cacheManager.createCache("METADATA_0", cacheConfiguration);
}

@AfterEach
public void tearDown() {
((TestableStorageManager) StorageManagerFactory.get().getStorageManager()).restart(); // make sure that FakeCacheManager is removed
((TestableStorageManager) StorageManagerFactory.get().getStorageManager()).restart();
}

static boolean isEmbeddedInfinispan() {
Expand All @@ -59,31 +66,17 @@ static boolean isEmbeddedInfinispan() {

@Test
void removeAllSessionCaches_shouldLeaveNonSessionCache() {
((InfinispanStorageManager) StorageManagerFactory.get().getStorageManager()).setEmbeddedCacheManager(new FakeCacheManager());

StorageManagerFactory.get().getStorageManager().removeAllSessionStorages();

assertThat(StorageManagerFactory.get().getStorageManager().getStorageNames()).contains("METADATA_0");
assertThat(StorageManagerFactory.get().getStorageManager().getStorageNames())
.containsExactlyInAnyOrder("METADATA_0", "___protobuf_metadata", "___script_cache");
}

@Test
void removeCachesBySessionId_shouldRemoveSpecifiedCacheOnly() {
((InfinispanStorageManager) StorageManagerFactory.get().getStorageManager()).setEmbeddedCacheManager(new FakeCacheManager());

StorageManagerFactory.get().getStorageManager().removeStoragesBySessionId("1");

assertThat(StorageManagerFactory.get().getStorageManager().getStorageNames()).contains(SESSION_STORAGE_PREFIX + "0_" + "epDefault", "METADATA_0");
}

public static class FakeCacheManager extends DefaultCacheManager {
public FakeCacheManager() {

ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().cacheMode(CacheMode.LOCAL);

this.createCache(SESSION_STORAGE_PREFIX + "0_" + "epDefault", builder.build());
this.createCache(SESSION_STORAGE_PREFIX + "1_" + "epDefault", builder.build());
this.createCache("METADATA_0", builder.build());
}
assertThat(StorageManagerFactory.get().getStorageManager().getStorageNames())
.containsExactlyInAnyOrder(SESSION_STORAGE_PREFIX + "0_" + "epDefault", "METADATA_0", "___protobuf_metadata", "___script_cache");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class ConstantsHolder {
public static final String SCENARIO_SIMULATION_MODEL_NODE = "ScenarioSimulationModel";
public static final String SETTINGS_NODE = "settings";
public static final String FACT_MAPPING_VALUE_TYPE_NODE = "factMappingValueType";
public static final String VERSION_ATTRIBUTE = "version";
public static final String NOT_EXPRESSION = "NOT_EXPRESSION";
public static final String EXECUTED = "EXECUTED";
public static final List<String> SETTINGS = Collections.unmodifiableList(Arrays.asList(DMO_SESSION_NODE, "dmnFilePath", "type", "fileName", "kieSession",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
*/
package org.drools.scenariosimulation.backend.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.security.WildcardTypePermission;
Expand Down Expand Up @@ -48,12 +45,12 @@
import static org.drools.scenariosimulation.api.utils.ConstantsHolder.SETTINGS;
import static org.drools.scenariosimulation.api.utils.ConstantsHolder.SIMULATION_DESCRIPTOR_NODE;
import static org.drools.scenariosimulation.api.utils.ConstantsHolder.SIMULATION_NODE;
import static org.drools.scenariosimulation.api.utils.ConstantsHolder.VERSION_ATTRIBUTE;

public class ScenarioSimulationXMLPersistence {

private static final ScenarioSimulationXMLPersistence INSTANCE = new ScenarioSimulationXMLPersistence();
private static final String CURRENT_VERSION = new ScenarioSimulationModel().getVersion();
private static final Pattern p = Pattern.compile(SCENARIO_SIMULATION_MODEL_NODE + " version=\"([0-9]+\\.[0-9]+)");

private XStream xt;
private MigrationStrategy migrationStrategy = new InMemoryMigrationStrategy();
Expand Down Expand Up @@ -147,7 +144,8 @@ public ScenarioSimulationModel unmarshal(final String rawXml, boolean migrate) t
}

public String migrateIfNecessary(String rawXml) throws Exception {
String fileVersion = extractVersion(rawXml);
Document document = DOMParserUtil.getDocument(rawXml);
String fileVersion = extractVersion(document);
ThrowingConsumer<Document> migrator = getMigrationStrategy().start();
boolean supported;
switch (fileVersion) {
Expand Down Expand Up @@ -179,18 +177,17 @@ public String migrateIfNecessary(String rawXml) throws Exception {
.append(CURRENT_VERSION).toString());
}
migrator = migrator.andThen(getMigrationStrategy().end());
Document document = DOMParserUtil.getDocument(rawXml);
migrator.accept(document);
return DOMParserUtil.getString(document);
}

public String extractVersion(String rawXml) {
Matcher m = p.matcher(rawXml);

if (m.find()) {
return m.group(1);
public String extractVersion(Document document) {
try {
return document.getElementsByTagName(SCENARIO_SIMULATION_MODEL_NODE)
.item(0).getAttributes().getNamedItem(VERSION_ATTRIBUTE).getTextContent();
} catch (Exception e) {
throw new IllegalArgumentException("Impossible to extract version from the file", e);
}
throw new IllegalArgumentException("Impossible to extract version from the file");
}

public MigrationStrategy getMigrationStrategy() {
Expand Down
Loading

0 comments on commit 2fadf03

Please sign in to comment.