Skip to content

Tests #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sudo: required
before_script:
- ./install_tarantool.sh
language: java
jdk:
- openjdk6
18 changes: 18 additions & 0 deletions install_tarantool.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

curl http://download.tarantool.org/tarantool/1.7/gpgkey | sudo apt-key add -
release=`lsb_release -c -s`

# install https download transport for APT
sudo apt-get -y install apt-transport-https

# append two lines to a list of source repositories
sudo rm -f /etc/apt/sources.list.d/*tarantool*.list
sudo tee /etc/apt/sources.list.d/tarantool_1_7.list <<- EOF
deb http://download.tarantool.org/tarantool/1.7/ubuntu/ $release main
deb-src http://download.tarantool.org/tarantool/1.7/ubuntu/ $release main
EOF

# install
sudo apt-get update
sudo apt-get -y install tarantool
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.msgpack</groupId>
<artifactId>msgpack-core</artifactId>
<version>0.8.13</version>
<scope>test</scope>
</dependency>
</dependencies>

<parent>
Expand Down
127 changes: 127 additions & 0 deletions src/test/java/org/tarantool/MsgPackLiteTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package org.tarantool;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.msgpack.core.MessageBufferPacker;
import org.msgpack.core.MessagePack;

public class MsgPackLiteTest {
private MessageBufferPacker packer;

@Before
public void setup() {
packer = MessagePack.newDefaultBufferPacker();
}

@After
public void tearDown() throws IOException {
packer.close();
}

@Test
public void testNull() throws IOException {
packer.packNil();
byte[] actual = packActual(null);
Assert.assertArrayEquals(packer.toByteArray(), actual);
}

@Test
public void testInt() throws IOException {
packer.packInt(Integer.MAX_VALUE);
byte[] actual = packActual(Integer.MAX_VALUE);
Assert.assertArrayEquals(packer.toByteArray(), actual);
}

@Test
public void testLong() throws IOException {
packer.packLong(Long.MAX_VALUE);
byte[] actual = packActual(Long.MAX_VALUE);
Assert.assertArrayEquals(packer.toByteArray(), actual);
}

@Test
public void testString() throws IOException {
packer.packString("FooBar");
byte[] actual = packActual("FooBar");
Assert.assertArrayEquals(packer.toByteArray(), actual);
}

@Test
public void testArray() throws IOException {
packer.packArrayHeader(2);
packer.packString("Foo");
packer.packString("Bar");

byte[] actual = packActual(new String[] { "Foo", "Bar" });
Assert.assertArrayEquals(packer.toByteArray(), actual);
}

@Test
public void testList() throws IOException {
packer.packArrayHeader(2);
packer.packString("Foo");
packer.packString("Bar");

byte[] actual = packActual(Arrays.asList("Foo", "Bar"));
Assert.assertArrayEquals(packer.toByteArray(), actual);
}

@Test
public void testBigList() throws IOException {
packer.packArrayHeader(100);
for (int i = 0; i < 100; i++) {
packer.packString("Foo");
}

byte[] actual = packActual(Collections.nCopies(100, "Foo"));
Assert.assertArrayEquals(packer.toByteArray(), actual);
}

@Test
public void testKeyCode() throws IOException{
packer.packInt(Key.CODE.id);
Assert.assertArrayEquals(packer.toByteArray(), packActual(Key.CODE));
}

@Test
public void testKeyData() throws IOException{
packer.packInt(Key.DATA.id);
Assert.assertArrayEquals(packer.toByteArray(), packActual(Key.DATA));
}

@Test
public void testKeyIterator() throws IOException{
packer.packInt(Key.ITERATOR.id);
Assert.assertArrayEquals(packer.toByteArray(), packActual(Key.ITERATOR));
}

@Test
public void testMap() throws IOException {
packer.packMapHeader(2);
packer.packString("Foo");
packer.packString("Bar");
packer.packString("Bar");
packer.packString("Foo");

Map<String, String> map = new LinkedHashMap<String, String>();
map.put("Foo", "Bar");
map.put("Bar", "Foo");
byte[] actual = packActual(map);
Assert.assertArrayEquals(packer.toByteArray(), actual);
}

private static byte[] packActual(Object obj) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
MsgPackLite.INSTANCE.pack(obj, out);
return out.toByteArray();
}
}
24 changes: 24 additions & 0 deletions src/test/java/org/tarantool/TarantoolConnectionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.tarantool;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Collections;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;

public class TarantoolConnectionTest {

@Test
public void testGuestConnect() throws IOException {
Socket socket = new Socket();
socket.connect(new InetSocketAddress("127.0.0.1", 3301));
TarantoolConnection con = new TarantoolConnection(null, null, socket);
List<?> result = con.select(281, 0, Collections.emptyList(), 0, 1024, 0);
Assert.assertFalse(result.isEmpty());
con.close();
}

}