forked from EsotericSoftware/kryonet
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a test for the ObjectIntMap, improved the code coverage & reworked
the server discovery.
- Loading branch information
Showing
9 changed files
with
140 additions
and
30 deletions.
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
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
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 |
---|---|---|
|
@@ -39,8 +39,7 @@ | |
* @author Nathan Sweet <[email protected]> | ||
*/ | ||
class TcpConnection { | ||
private static final int IPTOS_LOWDELAY = 0x10; | ||
|
||
|
||
SocketChannel socketChannel; | ||
int keepAliveMillis = 8000; | ||
final ByteBuffer readBuffer, writeBuffer; | ||
|
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
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
98 changes: 98 additions & 0 deletions
98
src/test/java/com/esotericsoftware/kryonet/util/ObjectIntMapTest.java
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,98 @@ | ||
package com.esotericsoftware.kryonet.util; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
public class ObjectIntMapTest { | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testConstructor() { | ||
new ObjectIntMap(-1, 0); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testConstructor2() { | ||
new ObjectIntMap((1 << 30) + 1, 0); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testConstructor3() { | ||
new ObjectIntMap(15, 0); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testConstructor4() { | ||
new ObjectIntMap(15, -1); | ||
} | ||
|
||
@Test | ||
public void testConstructor5() { | ||
ObjectIntMap tmp = new ObjectIntMap(15, 2); | ||
tmp.put("S", 3); | ||
tmp.put("A", 11); | ||
tmp.put("S", 2); | ||
|
||
ObjectIntMap map2 = new ObjectIntMap<>(tmp); | ||
|
||
assertEquals(tmp.capacity, map2.capacity); | ||
assertArrayEquals(tmp.keyTable, map2.keyTable); | ||
assertEquals(tmp.size, map2.size); | ||
assertEquals(tmp.stashSize, map2.stashSize); | ||
assertArrayEquals(tmp.valueTable, map2.valueTable); | ||
} | ||
|
||
@Test(expected = NullPointerException.class) | ||
public void testPut() { | ||
ObjectIntMap tmp = new ObjectIntMap(15, 2); | ||
tmp.put(null, 3); | ||
} | ||
|
||
@Test | ||
public void testStuff() { | ||
ObjectIntMap tmp = new ObjectIntMap(4, 2); | ||
|
||
// toString() - 1 | ||
assertEquals("{}", tmp.toString()); | ||
|
||
// put(x, y) | ||
tmp.put("S", 3); | ||
tmp.put("A", 11); | ||
|
||
assertEquals(3, tmp.get("S", -1)); | ||
assertEquals(2, tmp.size); | ||
|
||
tmp.put("S", 2); | ||
tmp.put("K", 5); | ||
|
||
assertEquals(2, tmp.get("S", -1)); | ||
|
||
// remove(x, y) | ||
assertEquals(5, tmp.remove("K", -1)); | ||
|
||
// toString() - 2 | ||
assertEquals("{S=2, A=11}", tmp.toString()); | ||
|
||
// ensureCapacity(x) | ||
assertEquals(4, tmp.capacity); | ||
|
||
tmp.ensureCapacity(5); | ||
assertEquals(4, tmp.capacity); | ||
|
||
tmp.ensureCapacity(50); | ||
assertEquals(32, tmp.capacity); | ||
|
||
// findKex(y) | ||
assertEquals("A", tmp.findKey(11)); | ||
|
||
// containsKey/Value(x) | ||
assertTrue(tmp.containsKey("S")); | ||
assertFalse(tmp.containsKey("G")); | ||
assertTrue(tmp.containsValue(11)); | ||
assertFalse(tmp.containsValue(26)); | ||
} | ||
|
||
} |