Skip to content

Commit bdd5534

Browse files
committed
Modified TestMemcached.java to work with rejig client.
1 parent 76046c0 commit bdd5534

File tree

2 files changed

+89
-65
lines changed

2 files changed

+89
-65
lines changed

build.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ repositories {
3131
task memcachedBench(type: JavaExec) {
3232
main = 'edu.usc.cs550.rejig.client.test.MemcachedBench'
3333
classpath = sourceSets.test.runtimeClasspath
34-
// Pass arguments using -PrunsAndStart=x
34+
// Pass arguments using -PcmdArgs=x
3535
if (project.hasProperty('cmdArgs')) {
3636
args(cmdArgs.split(','))
3737
} else {
@@ -42,10 +42,15 @@ task memcachedBench(type: JavaExec) {
4242
task memcachedTest(type: JavaExec) {
4343
main = 'edu.usc.cs550.rejig.client.test.MemcachedTest'
4444
classpath = sourceSets.test.runtimeClasspath
45-
// Pass arguments using -PrunsAndStart=x
45+
// Pass arguments using -PcmdArgs=x
4646
if (project.hasProperty('cmdArgs')) {
4747
args(cmdArgs.split(','))
4848
} else {
4949
args(['10', '100000', '10'])
5050
}
5151
}
52+
53+
task testMemcached(type: JavaExec) {
54+
main = 'edu.usc.cs550.rejig.client.test.TestMemcached'
55+
classpath = sourceSets.test.runtimeClasspath
56+
}
Lines changed: 82 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,82 @@
1-
// /**
2-
// * Copyright (c) 2008 Greg Whalin
3-
// * All rights reserved.
4-
// *
5-
// * This library is free software; you can redistribute it and/or
6-
// * modify it under the terms of the BSD license
7-
// *
8-
// * This library is distributed in the hope that it will be
9-
// * useful, but WITHOUT ANY WARRANTY; without even the implied
10-
// * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11-
// * PURPOSE.
12-
// *
13-
// * You should have received a copy of the BSD License along with this
14-
// * library.
15-
// *
16-
// * @author greg whalin <[email protected]>
17-
// */
18-
// package edu.usc.cs550.rejig.client.test;
19-
20-
// import edu.usc.cs550.rejig.client.*;
21-
// import org.apache.log4j.*;
22-
23-
// public class TestMemcached {
24-
// public static void main(String[] args) {
25-
// // memcached should be running on port 11211 but NOT on 11212
26-
27-
// BasicConfigurator.configure();
28-
// String[] servers = { "192.168.1.1:1624", "192.168.1.1:1625" };
29-
// SockIOPool pool = SockIOPool.getInstance();
30-
// pool.setServers( servers );
31-
// pool.setFailover( true );
32-
// pool.setInitConn( 10 );
33-
// pool.setMinConn( 5 );
34-
// pool.setMaxConn( 250 );
35-
// pool.setMaintSleep( 30 );
36-
// pool.setNagle( false );
37-
// pool.setSocketTO( 3000 );
38-
// pool.setAliveCheck( true );
39-
// pool.initialize();
40-
41-
// MemcachedClient mcc = new MemcachedClient();
42-
43-
// // turn off most memcached client logging:
44-
// com.meetup.memcached.Logger.getLogger( MemcachedClient.class.getName() ).setLevel( com.meetup.memcached.Logger.LEVEL_WARN );
45-
46-
// for ( int i = 0; i < 10; i++ ) {
47-
// boolean success = mcc.set( "" + i, "Hello!" );
48-
// String result = (String)mcc.get( "" + i );
49-
// System.out.println( String.format( "set( %d ): %s", i, success ) );
50-
// System.out.println( String.format( "get( %d ): %s", i, result ) );
51-
// }
52-
53-
// System.out.println( "\n\t -- sleeping --\n" );
54-
// try { Thread.sleep( 10000 ); } catch ( Exception ex ) { }
55-
56-
// for ( int i = 0; i < 10; i++ ) {
57-
// boolean success = mcc.set( "" + i, "Hello!" );
58-
// String result = (String)mcc.get( "" + i );
59-
// System.out.println( String.format( "set( %d ): %s", i, success ) );
60-
// System.out.println( String.format( "get( %d ): %s", i, result ) );
61-
// }
62-
// }
63-
// }
1+
/**
2+
* Copyright (c) 2008 Greg Whalin
3+
* All rights reserved.
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the BSD license
7+
*
8+
* This library is distributed in the hope that it will be
9+
* useful, but WITHOUT ANY WARRANTY; without even the implied
10+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11+
* PURPOSE.
12+
*
13+
* You should have received a copy of the BSD License along with this
14+
* library.
15+
*
16+
* @author greg whalin <[email protected]>
17+
*/
18+
package edu.usc.cs550.rejig.client.test;
19+
20+
import edu.usc.cs550.rejig.client.*;
21+
import edu.usc.cs550.rejig.interfaces.Fragment;
22+
import edu.usc.cs550.rejig.interfaces.RejigConfig;
23+
24+
import org.apache.log4j.*;
25+
26+
public class TestMemcached {
27+
public static void main(String[] args) {
28+
// memcached should be running on port 11211 but NOT on 11212
29+
30+
BasicConfigurator.configure();
31+
String[] servers = { "localhost:11211", "localhost:11212" };
32+
// initialize the pool options
33+
SockIOPool.SockIOPoolOptions options = new SockIOPool.SockIOPoolOptions();
34+
options.failover = true;
35+
options.initConn = 10;
36+
options.minConn = 5;
37+
options.maxConn = 250;
38+
options.maintSleep = 30;
39+
options.nagle = false;
40+
options.socketTO = 3000;
41+
options.aliveCheck = true;
42+
43+
// set RejigConfig
44+
MockRejigConfigReader configReader = new MockRejigConfigReader();
45+
configReader.setConfig(RejigConfig.newBuilder()
46+
.setId(1)
47+
.addFragment(Fragment.newBuilder()
48+
.setId(1)
49+
.setAddress(servers[0])
50+
.build()
51+
).addFragment(Fragment.newBuilder()
52+
.setId(1)
53+
.setAddress(servers[1])
54+
.build()
55+
).build());
56+
57+
// get client instance
58+
MemcachedClient mcc = new MemcachedClient(
59+
null, new MockErrorHandler(),
60+
"test", configReader, options);
61+
62+
// turn off most memcached client logging:
63+
edu.usc.cs550.rejig.client.Logger.getLogger( MemcachedClient.class.getName() ).setLevel( edu.usc.cs550.rejig.client.Logger.LEVEL_WARN );
64+
65+
for ( int i = 0; i < 10; i++ ) {
66+
boolean success = mcc.set( "" + i, "Hello!" );
67+
String result = (String)mcc.get( "" + i );
68+
System.out.println( String.format( "set( %d ): %s", i, success ) );
69+
System.out.println( String.format( "get( %d ): %s", i, result ) );
70+
}
71+
72+
System.out.println( "\n\t -- sleeping --\n" );
73+
try { Thread.sleep( 10000 ); } catch ( Exception ex ) { }
74+
75+
for ( int i = 0; i < 10; i++ ) {
76+
boolean success = mcc.set( "" + i, "Hello!" );
77+
String result = (String)mcc.get( "" + i );
78+
System.out.println( String.format( "set( %d ): %s", i, success ) );
79+
System.out.println( String.format( "get( %d ): %s", i, result ) );
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)