Package org.springframework.data.gemfire.function.execution

Source Code of org.springframework.data.gemfire.function.execution.FunctionExecutionTests

/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.springframework.data.gemfire.function.execution;

import static org.junit.Assert.assertEquals;

import java.util.Iterator;
import java.util.Properties;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.data.gemfire.ForkUtil;
import org.springframework.data.gemfire.fork.FunctionCacheServerProcess;

import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
import com.gemstone.gemfire.cache.client.ClientRegionFactory;
import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
import com.gemstone.gemfire.cache.client.Pool;
import com.gemstone.gemfire.cache.client.PoolFactory;
import com.gemstone.gemfire.cache.client.PoolManager;

/**
* @author David Turanski
*
*/
public class FunctionExecutionTests {

  private static ClientCache cache = null;

  private static Pool pool = null;

  private static Region<String, Integer> clientRegion = null;

  @BeforeClass
  public static void startUp() throws Exception {
    // Registers function "echoFunction"
    ForkUtil.cacheServer(FunctionCacheServerProcess.class);

    Properties props = new Properties();
    props.put("mcast-port", "0");
    props.put("name", "function-client");
    props.put("log-level", "warning");

    ClientCacheFactory ccf = new ClientCacheFactory(props);
    ccf.setPoolSubscriptionEnabled(true);
    cache = ccf.create();

    PoolFactory pf = PoolManager.createFactory();
    pf.addServer("localhost", 40404);
    pf.setSubscriptionEnabled(true);
    pool = pf.create("client");

    ClientRegionFactory<String, Integer> crf = cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
    crf.setPoolName("client");
    clientRegion = crf.create("test-function");
  }

  @AfterClass
  public static void cleanUp() {
    ForkUtil.sendSignal();
    if (clientRegion != null) {
      clientRegion.destroyRegion();
    }
    if (pool != null) {
      pool.destroy();
      pool = null;
    }

    if (cache != null) {
      cache.close();
    }
    cache = null;
  }

  @Test
  public void testBasicFunctionExecutions() { 
    verifyfunctionExecution(new RegionFunctionExecution(clientRegion));
    verifyfunctionExecution(new ServerFunctionExecution(cache));
    verifyfunctionExecution(new PoolServerFunctionExecution(pool));
    verifyfunctionExecution(new ServersFunctionExecution(cache));   
  }
 
  
 
  private void verifyfunctionExecution(AbstractFunctionExecution functionExecution) {
    Iterable<String> results = functionExecution
    .setArgs("1","2","3")
    .setFunctionId("echoFunction")
    .execute();
    Iterator<String> it = results.iterator();
    for (int i = 1; i<= 3; i++) {
      assertEquals(String.valueOf(i),it.next());
    }
  }

}
TOP

Related Classes of org.springframework.data.gemfire.function.execution.FunctionExecutionTests

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.