Heroku MemCached Junit Test

Heroku Memcached Cloud Junit Test

package com.example.cache;

import static org.junit.Assert.*;

import java.io.IOException;
import java.math.BigInteger;

import net.spy.memcached.AddrUtil;
import net.spy.memcached.ConnectionFactoryBuilder;
import net.spy.memcached.MemcachedClient;
import net.spy.memcached.auth.AuthDescriptor;
import net.spy.memcached.auth.PlainCallbackHandler;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.example.model.Customer;

public class CacheCustomerServiceTest {
	private static final String USERNAME="######";
	private static final String PASSWORD="######";
	private static final String HOST="######";
	static class ContextConfiguration{
		public MemcachedClient memcachedConfig() {
			 AuthDescriptor ad = new AuthDescriptor(new String[] { "PLAIN" },
				        new PlainCallbackHandler(USERNAME, PASSWORD));

			MemcachedClient mc = new MemcachedClient(
					new ConnectionFactoryBuilder()
			return mc;
		} catch (IOException ex) {}
			return null;
	@Autowired MemcachedClient memcachedConfig;
	public void testMemCachedSet() {
		memcachedConfig.set("customerKey", 3600, new Customer(new BigInteger("1"), "John", "Doe"));
		Object value = memcachedConfig.get("customerKey");

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: