2222
2323import com .danga .MemCached .*;
2424import java .util .*;
25+ import java .io .Serializable ;
2526
2627import org .apache .log4j .Level ;
2728import 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