throws Exception
{
//boolean show = true;//false;
JCS cache = JCS.getInstance( region );
Thread.sleep( 100 );
TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
lattr2.setTcpListenerPort( 1102 );
lattr2.setTransmissionTypeName( "TCP" );
lattr2.setTcpServer( "localhost:1110" );
lattr2.setIssueRemoveOnPut( true );
// should still try to remove
lattr2.setAllowPut( false );
// this service will put and remove using the lateral to
// the cache instance above
// the cache thinks it is different since the listenerid is different
LateralTCPService service = new LateralTCPService( lattr2 );
service.setListenerId( 123456 );
String keyToBeRemovedOnPut = "test1";
String keyToNotBeRemovedOnPut = "test2";
Serializable dataToPassHashCodeCompare = new Serializable()
{
private static final long serialVersionUID = 1L;
public int hashCode()
{
return 1;
}
};
//String dataToPassHashCodeCompare = "this should be the same and not
// get removed.";
//p( "dataToPassHashCodeCompare hashcode = " + +
// dataToPassHashCodeCompare.hashCode() );
cache.put( keyToBeRemovedOnPut, "this should get removed." );
ICacheElement element1 = new CacheElement( region, keyToBeRemovedOnPut, region
+ ":data-this shouldn't get there" );
service.update( element1 );
cache.put( keyToNotBeRemovedOnPut, dataToPassHashCodeCompare );
ICacheElement element2 = new CacheElement( region, keyToNotBeRemovedOnPut, dataToPassHashCodeCompare );
service.update( element2 );
/*
* try { for ( int i = 1; i < numOps; i++ ) { Random ran = new Random( i );
* int n = ran.nextInt( 4 ); int kn = ran.nextInt( range ); String key =
* "key" + kn;
*
* ICacheElement element = new CacheElement( region, key, region +
* ":data" + i + " junk asdfffffffadfasdfasf " + kn + ":" + n );
* service.update( element ); if ( show ) { p( "put " + key ); }
*
* if ( i % 100 == 0 ) { System.out.println( cache.getStats() ); }
* } p( "Finished cycle of " + numOps ); } catch ( Exception e ) { p(
* e.toString() ); e.printStackTrace( System.out ); throw e; }
*/
JCS jcs = JCS.getInstance( region );
String key = "testKey" + testNum;
String data = "testData" + testNum;
jcs.put( key, data );
String value = (String) jcs.get( key );
assertEquals( "Couldn't put normally.", data, value );
// make sure the items we can find are in the correct region.
for ( int i = 1; i < numOps; i++ )
{
String keyL = "key" + i;
String dataL = (String) jcs.get( keyL );
if ( dataL != null )
{
assertTrue( "Incorrect region detected.", dataL.startsWith( region ) );
}