upgrade module naocs-consistency from junit4 to junit5 (#12118)
This commit is contained in:
parent
dc0e46e9f9
commit
26176ddb3c
@ -21,16 +21,16 @@ import com.alibaba.nacos.consistency.entity.Log;
|
||||
import com.alibaba.nacos.consistency.entity.ReadRequest;
|
||||
import com.alibaba.nacos.consistency.entity.WriteRequest;
|
||||
import com.google.protobuf.ByteString;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class ProtoMessageUtilTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ProtoMessageUtilTest {
|
||||
|
||||
@Test
|
||||
public void testProto() throws Exception {
|
||||
void testProto() throws Exception {
|
||||
WriteRequest request = WriteRequest.newBuilder().setKey("test-proto-new").build();
|
||||
|
||||
byte[] bytes = request.toByteArray();
|
||||
@ -39,7 +39,7 @@ public class ProtoMessageUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseReadRequestWithRequestTypeField() {
|
||||
void testParseReadRequestWithRequestTypeField() {
|
||||
String group = "test";
|
||||
ByteString data = ByteString.copyFrom("data".getBytes());
|
||||
ReadRequest testCase = ReadRequest.newBuilder().setGroup(group).setData(data).build();
|
||||
@ -49,8 +49,8 @@ public class ProtoMessageUtilTest {
|
||||
requestTypeFieldBytes[1] = ProtoMessageUtil.REQUEST_TYPE_READ;
|
||||
|
||||
byte[] dataBytes = testCase.toByteArray();
|
||||
ByteBuffer byteBuffer = (ByteBuffer) ByteBuffer.allocate(requestTypeFieldBytes.length + dataBytes.length)
|
||||
.put(requestTypeFieldBytes).put(dataBytes).position(0);
|
||||
ByteBuffer byteBuffer = (ByteBuffer) ByteBuffer.allocate(requestTypeFieldBytes.length + dataBytes.length).put(requestTypeFieldBytes)
|
||||
.put(dataBytes).position(0);
|
||||
|
||||
Object actual = ProtoMessageUtil.parse(byteBuffer.array());
|
||||
assertEquals(ReadRequest.class, testCase.getClass());
|
||||
@ -59,7 +59,7 @@ public class ProtoMessageUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseWriteRequestWithRequestTypeField() {
|
||||
void testParseWriteRequestWithRequestTypeField() {
|
||||
String group = "test";
|
||||
ByteString data = ByteString.copyFrom("data".getBytes());
|
||||
WriteRequest testCase = WriteRequest.newBuilder().setGroup(group).setData(data).build();
|
||||
@ -69,8 +69,8 @@ public class ProtoMessageUtilTest {
|
||||
requestTypeFieldBytes[1] = ProtoMessageUtil.REQUEST_TYPE_WRITE;
|
||||
|
||||
byte[] dataBytes = testCase.toByteArray();
|
||||
ByteBuffer byteBuffer = (ByteBuffer) ByteBuffer.allocate(requestTypeFieldBytes.length + dataBytes.length)
|
||||
.put(requestTypeFieldBytes).put(dataBytes).position(0);
|
||||
ByteBuffer byteBuffer = (ByteBuffer) ByteBuffer.allocate(requestTypeFieldBytes.length + dataBytes.length).put(requestTypeFieldBytes)
|
||||
.put(dataBytes).position(0);
|
||||
|
||||
Object actual = ProtoMessageUtil.parse(byteBuffer.array());
|
||||
assertEquals(WriteRequest.class, testCase.getClass());
|
||||
@ -79,7 +79,7 @@ public class ProtoMessageUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseReadRequest() {
|
||||
void testParseReadRequest() {
|
||||
String group = "test";
|
||||
ByteString data = ByteString.copyFrom("data".getBytes());
|
||||
ReadRequest testCase = ReadRequest.newBuilder().setGroup(group).setData(data).build();
|
||||
@ -90,7 +90,7 @@ public class ProtoMessageUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseWriteRequest() {
|
||||
void testParseWriteRequest() {
|
||||
String group = "test";
|
||||
ByteString data = ByteString.copyFrom("data".getBytes());
|
||||
WriteRequest testCase = WriteRequest.newBuilder().setGroup(group).setData(data).build();
|
||||
@ -101,7 +101,7 @@ public class ProtoMessageUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertToReadRequest() {
|
||||
void testConvertToReadRequest() {
|
||||
ByteString data = ByteString.copyFrom("data".getBytes());
|
||||
String group = "test";
|
||||
|
||||
@ -116,10 +116,9 @@ public class ProtoMessageUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertToWriteRequest() {
|
||||
void testConvertToWriteRequest() {
|
||||
ByteString data = ByteString.copyFrom("data".getBytes());
|
||||
Log log = Log.newBuilder().setKey("key").setGroup("group").setData(data).setOperation("o")
|
||||
.putExtendInfo("k", "v").build();
|
||||
Log log = Log.newBuilder().setKey("key").setGroup("group").setData(data).setOperation("o").putExtendInfo("k", "v").build();
|
||||
WriteRequest writeRequest = ProtoMessageUtil.convertToWriteRequest(log);
|
||||
|
||||
assertEquals(1, writeRequest.getExtendInfoCount());
|
||||
|
@ -17,8 +17,7 @@
|
||||
package com.alibaba.nacos.consistency;
|
||||
|
||||
import com.alibaba.nacos.common.utils.JacksonUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@ -27,10 +26,12 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class ProtocolMetaDataTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ProtocolMetaDataTest {
|
||||
|
||||
@Test
|
||||
public void testProtocolMetaData() throws Exception {
|
||||
void testProtocolMetaData() throws Exception {
|
||||
Map<String, Map<String, Object>> map = new HashMap<>();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("test-1", new Date());
|
||||
@ -68,7 +69,7 @@ public class ProtocolMetaDataTest {
|
||||
|
||||
latch.await(10_000L, TimeUnit.MILLISECONDS);
|
||||
|
||||
Assert.assertEquals(2, count.get());
|
||||
assertEquals(2, count.get());
|
||||
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,7 @@
|
||||
package com.alibaba.nacos.consistency;
|
||||
|
||||
import com.alibaba.nacos.consistency.serialize.JacksonSerializer;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -27,10 +26,13 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
public class SerializeFactoryTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class SerializeFactoryTest {
|
||||
|
||||
@Test
|
||||
public void testListSerialize() {
|
||||
void testListSerialize() {
|
||||
Serializer serializer = SerializeFactory.getDefault();
|
||||
|
||||
List<Integer> logsList = new ArrayList<>();
|
||||
@ -38,27 +40,27 @@ public class SerializeFactoryTest {
|
||||
logsList.add(i);
|
||||
}
|
||||
byte[] data = serializer.serialize(logsList);
|
||||
Assert.assertNotEquals(0, data.length);
|
||||
assertNotEquals(0, data.length);
|
||||
|
||||
ArrayList<Integer> list = serializer.deserialize(data, ArrayList.class);
|
||||
System.out.println(list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapSerialize() {
|
||||
void testMapSerialize() {
|
||||
Serializer serializer = SerializeFactory.getDefault();
|
||||
Map<Integer, Integer> logsMap = new HashMap<>();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
logsMap.put(i, i);
|
||||
}
|
||||
byte[] data = serializer.serialize(logsMap);
|
||||
Assert.assertNotEquals(0, data.length);
|
||||
assertNotEquals(0, data.length);
|
||||
Map<Integer, Integer> result = serializer.deserialize(data, HashMap.class);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSerialize() {
|
||||
void testSetSerialize() {
|
||||
Serializer serializer = SerializeFactory.getDefault();
|
||||
Set<Integer> logsMap = new CopyOnWriteArraySet<>();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
@ -66,14 +68,14 @@ public class SerializeFactoryTest {
|
||||
}
|
||||
|
||||
byte[] data = serializer.serialize(logsMap);
|
||||
Assert.assertNotEquals(0, data.length);
|
||||
assertNotEquals(0, data.length);
|
||||
Set<Integer> result = serializer.deserialize(data, CopyOnWriteArraySet.class);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSerializer() {
|
||||
void testGetSerializer() {
|
||||
Serializer serializer = SerializeFactory.getSerializer("JSON");
|
||||
Assert.assertTrue(serializer instanceof JacksonSerializer);
|
||||
assertTrue(serializer instanceof JacksonSerializer);
|
||||
}
|
||||
}
|
||||
|
@ -19,66 +19,69 @@ package com.alibaba.nacos.consistency.serialize;
|
||||
|
||||
import com.alibaba.nacos.api.exception.runtime.NacosDeserializationException;
|
||||
import org.apache.http.HttpException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* {@link HessianSerializer} unit test.
|
||||
*
|
||||
* @author Chenhao26
|
||||
* @date 2022-08-13
|
||||
*/
|
||||
public class HessianSerializerTest {
|
||||
class HessianSerializerTest {
|
||||
|
||||
private HessianSerializer hessianSerializer;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
hessianSerializer = new HessianSerializer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializerAndDeserialize() {
|
||||
void testSerializerAndDeserialize() {
|
||||
String data = "xxx";
|
||||
byte[] bytes = hessianSerializer.serialize(data);
|
||||
|
||||
try {
|
||||
hessianSerializer.deserialize(bytes);
|
||||
} catch (Exception e) {
|
||||
Assert.assertTrue(e instanceof RuntimeException);
|
||||
assertTrue(e instanceof RuntimeException);
|
||||
}
|
||||
|
||||
String res1 = hessianSerializer.deserialize(bytes, String.class);
|
||||
Assert.assertEquals(data, res1);
|
||||
assertEquals(data, res1);
|
||||
|
||||
String res2 = hessianSerializer.deserialize(bytes, "java.lang.String");
|
||||
Assert.assertEquals(data, res2);
|
||||
assertEquals(data, res2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializerAndDeserializeForNotAllowClass() {
|
||||
void testSerializerAndDeserializeForNotAllowClass() {
|
||||
Serializable data = new HttpException();
|
||||
byte[] bytes = hessianSerializer.serialize(data);
|
||||
|
||||
try {
|
||||
HttpException res = hessianSerializer.deserialize(bytes);
|
||||
Assert.fail("deserialize success which is not expected");
|
||||
fail("deserialize success which is not expected");
|
||||
} catch (Exception e) {
|
||||
Assert.assertTrue(e instanceof ClassCastException);
|
||||
assertTrue(e instanceof ClassCastException);
|
||||
}
|
||||
|
||||
try {
|
||||
HttpException res1 = hessianSerializer.deserialize(bytes, HttpException.class);
|
||||
} catch (Exception e) {
|
||||
Assert.assertTrue(e instanceof NacosDeserializationException);
|
||||
assertTrue(e instanceof NacosDeserializationException);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testName() {
|
||||
Assert.assertEquals("Hessian", hessianSerializer.name());
|
||||
void testName() {
|
||||
assertEquals("Hessian", hessianSerializer.name());
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,11 @@
|
||||
|
||||
package com.alibaba.nacos.consistency.serialize;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* {@link JacksonSerializer} unit test.
|
||||
@ -27,35 +29,35 @@ import org.junit.Test;
|
||||
* @author chenglu
|
||||
* @date 2021-07-27 18:32
|
||||
*/
|
||||
public class JacksonSerializerTest {
|
||||
class JacksonSerializerTest {
|
||||
|
||||
private JacksonSerializer jacksonSerializer;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
jacksonSerializer = new JacksonSerializer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializerAndDeserialize() {
|
||||
void testSerializerAndDeserialize() {
|
||||
String data = "xxx";
|
||||
byte[] bytes = jacksonSerializer.serialize(data);
|
||||
|
||||
try {
|
||||
jacksonSerializer.deserialize(bytes);
|
||||
} catch (Exception e) {
|
||||
Assert.assertTrue(e instanceof UnsupportedOperationException);
|
||||
assertTrue(e instanceof UnsupportedOperationException);
|
||||
}
|
||||
|
||||
String res1 = jacksonSerializer.deserialize(bytes, String.class);
|
||||
Assert.assertEquals(data, res1);
|
||||
assertEquals(data, res1);
|
||||
|
||||
String res2 = jacksonSerializer.deserialize(bytes, "java.lang.String");
|
||||
Assert.assertEquals(data, res2);
|
||||
assertEquals(data, res2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testName() {
|
||||
Assert.assertEquals("JSON", jacksonSerializer.name());
|
||||
void testName() {
|
||||
assertEquals("JSON", jacksonSerializer.name());
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,10 @@
|
||||
|
||||
package com.alibaba.nacos.consistency.snapshot;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* {@link LocalFileMeta} unit test.
|
||||
@ -27,18 +28,18 @@ import org.junit.Test;
|
||||
* @author chenglu
|
||||
* @date 2021-07-27 18:43
|
||||
*/
|
||||
public class LocalFileMetaTest {
|
||||
class LocalFileMetaTest {
|
||||
|
||||
private LocalFileMeta fileMeta;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
fileMeta = new LocalFileMeta();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppendAndGet() {
|
||||
void testAppendAndGet() {
|
||||
fileMeta.append("key", "value");
|
||||
Assert.assertEquals("value", fileMeta.get("key"));
|
||||
assertEquals("value", fileMeta.get("key"));
|
||||
}
|
||||
}
|
||||
|
@ -17,26 +17,27 @@
|
||||
|
||||
package com.alibaba.nacos.consistency.snapshot;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* {@link Reader} unit test.
|
||||
*
|
||||
* @author chenglu
|
||||
* @date 2021-07-27 18:46
|
||||
*/
|
||||
public class ReaderTest {
|
||||
class ReaderTest {
|
||||
|
||||
private Reader reader;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
Map<String, LocalFileMeta> map = new HashMap<>(2);
|
||||
Properties properties = new Properties();
|
||||
properties.put("k", "v");
|
||||
@ -45,11 +46,11 @@ public class ReaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Assert.assertEquals("test", reader.getPath());
|
||||
void test() {
|
||||
assertEquals("test", reader.getPath());
|
||||
|
||||
Assert.assertEquals(1, reader.listFiles().size());
|
||||
assertEquals(1, reader.listFiles().size());
|
||||
|
||||
Assert.assertEquals("v", reader.getFileMeta("a").getFileMeta().getProperty("k"));
|
||||
assertEquals("v", reader.getFileMeta("a").getFileMeta().getProperty("k"));
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,11 @@
|
||||
|
||||
package com.alibaba.nacos.consistency.snapshot;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* {@link Writer} unit test.
|
||||
@ -27,27 +29,27 @@ import org.junit.Test;
|
||||
* @author chenglu
|
||||
* @date 2021-07-28 18:50
|
||||
*/
|
||||
public class WriterTest {
|
||||
class WriterTest {
|
||||
|
||||
private Writer writer;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
writer = new Writer("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Assert.assertEquals("test", writer.getPath());
|
||||
|
||||
Assert.assertTrue(writer.addFile("a"));
|
||||
void test() {
|
||||
assertEquals("test", writer.getPath());
|
||||
|
||||
Assert.assertTrue(writer.addFile("b", new LocalFileMeta()));
|
||||
assertTrue(writer.addFile("a"));
|
||||
|
||||
Assert.assertEquals(2, writer.listFiles().size());
|
||||
assertTrue(writer.addFile("b", new LocalFileMeta()));
|
||||
|
||||
Assert.assertTrue(writer.removeFile("a"));
|
||||
assertEquals(2, writer.listFiles().size());
|
||||
|
||||
Assert.assertEquals(1, writer.listFiles().size());
|
||||
assertTrue(writer.removeFile("a"));
|
||||
|
||||
assertEquals(1, writer.listFiles().size());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user