提交 a03e6cb2 编写于 作者: wu-sheng's avatar wu-sheng

Add test cases for core module.

上级 4e524de1
/*
* 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;
import org.skywalking.apm.collector.core.data.AbstractHashMessage;
/**
* @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());
}
}
/*
* 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<ServiceInterface> definitionLoader = new DefinitionLoader<>(ServiceInterface.class, define);
Iterator<ServiceInterface> iterator = definitionLoader.iterator();
if (iterator.hasNext()) {
ServiceInterface service = iterator.next();
Assert.assertTrue(service instanceof ServiceInterface);
Assert.assertTrue(service instanceof ServiceImpl);
}
}
}
/*
* 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 {
}
/*
* 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 {
}
/*
* 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";
}
}
/*
* 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)));
}
}
/*
* 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<String> list = new LinkedList<>();
Assert.assertTrue(CollectionUtils.isEmpty(list));
Assert.assertFalse(CollectionUtils.isNotEmpty(list));
}
@Test
public void testMap() {
Map<String, String> 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));
}
}
/*
* 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"));
}
}
/*
* 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));
}
}
/*
* 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();
}
}
}
/*
* 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"));
}
}
/*
* 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 TimeBucketUtilsTest {
@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));
}
}
org.skywalking.apm.collector.core.define.ServiceImpl
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册