Search in sources :

Example 31 with CacheWriterException

use of org.apache.geode.cache.CacheWriterException in project geode by apache.

the class ClientInterestNotifyDUnitTest method registerInterest.

/**
   * register interest with the server on ALL_KEYS
   *
   */
public static void registerInterest() {
    try {
        Cache cacheClient = GemFireCacheImpl.getInstance();
        Region region1 = cacheClient.getRegion(Region.SEPARATOR + REGION_NAME1);
        Region region2 = cacheClient.getRegion(Region.SEPARATOR + REGION_NAME2);
        // We intentionally do not register interest in region 3 to check no events recvd.
        Region region3 = cacheClient.getRegion(Region.SEPARATOR + REGION_NAME3);
        assertTrue(region1 != null);
        assertTrue(region2 != null);
        assertTrue(region3 != null);
        region1.registerInterest("ALL_KEYS", InterestResultPolicy.KEYS_VALUES, false, true);
        region2.registerInterest("ALL_KEYS", InterestResultPolicy.KEYS_VALUES, false, false);
    // We intentionally do not register interest in region 3 to check no events recvd.
    // region3.registerInterestBlah();
    } catch (CacheWriterException e) {
        fail("test failed due to " + e);
    }
}
Also used : Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 32 with CacheWriterException

use of org.apache.geode.cache.CacheWriterException in project geode by apache.

the class ClientServerMiscDUnitTest method registerInterestForInvalidatesInBothTheRegions.

public static void registerInterestForInvalidatesInBothTheRegions() {
    try {
        Cache cache = new ClientServerMiscDUnitTest().getCache();
        Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME1);
        assertNotNull(r1);
        Region r2 = cache.getRegion(Region.SEPARATOR + REGION_NAME2);
        assertNotNull(r2);
        r1.registerInterest("ALL_KEYS", false, false);
        r2.registerInterest("ALL_KEYS", false, false);
    } catch (CacheWriterException e) {
        e.printStackTrace();
        Assert.fail("Test failed due to CacheWriterException during registerInterestnBothRegions", e);
    }
}
Also used : LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 33 with CacheWriterException

use of org.apache.geode.cache.CacheWriterException in project geode by apache.

the class ConflationDUnitTest method unregisterInterest.

/**
   * register interest with the server on ALL_KEYS
   *
   */
public static void unregisterInterest() {
    try {
        Region region1 = cache.getRegion(Region.SEPARATOR + REGION_NAME1);
        Region region2 = cache.getRegion(Region.SEPARATOR + REGION_NAME2);
        region1.unregisterInterest("ALL_KEYS");
        region2.unregisterInterest("ALL_KEYS");
    } catch (CacheWriterException e) {
        fail("test failed due to " + e);
    }
}
Also used : HARegion(org.apache.geode.internal.cache.HARegion) Region(org.apache.geode.cache.Region) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 34 with CacheWriterException

use of org.apache.geode.cache.CacheWriterException in project geode by apache.

the class QueryResultData method executeQueryTestCases.

private void executeQueryTestCases() {
    HttpHeaders headers = setAcceptAndContentTypeHeaders();
    HttpEntity<Object> entity;
    int totalRequests = TEST_DATA.length;
    String expectedEx = null;
    for (int index = 0; index < totalRequests; index++) {
        try {
            expectedEx = addExpectedException(index);
            final String restRequestUrl = createRestURL(this.baseURL, TEST_DATA[index][URL_INDEX]);
            entity = new HttpEntity<>(TEST_DATA[index][REQUEST_BODY_INDEX], headers);
            ResponseEntity<String> result = RestTestUtils.getRestTemplate().exchange(restRequestUrl, (HttpMethod) TEST_DATA[index][METHOD_INDEX], entity, String.class);
            validateGetAllResult(index, result);
            validateQueryResult(index, result);
            assertEquals(result.getStatusCode(), TEST_DATA[index][STATUS_CODE_INDEX]);
            assertEquals(result.hasBody(), ((Boolean) TEST_DATA[index][RESPONSE_HAS_BODY_INDEX]).booleanValue());
            verifyRegionSize(index, result);
        // TODO:
        // verify location header
        } catch (HttpClientErrorException e) {
            if (VALID_409_URL_INDEXS.contains(index)) {
                // create-409, conflict testcase. [create on already existing key]
                assertEquals(e.getStatusCode(), TEST_DATA[index][STATUS_CODE_INDEX]);
                assertEquals(StringUtils.hasText(e.getResponseBodyAsString()), ((Boolean) TEST_DATA[index][RESPONSE_HAS_BODY_INDEX]).booleanValue());
            } else if (VALID_400_URL_INDEXS.contains(index)) {
                // 400, Bad Request testcases. [create with malformed Json]
                assertEquals(e.getStatusCode(), TEST_DATA[index][STATUS_CODE_INDEX]);
                assertEquals(StringUtils.hasText(e.getResponseBodyAsString()), ((Boolean) TEST_DATA[index][RESPONSE_HAS_BODY_INDEX]).booleanValue());
            } else if (VALID_404_URL_INDEXS.contains(index)) {
                // create-404, Not Found testcase. [create on not-existing region]
                assertEquals(e.getStatusCode(), TEST_DATA[index][STATUS_CODE_INDEX]);
                assertEquals(StringUtils.hasText(e.getResponseBodyAsString()), ((Boolean) TEST_DATA[index][RESPONSE_HAS_BODY_INDEX]).booleanValue());
            } else if (VALID_405_URL_INDEXS.contains(index)) {
                // create-404, Not Found testcase. [create on not-existing region]
                assertEquals(e.getStatusCode(), TEST_DATA[index][STATUS_CODE_INDEX]);
                assertEquals(StringUtils.hasText(e.getResponseBodyAsString()), ((Boolean) TEST_DATA[index][RESPONSE_HAS_BODY_INDEX]).booleanValue());
            } else {
                fail("Index:" + index + " " + TEST_DATA[index][METHOD_INDEX] + " " + TEST_DATA[index][URL_INDEX] + " should not have thrown exception ");
            }
        } catch (HttpServerErrorException se) {
            // index=4, create- 500, INTERNAL_SERVER_ERROR testcase. [create on Region with
            // DataPolicy=Empty set]
            // index=7, create- 500, INTERNAL_SERVER_ERROR testcase. [Get, attached cache loader throws
            // Timeout exception]
            // index=11, put- 500, [While doing R.put, CacheWriter.beforeCreate() has thrown
            // CacheWriterException]
            // .... and more test cases
            assertEquals(TEST_DATA[index][STATUS_CODE_INDEX], se.getStatusCode());
            assertEquals(TEST_DATA[index][RESPONSE_HAS_BODY_INDEX], StringUtils.hasText(se.getResponseBodyAsString()));
        } catch (Exception e) {
            caught("caught Exception in executeQueryTestCases " + "Index:" + index + " " + TEST_DATA[index][METHOD_INDEX] + " " + TEST_DATA[index][URL_INDEX] + " :: Unexpected ERROR...!!", e);
        } finally {
            c.getLogger().info("<ExpectedException action=remove>" + expectedEx + "</ExpectedException>");
        }
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) JSONObject(org.json.JSONObject) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException) TimeoutException(org.apache.geode.cache.TimeoutException) JSONException(org.json.JSONException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CacheWriterException(org.apache.geode.cache.CacheWriterException) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException) UnknownHostException(java.net.UnknownHostException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException)

