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

Make it compatible with Windows #5

Open
wants to merge 3 commits into
base: develop
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
2 changes: 1 addition & 1 deletion .github/workflows/maven.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04]
os: [ubuntu-18.04, windows-2022]
jdk: [8]
steps:
- name: Checkout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ public class PlainAccessControlFlowTest {
public static final String DEFAULT_GLOBAL_WHITE_ADDR = "172.16.123.123";
public static final List<String> DEFAULT_GLOBAL_WHITE_ADDRS_LIST = Arrays.asList(DEFAULT_GLOBAL_WHITE_ADDR);

public static final Path EMPTY_ACL_FOLDER_PLAIN_ACL_YML_PATH = Paths.get("src/test/resources/empty_acl_folder_conf/conf/plain_acl.yml");
private static final Path EMPTY_ACL_FOLDER_PLAIN_ACL_YML_BAK_PATH = Paths.get("src/test/resources/empty_acl_folder_conf/conf/plain_acl.yml.bak");
public static final Path EMPTY_ACL_FOLDER_PLAIN_ACL_YML_PATH = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "empty_acl_folder_conf" + File.separator + "conf" + File.separator + "plain_acl.yml");
private static final Path EMPTY_ACL_FOLDER_PLAIN_ACL_YML_BAK_PATH = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "empty_acl_folder_conf" + File.separator + "conf" + File.separator + "plain_acl.yml.bak");


public static final Path ONLY_ACL_FOLDER_DELETE_YML_PATH = Paths.get("src/test/resources/only_acl_folder_conf/conf/plain_acl.yml");
private static final Path ONLY_ACL_FOLDER_PLAIN_ACL_YML_PATH = Paths.get("src/test/resources/only_acl_folder_conf/conf/acl/plain_acl.yml");
private static final Path ONLY_ACL_FOLDER_PLAIN_ACL_YML_BAK_PATH = Paths.get("src/test/resources/only_acl_folder_conf/conf/acl/plain_acl.yml.bak");
public static final Path ONLY_ACL_FOLDER_DELETE_YML_PATH = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "only_acl_folder_conf" + File.separator + "conf" + File.separator + "plain_acl.yml");
private static final Path ONLY_ACL_FOLDER_PLAIN_ACL_YML_PATH = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "only_acl_folder_conf" + File.separator + "conf" + File.separator + "acl" + File.separator + "plain_acl.yml");
private static final Path ONLY_ACL_FOLDER_PLAIN_ACL_YML_BAK_PATH = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "only_acl_folder_conf" + File.separator + "conf" + File.separator + "acl" + File.separator + "plain_acl.yml.bak");

private static final Path BOTH_ACL_FOLDER_PLAIN_ACL_YML_PATH = Paths.get("src/test/resources/both_acl_file_folder_conf/conf/acl/plain_acl.yml");
private static final Path BOTH_ACL_FOLDER_PLAIN_ACL_YML_BAK_PATH = Paths.get("src/test/resources/both_acl_file_folder_conf/conf/acl/plain_acl.yml.bak");
private static final Path BOTH_CONF_FOLDER_PLAIN_ACL_YML_PATH = Paths.get("src/test/resources/both_acl_file_folder_conf/conf/plain_acl.yml");
private static final Path BOTH_CONF_FOLDER_PLAIN_ACL_YML_BAK_PATH = Paths.get("src/test/resources/both_acl_file_folder_conf/conf/plain_acl.yml.bak");
private static final Path BOTH_ACL_FOLDER_PLAIN_ACL_YML_PATH = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "both_acl_file_folder_conf" + File.separator + "conf" + File.separator + "acl" + File.separator + "plain_acl.yml");
private static final Path BOTH_ACL_FOLDER_PLAIN_ACL_YML_BAK_PATH = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "both_acl_file_folder_conf" + File.separator + "conf" + File.separator + "acl" + File.separator + "plain_acl.yml.bak");
private static final Path BOTH_CONF_FOLDER_PLAIN_ACL_YML_PATH = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "both_acl_file_folder_conf" + File.separator + "conf" + File.separator + "plain_acl.yml");
private static final Path BOTH_CONF_FOLDER_PLAIN_ACL_YML_BAK_PATH = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "both_acl_file_folder_conf" + File.separator + "conf" + File.separator + "plain_acl.yml.bak");

