diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/data/AbstractHashMessageTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/data/AbstractHashMessageTest.java new file mode 100644 index 000000000..41e645d76 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/data/AbstractHashMessageTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.core.data; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class AbstractHashMessageTest { + public class NewMessage extends AbstractHashMessage { + public NewMessage() { + super("key"); + } + } + + @Test + public void testHash() { + NewMessage message = new NewMessage(); + Assert.assertEquals("key".hashCode(), message.getHashCode()); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/DefinitionLoaderTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/DefinitionLoaderTest.java new file mode 100644 index 000000000..a3c44cc0a --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/DefinitionLoaderTest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.core.define; + +import java.util.Iterator; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class DefinitionLoaderTest { + @Test + public void testLoad() { + TestDefineFile define = new TestDefineFile(); + DefinitionLoader definitionLoader = new DefinitionLoader<>(ServiceInterface.class, define); + Iterator iterator = definitionLoader.iterator(); + if (iterator.hasNext()) { + ServiceInterface service = iterator.next(); + Assert.assertTrue(service instanceof ServiceInterface); + Assert.assertTrue(service instanceof ServiceImpl); + } + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/ServiceImpl.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/ServiceImpl.java new file mode 100644 index 000000000..8978b3cc7 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/ServiceImpl.java @@ -0,0 +1,25 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.core.define; + +/** + * @author wu-sheng + */ +public class ServiceImpl implements ServiceInterface { +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/ServiceInterface.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/ServiceInterface.java new file mode 100644 index 000000000..d47d4dbe0 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/ServiceInterface.java @@ -0,0 +1,25 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.core.define; + +/** + * @author wu-sheng + */ +public interface ServiceInterface { +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/TestDefineFile.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/TestDefineFile.java new file mode 100644 index 000000000..5206e8052 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/define/TestDefineFile.java @@ -0,0 +1,28 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.core.define; + +/** + * @author wu-sheng + */ +public class TestDefineFile extends DefinitionFile { + @Override protected String fileName() { + return "test_define.define"; + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/BytesUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/BytesUtilsTest.java new file mode 100644 index 000000000..9e0e11476 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/BytesUtilsTest.java @@ -0,0 +1,32 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.core.util; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class BytesUtilsTest { + @Test + public void testLong2Bytes() { + Assert.assertEquals(655390L, BytesUtils.bytes2Long(BytesUtils.long2Bytes(655390L))); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/CollectionUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/CollectionUtilsTest.java new file mode 100644 index 000000000..9b10c4eee --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/CollectionUtilsTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.core.util; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class CollectionUtilsTest { + @Test + public void testList() { + List list = new LinkedList<>(); + Assert.assertTrue(CollectionUtils.isEmpty(list)); + Assert.assertFalse(CollectionUtils.isNotEmpty(list)); + } + + @Test + public void testMap() { + Map map = new HashMap<>(); + Assert.assertTrue(CollectionUtils.isEmpty(map)); + Assert.assertFalse(CollectionUtils.isNotEmpty(map)); + } + + @Test + public void testArray() { + String[] array = new String[] {"abc"}; + Assert.assertTrue(CollectionUtils.isNotEmpty(array)); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ColumnNameUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ColumnNameUtilsTest.java new file mode 100644 index 000000000..263724d0e --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ColumnNameUtilsTest.java @@ -0,0 +1,33 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.core.util; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class ColumnNameUtilsTest { + @Test + public void testRename() { + Assert.assertEquals("newAttributeNameFromColumnName", + ColumnNameUtils.INSTANCE.rename("new_attribute_name_from_column_name")); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ObjectUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ObjectUtilsTest.java new file mode 100644 index 000000000..374e586db --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ObjectUtilsTest.java @@ -0,0 +1,33 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.core.util; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class ObjectUtilsTest { + @Test + public void testNullObject() { + Object o = new Object(); + Assert.assertTrue(ObjectUtils.isNotEmpty(o)); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ResourceUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ResourceUtilsTest.java new file mode 100644 index 000000000..643542da8 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/ResourceUtilsTest.java @@ -0,0 +1,42 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.core.util; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Reader; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class ResourceUtilsTest { + @Test + public void testGetResource() throws IOException { + Reader read = ResourceUtils.read("TestResourceFile.txt"); + try { + BufferedReader reader = new BufferedReader(read); + String line1 = reader.readLine(); + Assert.assertEquals("skywalking", line1); + } finally { + read.close(); + } + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/StringUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/StringUtilsTest.java new file mode 100644 index 000000000..31130a81b --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/StringUtilsTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.core.util; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class StringUtilsTest { + @Test + public void testEmptyString() { + Assert.assertTrue(StringUtils.isEmpty(null)); + Assert.assertTrue(StringUtils.isEmpty("")); + + Assert.assertTrue(StringUtils.isNotEmpty("abc")); + } +} diff --git a/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/TimeBucketUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/TimeBucketUtilsTest.java new file mode 100644 index 000000000..ffaf530ce --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/java/org/skywalking/apm/collector/core/util/TimeBucketUtilsTest.java @@ -0,0 +1,56 @@ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * Licensed 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.skywalking.apm.collector.core.util; + +import java.util.TimeZone; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @author wu-sheng + */ +public class TimeBucketUtilsTest { + @Before + public void setup() { + TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai")); + } + + @After + public void teardown() { + + } + + @Test + public void testGetInfoFromATimestamp() { + long timeMillis = 1509521745220L; + Assert.assertArrayEquals(new long[] { + 20171101153545L, + 20171101153544L, + 20171101153543L, + 20171101153542L, + 20171101153541L + }, TimeBucketUtils.INSTANCE.getFiveSecondTimeBuckets(TimeBucketUtils.INSTANCE.getSecondTimeBucket(timeMillis))); + Assert.assertEquals(20171101153545L, TimeBucketUtils.INSTANCE.getSecondTimeBucket(timeMillis)); + Assert.assertEquals(201711011535L, TimeBucketUtils.INSTANCE.getMinuteTimeBucket(timeMillis)); + Assert.assertEquals(201711011500L, TimeBucketUtils.INSTANCE.getHourTimeBucket(timeMillis)); + Assert.assertEquals(201711010000L, TimeBucketUtils.INSTANCE.getDayTimeBucket(timeMillis)); + } +} diff --git a/apm-collector/apm-collector-core/src/test/resources/META-INF/defines/test_define.define b/apm-collector/apm-collector-core/src/test/resources/META-INF/defines/test_define.define new file mode 100644 index 000000000..d44e660dd --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/resources/META-INF/defines/test_define.define @@ -0,0 +1 @@ +org.skywalking.apm.collector.core.define.ServiceImpl \ No newline at end of file diff --git a/apm-collector/apm-collector-core/src/test/resources/TestResourceFile.txt b/apm-collector/apm-collector-core/src/test/resources/TestResourceFile.txt new file mode 100644 index 000000000..d967dd633 --- /dev/null +++ b/apm-collector/apm-collector-core/src/test/resources/TestResourceFile.txt @@ -0,0 +1 @@ +skywalking \ No newline at end of file