Skip to content

Commit

Permalink
[Bugfix] engine version support hyphen (#4246)
Browse files Browse the repository at this point in the history
* EngineTypeLabel support "-"
  • Loading branch information
GuoPhilipse committed Feb 21, 2023
1 parent b5d4ec4 commit 436f90d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,19 @@ public void setVersion(String version) {
public Boolean isEmpty() {
return StringUtils.isBlank(getEngineType()) || StringUtils.isBlank(getVersion());
}

@Override
protected void setStringValue(String stringValue) {
String version;
String engineType = stringValue.split("-")[0];

if (engineType.equals("*")) {
version = stringValue.replaceFirst("[" + engineType + "]-", "");
} else {
version = stringValue.replaceFirst(engineType + "-", "");
}

setEngineType(engineType);
setVersion(version);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.linkis.manager.label.entity.engine;

import org.apache.linkis.manager.label.builder.factory.LabelBuilderFactory;
import org.apache.linkis.manager.label.builder.factory.LabelBuilderFactoryContext;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/** EngineTypeLabel Tester */
public class EngineTypeLabelTest {

@Test
public void testSetStringValue() {
String engineType = "hive";
String version = "1.1.0-cdh5.12.0";

String engineType1 = "*";
String version1 = "*";

LabelBuilderFactory labelBuilderFactory = LabelBuilderFactoryContext.getLabelBuilderFactory();
EngineTypeLabel engineTypeLabel = labelBuilderFactory.createLabel(EngineTypeLabel.class);
engineTypeLabel.setStringValue(engineType + "-" + version);
Assertions.assertEquals(engineTypeLabel.getEngineType(), engineType);
Assertions.assertEquals(engineTypeLabel.getVersion(), version);

engineTypeLabel.setStringValue(engineType1 + "-" + version1);
Assertions.assertEquals(engineTypeLabel.getEngineType(), engineType1);
Assertions.assertEquals(engineTypeLabel.getVersion(), version1);
}
}

0 comments on commit 436f90d

Please sign in to comment.