Unverified Commit 70342d51 authored by Licho's avatar Licho Committed by GitHub

fix: port pass error (#1859)

* fix: port pass error Signed-off-by: 's avatarLicho <lecho.sun@gmail.com> * Spotless Apply --------- Signed-off-by: 's avatarLicho <lecho.sun@gmail.com> Co-authored-by: 's avatarleechor <leechor@users.noreply.github.com>
parent 9f60a778
......@@ -85,7 +85,13 @@ public class JobConfig {
if (GatewayType.LOCAL.equalsValue(type)
&& Asserts.isNotNull(config)
&& config.containsKey(RestOptions.PORT.key())) {
this.address = address + NetConstant.COLON + config.get(RestOptions.PORT.key());
int colonIndex = address.indexOf(':');
if (colonIndex == -1) {
this.address = address + NetConstant.COLON + config.get(RestOptions.PORT.key());
} else {
this.address =
address.replaceAll("(?<=:)\\d{0,6}$", config.get(RestOptions.PORT.key()));
}
} else {
this.address = address;
}
......
/*
*
* 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.dinky.job;
import static org.junit.jupiter.api.Assertions.*;
import org.dinky.gateway.GatewayType;
import org.apache.flink.configuration.RestOptions;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
class JobConfigTest {
@Test
void setAddress() {
JobConfig jobConfig = new JobConfig();
jobConfig.setAddress("127.0.0.1:8888");
jobConfig.setType(GatewayType.LOCAL.getValue());
Map<String, String> config = new HashMap<>();
config.put(RestOptions.PORT.key(), "9999");
jobConfig.setConfig(config);
jobConfig.setAddress("127.0.0.1:7777");
assertEquals("127.0.0.1:9999", jobConfig.getAddress());
jobConfig.setAddress("127.0.0.2");
assertEquals("127.0.0.2:9999", jobConfig.getAddress());
config.remove(RestOptions.PORT.key());
jobConfig.setAddress("127.0.0.2:6666");
assertEquals("127.0.0.2:6666", jobConfig.getAddress());
jobConfig.setType(GatewayType.STANDALONE.getLongValue());
jobConfig.setAddress("127.0.0.3:6666");
assertEquals("127.0.0.3:6666", jobConfig.getAddress());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment