Skip to content

Commit

Permalink
fix: change ehCache storage location (#3184)
Browse files Browse the repository at this point in the history
* fix cache storage location and adding condition on cache controller creation

Signed-off-by: at670475 <[email protected]>

* change condition on cacheconfig

Signed-off-by: at670475 <[email protected]>

* fix license check

Signed-off-by: at670475 <[email protected]>

* make bean matchable by default

Signed-off-by: at670475 <[email protected]>

* fix code smell

Signed-off-by: at670475 <[email protected]>

* remove config

Signed-off-by: at670475 <[email protected]>

* add test

Signed-off-by: at670475 <[email protected]>

* add test

Signed-off-by: at670475 <[email protected]>

* fix test name

Signed-off-by: at670475 <[email protected]>

---------

Signed-off-by: at670475 <[email protected]>
  • Loading branch information
taban03 authored Nov 8, 2023
1 parent c6cc561 commit adfadff
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gateway-package/src/main/resources/bin/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ _BPX_JOBNAME=${ZWE_zowe_job_prefix}${GATEWAY_CODE} java \
-Dapiml.service.externalUrl="${httpProtocol}://${ZWE_zowe_externalDomains_0}:${ZWE_zowe_externalPort}" \
-Dapiml.service.apimlId=${ZWE_configs_apimlId:-} \
-Dapiml.catalog.serviceId=${APIML_GATEWAY_CATALOG_ID:-apicatalog} \
-Dapiml.cache.storage.location=${ZWE_zowe_workspaceDirectory}/api-mediation/${ZWE_PARAMETER_HA_INSTANCE:-localhost} \
-Dapiml.cache.storage.location=${ZWE_zowe_workspaceDirectory}/api-mediation/${ZWE_haInstance_id:-localhost} \
-Dapiml.logs.location=${ZWE_zowe_logDirectory} \
-Dapiml.gateway.timeoutMillis=${ZWE_configs_apiml_gateway_timeoutMillis:-600000} \
-Dapiml.security.ssl.verifySslCertificatesOfServices=${verifySslCertificatesOfServices:-false} \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

package org.zowe.apiml.gateway.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.KeyGenerator;
Expand All @@ -30,6 +31,7 @@
*/
@EnableCaching
@Configuration
@ConditionalOnProperty(value = "apiml.caching.enabled", havingValue = "true", matchIfMissing = true)
public class CacheConfig {

public static final String COMPOSITE_KEY_GENERATOR = "compositeKeyGenerator";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.apiml.gateway.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.support.NoOpCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.zowe.apiml.util.CacheUtils;

/**
* Spring configuration to disable EhCache usage.
*/
@EnableCaching
@Configuration
@ConditionalOnProperty(value = "apiml.caching.enabled", havingValue = "false")
public class NoOpCacheConfig {
@Bean
public CacheManager cacheManager() {
return new NoOpCacheManager();
}

@Bean
public CacheUtils cacheUtils() {
return new CacheUtils();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.apiml.gateway.config;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cache.CacheManager;
import org.springframework.cache.jcache.JCacheCacheManager;
import org.springframework.test.context.ActiveProfiles;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = CacheConfig.class)
@ActiveProfiles("test")
class CacheConfigTest {

@Autowired
private CacheManager cacheManager;

@Test
void testCacheManagerIsRealImplementation() {
assertNotNull(cacheManager);
assertTrue(cacheManager instanceof JCacheCacheManager);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.apiml.gateway.config;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cache.CacheManager;
import org.springframework.cache.support.NoOpCacheManager;
import org.springframework.test.context.ActiveProfiles;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = NoOpCacheConfig.class, properties = "apiml.caching.enabled=false")
@ActiveProfiles("test")
class NoOpCacheConfigTest {
@Autowired
private CacheManager cacheManager;

@Test
void testDisabledCacheManager() {
assertNotNull(cacheManager);
assertTrue(cacheManager instanceof NoOpCacheManager);
}
}

0 comments on commit adfadff

Please sign in to comment.