Example 35 with CacheWriterException

use of org.apache.geode.cache.CacheWriterException in project geode by apache.

the class HARegion method findObjectInSystem.

/**
   * @return the deserialized value
   * @see LocalRegion#findObjectInSystem(KeyInfo, boolean, TXStateInterface, boolean, Object,
   *      boolean, boolean, ClientProxyMembershipID, EntryEventImpl, boolean)
   * 
   */
@Override
protected Object findObjectInSystem(KeyInfo keyInfo, boolean isCreate, TXStateInterface txState, boolean generateCallbacks, Object localValue, boolean disableCopyOnRead, boolean preferCD, ClientProxyMembershipID requestingClient, EntryEventImpl clientEvent, boolean returnTombstones) throws CacheLoaderException, TimeoutException {
    Object value = null;
    final Object key = keyInfo.getKey();
    final Object aCallbackArgument = keyInfo.getCallbackArg();
    // copy into local var to prevent race condition
    RegionEntry re = null;
    Assert.assertTrue(!hasServerProxy());
    CacheLoader loader = basicGetLoader();
    if (loader != null) {
        final LoaderHelper loaderHelper = loaderHelperFactory.createLoaderHelper(key, aCallbackArgument, false, /* netSearchAllowed */
        true, /* netloadallowed */
        null);
        try {
            value = loader.load(loaderHelper);
        } finally {
        }
        if (value != null) {
            try {
                validateKey(key);
                Operation op;
                if (isCreate) {
                    op = Operation.LOCAL_LOAD_CREATE;
                } else {
                    op = Operation.LOCAL_LOAD_UPDATE;
                }
                @Released EntryEventImpl event = EntryEventImpl.create(this, op, key, value, aCallbackArgument, false, getMyId(), generateCallbacks);
                try {
                    re = basicPutEntry(event, 0L);
                } finally {
                    event.release();
                }
                if (txState == null) {
                }
            } catch (CacheWriterException cwe) {
            // @todo smenon Log the exception
            }
        }
    }
    if (isCreate) {
        recordMiss(re, key);
    }
    return value;
}
Also used : LoaderHelper(org.apache.geode.cache.LoaderHelper) Released(org.apache.geode.internal.offheap.annotations.Released) CacheLoader(org.apache.geode.cache.CacheLoader) Operation(org.apache.geode.cache.Operation) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Aggregations

CacheWriterException (org.apache.geode.cache.CacheWriterException)50 Region (org.apache.geode.cache.Region)22 Test (org.junit.Test)14 EntryEvent (org.apache.geode.cache.EntryEvent)13 Released (org.apache.geode.internal.offheap.annotations.Released)12 AttributesFactory (org.apache.geode.cache.AttributesFactory)11 CacheException (org.apache.geode.cache.CacheException)11 TimeoutException (org.apache.geode.cache.TimeoutException)11 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)10 CacheWriterAdapter (org.apache.geode.cache.util.CacheWriterAdapter)9 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)9 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)8 VM (org.apache.geode.test.dunit.VM)8 Cache (org.apache.geode.cache.Cache)7 RegionEvent (org.apache.geode.cache.RegionEvent)7 Host (org.apache.geode.test.dunit.Host)7 IOException (java.io.IOException)6 CacheWriter (org.apache.geode.cache.CacheWriter)6 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)6 InternalGemFireError (org.apache.geode.InternalGemFireError)5