-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat-hot-load-plugin
- Loading branch information
Showing
30 changed files
with
1,692 additions
and
87 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...esources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# 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. | ||
|
||
org.apache.hertzbeat.alert.config.AlerterAutoConfiguration |
16 changes: 16 additions & 0 deletions
16
...esources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# 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. | ||
|
||
org.apache.hertzbeat.collector.config.CollectorAutoConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
common/src/main/java/org/apache/hertzbeat/common/util/TimeZoneUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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.hertzbeat.common.util; | ||
|
||
import java.util.Locale; | ||
import java.util.TimeZone; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.hertzbeat.common.constants.CommonConstants; | ||
|
||
/** | ||
* timezone util | ||
*/ | ||
public class TimeZoneUtil { | ||
private static final Integer LANG_REGION_LENGTH = 2; | ||
|
||
public static void setTimeZoneAndLocale(String timeZoneId, String locale) { | ||
setTimeZone(timeZoneId); | ||
setLocale(locale); | ||
} | ||
|
||
public static void setTimeZone(String timeZoneId) { | ||
if (StringUtils.isBlank(timeZoneId)) { | ||
return; | ||
} | ||
|
||
TimeZone.setDefault(TimeZone.getTimeZone(timeZoneId)); | ||
} | ||
|
||
public static void setLocale(String locale) { | ||
if (StringUtils.isBlank(locale)) { | ||
return; | ||
} | ||
|
||
String[] arr = locale.split(CommonConstants.LOCALE_SEPARATOR); | ||
if (arr.length == LANG_REGION_LENGTH) { | ||
String language = arr[0]; | ||
String country = arr[1]; | ||
Locale.setDefault(new Locale(language, country)); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...esources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# 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. | ||
|
||
org.apache.hertzbeat.common.config.CommonConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
common/src/test/java/org/apache/hertzbeat/common/util/MapCapUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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.hertzbeat.common.util; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* Test for {@link MapCapUtil} | ||
*/ | ||
class MapCapUtilTest { | ||
|
||
@Test | ||
public void testCalInitMap() { | ||
int size = 0; | ||
int expectedCapacity = (int) Math.ceil(size / 0.75); | ||
int actualCapacity = MapCapUtil.calInitMap(size); | ||
|
||
assertEquals(expectedCapacity, actualCapacity); | ||
|
||
size = 10; | ||
expectedCapacity = (int) Math.ceil(size / 0.75); | ||
actualCapacity = MapCapUtil.calInitMap(size); | ||
|
||
assertEquals(expectedCapacity, actualCapacity); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,23 +17,59 @@ | |
|
||
package org.apache.hertzbeat.common.util; | ||
|
||
import org.apache.hertzbeat.common.util.entity.PersonTest.Person; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.google.protobuf.InvalidProtocolBufferException; | ||
import com.google.protobuf.util.JsonFormat; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
/** | ||
* Test case for {@link ProtoJsonUtil} | ||
*/ | ||
class ProtoJsonUtilTest { | ||
|
||
private Person samplePerson; | ||
private String sampleJson; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
|
||
samplePerson = Person.newBuilder() | ||
.setName("John Doe") | ||
.setId(123) | ||
.setEmail("[email protected]") | ||
.build(); | ||
|
||
sampleJson = "{ \"name\": \"John Doe\", \"id\": 123, \"email\": \"[email protected]\" }"; | ||
} | ||
|
||
@Test | ||
void toJsonStr() { | ||
void toJsonStr() throws InvalidProtocolBufferException { | ||
|
||
String json = ProtoJsonUtil.toJsonStr(samplePerson); | ||
String expectedJson = JsonFormat.printer().print(samplePerson); | ||
assertEquals(expectedJson, json); | ||
|
||
json = ProtoJsonUtil.toJsonStr(null); | ||
assertNull(json); | ||
} | ||
|
||
@Test | ||
void toProtobuf() { | ||
|
||
Person.Builder builder = Person.newBuilder(); | ||
Person person = (Person) ProtoJsonUtil.toProtobuf(sampleJson, builder); | ||
assertEquals(samplePerson, person); | ||
|
||
String invalidJson = "{ \"name\": \"John Doe\", \"id\": \"not-a-number\" }"; | ||
builder = Person.newBuilder(); | ||
person = (Person) ProtoJsonUtil.toProtobuf(invalidJson, builder); | ||
|
||
assertNull(person); | ||
} | ||
|
||
} |
Oops, something went wrong.