private boolean isCheckCase1 = false;
private boolean isCheckCase2 = false;
Expand Down Expand Up @@ -150,7 +150,7 @@ public void restore() throws IOException {
@Test
public void testEmptyAclFolderCase() throws NoSuchFieldException, IllegalAccessException, InterruptedException {
this.isCheckCase1 = true;
System.setProperty("rocketmq.home.dir", Paths.get("src/test/resources/empty_acl_folder_conf").toString());
System.setProperty("rocketmq.home.dir", Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "empty_acl_folder_conf").toString());
PlainAccessValidator plainAccessValidator = new PlainAccessValidator();

checkDefaultAclFileExists(plainAccessValidator);
Expand All @@ -162,7 +162,7 @@ public void testEmptyAclFolderCase() throws NoSuchFieldException, IllegalAccessE
@Test
public void testOnlyAclFolderCase() throws NoSuchFieldException, IllegalAccessException, InterruptedException {
this.isCheckCase2 = true;
System.setProperty("rocketmq.home.dir", Paths.get("src/test/resources/only_acl_folder_conf").toString());
System.setProperty("rocketmq.home.dir", Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "only_acl_folder_conf").toString());
PlainAccessValidator plainAccessValidator = new PlainAccessValidator();

checkDefaultAclFileExists(plainAccessValidator);
Expand All @@ -174,7 +174,7 @@ public void testOnlyAclFolderCase() throws NoSuchFieldException, IllegalAccessEx
@Test
public void testBothAclFileAndFolderCase() throws NoSuchFieldException, IllegalAccessException, InterruptedException {
this.isCheckCase3 = true;
System.setProperty("rocketmq.home.dir", Paths.get("src/test/resources/both_acl_file_folder_conf").toString());
System.setProperty("rocketmq.home.dir", Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "both_acl_file_folder_conf").toString());
PlainAccessValidator plainAccessValidator = new PlainAccessValidator();

checkDefaultAclFileExists(plainAccessValidator);
Expand All @@ -193,7 +193,7 @@ private void testValidationAfterConfigFileChanged(PlainAccessValidator plainAcce
ymlMap.put(AclConstants.CONFIG_ACCOUNTS, plainAccessConfigList);

// write prepared PlainAccessConfigs to file
final String aclConfigFile = System.getProperty("rocketmq.home.dir") + File.separator + "conf/plain_acl.yml";
final String aclConfigFile = System.getProperty("rocketmq.home.dir") + File.separator + "conf" + File.separator + "plain_acl.yml";
AclUtils.writeDataObject(aclConfigFile, ymlMap);

loadConfigFile(plainAccessValidator, aclConfigFile);
Expand Down Expand Up @@ -259,7 +259,7 @@ private void testValidationAfterConsecutiveUpdates(PlainAccessValidator plainAcc

// load from file
loadConfigFile(plainAccessValidator,
System.getProperty("rocketmq.home.dir") + File.separator + "conf/plain_acl.yml");
System.getProperty("rocketmq.home.dir") + File.separator + "conf" + File.separator + "plain_acl.yml");
SessionCredentials unmatchedCredential = new SessionCredentials("non_exists_sk", "non_exists_sk");
AclClientRPCHook dummyHook = new AclClientRPCHook(unmatchedCredential);
validateSendMessage(RequestCode.SEND_MESSAGE, DEFAULT_TOPIC, dummyHook, DEFAULT_GLOBAL_WHITE_ADDR, plainAccessValidator);
Expand Down Expand Up @@ -388,7 +388,7 @@ private void checkPlainAccessConfig(final PlainAccessConfig plainAccessConfig, f

private void checkDefaultAclFileExists(PlainAccessValidator plainAccessValidator) {
boolean isExists = Files.exists(Paths.get(System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/plain_acl.yml"));
+ File.separator + "conf" + File.separator + "plain_acl.yml"));
Assert.assertTrue("default acl config file should exist", isExists);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1049,16 +1049,16 @@ public void testValidateAfterUpdateAccessConfig() throws NoSuchFieldException, I

@Test
public void testUpdateSpecifiedAclFileGlobalWhiteAddrsConfig() {
System.setProperty("rocketmq.home.dir", "src/test/resources/update_global_white_addr");
System.setProperty("rocketmq.acl.plain.file", "/conf/plain_acl.yml");
System.setProperty("rocketmq.home.dir", "src" + File.separator + "test" + File.separator + "resources" + File.separator + "update_global_white_addr");
System.setProperty("rocketmq.acl.plain.file", "conf" + File.separator + "plain_acl.yml");

String targetFileName = "src/test/resources/update_global_white_addr/conf/plain_acl.yml";
String targetFileName = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "update_global_white_addr" + File.separator + "conf" + File.separator + "plain_acl.yml";
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(targetFileName, Map.class);

String targetFileName1 = "src/test/resources/update_global_white_addr/conf/acl/plain_acl.yml";
String targetFileName1 = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "update_global_white_addr" + File.separator + "conf" + File.separator + "acl" + File.separator + "plain_acl.yml";
Map<String, Object> backUpAclConfigMap1 = AclUtils.getYamlDataObject(targetFileName1, Map.class);

String targetFileName2 = "src/test/resources/update_global_white_addr/conf/acl/empty.yml";
String targetFileName2 = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "update_global_white_addr" + File.separator + "conf" + File.separator + "acl" + File.separator + "empty.yml";
Map<String, Object> backUpAclConfigMap2 = AclUtils.getYamlDataObject(targetFileName2, Map.class);

PlainAccessValidator plainAccessValidator = new PlainAccessValidator();
Expand Down Expand Up @@ -1090,8 +1090,8 @@ public void testUpdateSpecifiedAclFileGlobalWhiteAddrsConfig() {
AclUtils.writeDataObject(targetFileName1, backUpAclConfigMap1);
AclUtils.writeDataObject(targetFileName2, backUpAclConfigMap2);

System.setProperty("rocketmq.home.dir", "src/test/resources");
System.setProperty("rocketmq.acl.plain.file", "/conf/plain_acl.yml");
System.setProperty("rocketmq.home.dir", "src" + File.separator + "test" + File.separator + "resources");
System.setProperty("rocketmq.acl.plain.file", "conf" + File.separator + "plain_acl.yml");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.concurrent.TimeUnit;

import org.apache.rocketmq.broker.latency.FutureTaskExt;
import org.apache.rocketmq.broker.util.BrokerTestUtils;
import org.apache.rocketmq.common.BrokerConfig;
import org.apache.rocketmq.common.UtilAll;
import org.apache.rocketmq.remoting.netty.NettyClientConfig;
Expand All @@ -48,7 +49,7 @@ public class BrokerControllerTest {
@Before
public void setUp() {
messageStoreConfig = new MessageStoreConfig();
String storePathRootDir = System.getProperty("java.io.tmpdir") + File.separator + "store-"
String storePathRootDir = BrokerTestUtils.getTmpDirectory() + File.separator + "store-"
+ UUID.randomUUID().toString();
messageStoreConfig.setStorePathRootDir(storePathRootDir);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.rocketmq.broker.filter;

import java.util.concurrent.TimeUnit;
import org.apache.rocketmq.broker.util.BrokerTestUtils;
import org.apache.rocketmq.common.BrokerConfig;
import org.apache.rocketmq.common.UtilAll;
import org.apache.rocketmq.common.filter.ExpressionType;
Expand Down Expand Up @@ -61,7 +62,7 @@ public class MessageStoreWithFilterTest {

private static final String topic = "topic";
private static final int queueId = 0;
private static final String storePath = System.getProperty("java.io.tmpdir") + File.separator + "unit_test_store";
private static final String storePath = BrokerTestUtils.getTmpDirectory() + File.separator + "unit_test_store";
private static final int commitLogFileSize = 1024 * 1024 * 256;
private static final int cqFileSize = 300000 * 20;
private static final int cqExtFileSize = 300000 * 128;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.concurrent.TimeUnit;
import org.apache.rocketmq.broker.BrokerController;
import org.apache.rocketmq.broker.failover.EscapeBridge;
import org.apache.rocketmq.broker.util.BrokerTestUtils;
import org.apache.rocketmq.broker.util.HookUtils;
import org.apache.rocketmq.common.BrokerConfig;
import org.apache.rocketmq.common.UtilAll;
Expand Down Expand Up @@ -73,7 +74,7 @@ public class ScheduleMessageServiceTest {
*/
int delayLevel = 3;

private static final String storePath = System.getProperty("java.io.tmpdir") + File.separator + "schedule_test#" + UUID.randomUUID();
private static final String storePath = BrokerTestUtils.getTmpDirectory() + File.separator + "schedule_test#" + UUID.randomUUID();
private static final int commitLogFileSize = 1024;
private static final int cqFileSize = 10;
private static final int cqExtFileSize = 10 * (ConsumeQueueExt.CqExtUnit.MIN_EXT_UNIT_SIZE + 64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.rocketmq.broker.topic;

import org.apache.rocketmq.broker.BrokerController;
import org.apache.rocketmq.broker.util.BrokerTestUtils;
import org.apache.rocketmq.common.BrokerConfig;
import org.apache.rocketmq.common.statictopic.TopicQueueMappingDetail;
import org.apache.rocketmq.common.statictopic.TopicQueueMappingUtils;
Expand Down Expand Up @@ -53,7 +54,7 @@ public void before() {
when(brokerController.getBrokerConfig()).thenReturn(brokerConfig);

MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
messageStoreConfig.setStorePathRootDir(System.getProperty("java.io.tmpdir"));
messageStoreConfig.setStorePathRootDir(BrokerTestUtils.getTmpDirectory());
messageStoreConfig.setDeleteWhen("01;02;03;04;05;06;07;08;09;10;11;12;13;14;15;16;17;18;19;20;21;22;23;00");
when(brokerController.getMessageStoreConfig()).thenReturn(messageStoreConfig);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.rocketmq.broker.util;

import java.io.File;

public abstract class BrokerTestUtils {

public static String getTmpDirectory() {
String tmpdir = System.getProperty("java.io.tmpdir");
return tmpdir.endsWith(File.separator) ? tmpdir.substring(0, tmpdir.length() - 1) : tmpdir;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.rocketmq.client.ClientConfig;
Expand All @@ -46,6 +45,7 @@
import org.apache.rocketmq.client.impl.consumer.RebalanceImpl;
import org.apache.rocketmq.client.impl.consumer.RebalanceService;
import org.apache.rocketmq.client.impl.factory.MQClientInstance;
import org.apache.rocketmq.client.utils.ClientTestUtils;
import org.apache.rocketmq.common.MixAll;
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
import org.apache.rocketmq.common.message.MessageClientExt;
Expand Down Expand Up @@ -99,7 +99,7 @@ public class DefaultLitePullConsumerTest {

@BeforeClass
public static void setEnv() {
System.setProperty("rocketmq.client.logRoot", System.getProperty("java.io.tmpdir"));
System.setProperty("rocketmq.client.logRoot", ClientTestUtils.getTmpDirectory());
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.apache.rocketmq.client.ClientConfig;
import org.apache.rocketmq.client.impl.factory.MQClientInstance;
import org.apache.rocketmq.client.utils.ClientTestUtils;
import org.apache.rocketmq.common.message.MessageQueue;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -43,7 +44,7 @@ public class LocalFileOffsetStoreTest {

@Before
public void init() {
System.setProperty("rocketmq.client.localOffsetStoreDir", System.getProperty("java.io.tmpdir") + File.separator + ".rocketmq_offsets");
System.setProperty("rocketmq.client.localOffsetStoreDir", ClientTestUtils.getTmpDirectory() + File.separator + ".rocketmq_offsets");
String clientId = new ClientConfig().buildMQClientId() + "#TestNamespace" + System.currentTimeMillis();
when(mQClientFactory.getClientId()).thenReturn(clientId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.rocketmq.client.impl.FindBrokerResult;
import org.apache.rocketmq.client.impl.MQClientAPIImpl;
import org.apache.rocketmq.client.impl.factory.MQClientInstance;
import org.apache.rocketmq.client.utils.ClientTestUtils;
import org.apache.rocketmq.common.MixAll;
import org.apache.rocketmq.common.message.MessageQueue;
import org.apache.rocketmq.common.protocol.ResponseCode;
Expand Down Expand Up @@ -58,7 +59,7 @@ public class RemoteBrokerOffsetStoreTest {

@Before
public void init() {
System.setProperty("rocketmq.client.localOffsetStoreDir", System.getProperty("java.io.tmpdir") + ".rocketmq_offsets");
System.setProperty("rocketmq.client.localOffsetStoreDir", ClientTestUtils.getTmpDirectory() + ".rocketmq_offsets");
String clientId = new ClientConfig().buildMQClientId() + "#TestNamespace" + System.currentTimeMillis();
when(mQClientFactory.getClientId()).thenReturn(clientId);
when(mQClientFactory.findBrokerAddressInSubscribe(brokerName, MixAll.MASTER_ID, false)).thenReturn(new FindBrokerResult("127.0.0.1", false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.client.utils.ClientTestUtils;
import org.apache.rocketmq.common.message.MessageClientExt;
import org.apache.rocketmq.common.message.MessageDecoder;
import org.apache.rocketmq.common.message.MessageExt;
Expand Down Expand Up @@ -107,7 +108,7 @@ public class DefaultMQLitePullConsumerWithTraceTest {

@BeforeClass
public static void setUpEnv() {
System.setProperty("rocketmq.client.logRoot", System.getProperty("java.io.tmpdir"));
System.setProperty("rocketmq.client.logRoot", ClientTestUtils.getTmpDirectory());
}

@Before
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.rocketmq.client.utils;

import java.io.File;

public abstract class ClientTestUtils {

public static String getTmpDirectory() {
String tmpdir = System.getProperty("java.io.tmpdir");
return tmpdir.endsWith(File.separator) ? tmpdir.substring(0, tmpdir.length() - 1) : tmpdir;
}
}
Loading