This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 6a6515dd243 remove useless code (#18053)
6a6515dd243 is described below
commit 6a6515dd243ddd58aa7c348173ce20781d06d812
Author: Haoran Meng <[email protected]>
AuthorDate: Mon May 30 11:21:06 2022 +0800
remove useless code (#18053)
---
.../infra/instance/definition/InstanceId.java | 68 ----------------------
.../infra/instance/definition/InstanceIdTest.java | 57 ------------------
2 files changed, 125 deletions(-)
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceId.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceId.java
deleted file mode 100644
index 2b7731d1fac..00000000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceId.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.shardingsphere.infra.instance.definition;
-
-import com.google.common.base.Splitter;
-import lombok.Getter;
-import org.apache.shardingsphere.infra.instance.utils.IpUtils;
-
-import java.lang.management.ManagementFactory;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * Instance id.
- */
-@Getter
-public final class InstanceId {
-
- private static final String DELIMITER = "@";
-
- private static final AtomicLong ATOMIC_LONG = new AtomicLong();
-
- private final String id;
-
- private final String ip;
-
- private final String uniqueSign;
-
- public InstanceId(final String ip, final String uniqueSign) {
- this.ip = ip;
- this.uniqueSign = uniqueSign;
- id = String.join(DELIMITER, ip, uniqueSign);
- }
-
- public InstanceId(final String instance) {
- if (instance.indexOf(DELIMITER) >= 0) {
- id = instance;
- List<String> ids = Splitter.on("@").splitToList(instance);
- ip = ids.get(0);
- uniqueSign = ids.get(1);
- } else {
- uniqueSign = instance;
- ip = IpUtils.getIp();
- id = String.join(DELIMITER, ip, uniqueSign);
- }
- }
-
- public InstanceId() {
- ip = IpUtils.getIp();
- uniqueSign = String.join("",
ManagementFactory.getRuntimeMXBean().getName().split(DELIMITER)[0],
String.valueOf(ATOMIC_LONG.incrementAndGet()));
- id = String.join(DELIMITER, ip, uniqueSign);
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/definition/InstanceIdTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/definition/InstanceIdTest.java
deleted file mode 100644
index 595d3c11de1..00000000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/definition/InstanceIdTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.shardingsphere.infra.instance.definition;
-
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-
-public final class InstanceIdTest {
-
- @Test
- public void assertInitInstanceIdWithPort() {
- InstanceId actual = new InstanceId("3307");
- assertThat(actual.getUniqueSign(), is("3307"));
- }
-
- @Test
- public void assertInitInstanceIdWithEmptyParameter() {
- InstanceId actual = new InstanceId();
- assertThat(actual.getId().split("@").length, is(2));
- }
-
- @Test
- public void assertInitInstanceIdWithIpAndUniqueSign() {
- InstanceId actual = new InstanceId("127.0.0.1", "3307");
- assertThat(actual.getId(), is("127.0.0.1@3307"));
- }
-
- @Test
- public void assertInitInstanceIdWithExistId() {
- InstanceId actual = new InstanceId("127.0.0.1@3307");
- assertThat(actual.getIp(), is("127.0.0.1"));
- assertThat(actual.getUniqueSign(), is("3307"));
- }
-
- @Test
- public void assertInitMultipleInstanceId() {
- assertFalse(new InstanceId().getId().equals(new InstanceId().getId()));
- }
-}