From dd8efe3e30bf857ee000ed3f3211df9193ce8d21 Mon Sep 17 00:00:00 2001 From: John Blum Date: Thu, 19 Mar 2015 11:09:29 -0700 Subject: [PATCH] SGF-384 - Issue with partitioned-region-template when persistence is enabled. Add IOUtils and ThrowableUtils to the ..test.support package. --- .../data/gemfire/test/support/IOUtils.java | 53 +++++++++++++++++++ .../gemfire/test/support/ThrowableUtils.java | 40 ++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 src/test/java/org/springframework/data/gemfire/test/support/IOUtils.java create mode 100644 src/test/java/org/springframework/data/gemfire/test/support/ThrowableUtils.java diff --git a/src/test/java/org/springframework/data/gemfire/test/support/IOUtils.java b/src/test/java/org/springframework/data/gemfire/test/support/IOUtils.java new file mode 100644 index 00000000..bab1298e --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/test/support/IOUtils.java @@ -0,0 +1,53 @@ +/* + * Copyright 2010-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.test.support; + +import java.io.Closeable; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * The IOUtils class is an utility class working with IO operations. + * + * @author John Blum + * @since 1.5.0 + */ +@SuppressWarnings("unused") +public abstract class IOUtils { + + private static final Logger log = Logger.getLogger(IOUtils.class.getName()); + + public static boolean close(final Closeable closeable) { + if (closeable != null) { + try { + closeable.close(); + return true; + } + catch (IOException ignore) { + if (log.isLoggable(Level.FINE)) { + log.fine(String.format("Failed to close Closeable object (%1$s) due to I/O error:%n%2$s", + closeable, ThrowableUtils.toString(ignore))); + } + + } + } + + return false; + } + +} diff --git a/src/test/java/org/springframework/data/gemfire/test/support/ThrowableUtils.java b/src/test/java/org/springframework/data/gemfire/test/support/ThrowableUtils.java new file mode 100644 index 00000000..f71e8c8e --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/test/support/ThrowableUtils.java @@ -0,0 +1,40 @@ +/* + * Copyright 2010-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.test.support; + +import java.io.PrintWriter; +import java.io.StringWriter; + +/** + * The ThrowableUtils class is a utility class for working with Throwable, Exception and Error objects. + * + * @author John Blum + * @see java.lang.Error + * @see java.lang.Exception + * @see java.lang.Throwable + * @since 1.5.0 + */ +@SuppressWarnings("unused") +public abstract class ThrowableUtils { + + public static String toString(final Throwable t) { + StringWriter writer = new StringWriter(); + t.printStackTrace(new PrintWriter(writer)); + return writer.toString(); + } + +}