-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Document serialVersionUID * old serialVersionUID
- Loading branch information
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.redisearch; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class DocumentTest { | ||
|
||
@Test | ||
public void serialize() throws IOException, ClassNotFoundException { | ||
String id = "9f"; | ||
double score = 10d; | ||
Map<String, Object> map = new HashMap<>(); | ||
map.put("string", "c"); | ||
map.put("float", 12d); | ||
byte[] payload = "1a".getBytes(); | ||
Document document = new Document(id, map, score, payload); | ||
|
||
ByteArrayOutputStream aos = new ByteArrayOutputStream(); | ||
ObjectOutputStream oos = new ObjectOutputStream(aos); | ||
oos.writeObject(document); | ||
oos.flush(); | ||
oos.close(); | ||
|
||
ByteArrayInputStream ais = new ByteArrayInputStream(aos.toByteArray()); | ||
ObjectInputStream ois = new ObjectInputStream(ais); | ||
Document read = (Document) ois.readObject(); | ||
ois.close(); | ||
|
||
assertEquals(id, read.getId()); | ||
assertEquals(score, read.getScore(), 0d); | ||
assertArrayEquals(payload, read.getPayload()); | ||
assertEquals("c", read.getString("string")); | ||
assertEquals(Double.valueOf(12d), read.get("float")); | ||
} | ||
} |