Skip to content

Commit 24ab99b

Browse files
committed
fix problem w/ serialized objects and also add more to unit tests
1 parent 4a635f8 commit 24ab99b

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

src/com/danga/MemCached/MemCachedClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,7 @@ private void loadItems( LineInputStream input, Map<String,Object> hm, boolean as
15411541
}
15421542

15431543
// we can only take out serialized objects
1544-
if ( ( flag & F_SERIALIZED ) == 0 ) {
1544+
if ( ( flag & F_SERIALIZED ) != F_SERIALIZED ) {
15451545
if ( primitiveAsString || asString ) {
15461546
// pulling out string value
15471547
log.info( "++++ retrieving object and stuffing into a string." );
@@ -2025,10 +2025,9 @@ public void loadItemsNIO( boolean asString, Map<String, StringBuilder> sockKeys,
20252025
timeRemaining = timeout;
20262026

20272027
while ( numConns > 0 && timeRemaining > 0 ) {
2028-
int n = selector.select( 3000 );
2028+
int n = selector.select( 5000 );
20292029
if ( n > 0 ) {
20302030
// we've got some activity; handle it
2031-
//
20322031
Iterator<SelectionKey> it = selector.selectedKeys().iterator();
20332032
while ( it.hasNext() ) {
20342033
SelectionKey key = it.next();
@@ -2038,6 +2037,7 @@ public void loadItemsNIO( boolean asString, Map<String, StringBuilder> sockKeys,
20382037
}
20392038
else {
20402039
// timeout likely... better check
2040+
// TODO: This seems like a problem area that we need to figure out how to handle.
20412041
log.error( "selector timed out waiting for activity" );
20422042
}
20432043

src/com/danga/MemCached/test/UnitTests.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.danga.MemCached.*;
2424
import java.util.*;
25+
import java.io.Serializable;
2526

2627
import org.apache.log4j.Level;
2728
import org.apache.log4j.Logger;
@@ -238,6 +239,13 @@ public static void test22() {
238239
log.error( "+ store/retrieve byte[] type test passed" );
239240
}
240241

242+
public static void test23() {
243+
TestClass tc = new TestClass( "foo", "bar", new Integer( 32 ) );
244+
mc.set( "foo", tc );
245+
assert tc.equals( (TestClass)mc.get( "foo" ) );
246+
log.error( "+ store/retrieve serialized object test passed" );
247+
}
248+
241249
/**
242250
* This runs through some simple tests of the MemCacheClient.
243251
*
@@ -295,6 +303,7 @@ public static void main(String[] args) {
295303
test17();
296304
test21();
297305
test22();
306+
test23();
298307

299308
for ( int i = 0; i < 3; i++ )
300309
test19();
@@ -320,4 +329,38 @@ public static void main(String[] args) {
320329
test20( 900*1024, 32*1024, 1 );
321330
}
322331
}
332+
333+
/**
334+
* Class for testing serializing of objects.
335+
*
336+
* @author $Author: $
337+
* @version $Revision: $ $Date: $
338+
*/
339+
public static final class TestClass implements Serializable {
340+
341+
private String field1;
342+
private String field2;
343+
private Integer field3;
344+
345+
public TestClass( String field1, String field2, Integer field3 ) {
346+
this.field1 = field1;
347+
this.field2 = field2;
348+
this.field3 = field3;
349+
}
350+
351+
public String getField1() { return this.field1; }
352+
public String getField2() { return this.field2; }
353+
public Integer getField3() { return this.field3; }
354+
355+
public boolean equals( Object o ) {
356+
if ( this == o ) return true;
357+
if ( !( o instanceof TestClass ) ) return false;
358+
359+
TestClass obj = (TestClass)o;
360+
361+
return ( ( this.field1 == obj.getField1() || ( this.field1 != null && this.field1.equals( obj.getField1() ) ) )
362+
&& ( this.field2 == obj.getField2() || ( this.field2 != null && this.field2.equals( obj.getField2() ) ) )
363+
&& ( this.field3 == obj.getField3() || ( this.field3 != null && this.field3.equals( obj.getField3() ) ) ) );
364+
}
365+
}
323366
}

0 commit comments

Comments
 (0)