Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C2026178D3 for ; Tue, 5 May 2015 18:21:00 +0000 (UTC) Received: (qmail 66198 invoked by uid 500); 5 May 2015 18:21:00 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 66107 invoked by uid 500); 5 May 2015 18:21:00 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 66095 invoked by uid 99); 5 May 2015 18:21:00 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 May 2015 18:21:00 +0000 Date: Tue, 5 May 2015 18:21:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (LANG-740) Add a Memoizer class MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/LANG-740?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14528978#comment-14528978 ] ASF GitHub Bot commented on LANG-740: ------------------------------------- Github user britter commented on a diff in the pull request: https://github.com/apache/commons-lang/pull/80#discussion_r29696898 --- Diff: src/test/java/org/apache/commons/lang3/concurrent/MemoizerTest.java --- @@ -0,0 +1,112 @@ +package org.apache.commons.lang3.concurrent; + +import org.easymock.EasyMockRunner; +import org.easymock.Mock; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +@RunWith(EasyMockRunner.class) +public class MemoizerTest { + + @Mock + private Computable computable; + + @Test + public void testOnlyCallComputableOnceIfDoesNotThrowException() throws Exception { + Integer input = 1; + Memoizer memoizer = new Memoizer(computable); + expect(computable.compute(input)).andReturn(input); + replay(computable); + + assertEquals("Should call computable first time", input, memoizer.compute(input)); + assertEquals("Should not call the computable the second time", input, memoizer.compute(input)); + } + + @Test(expected = IllegalStateException.class) + public void testDefaultBehaviourNotToRecalculateExecutionExceptions() throws Exception { + Integer input = 1; + Integer answer = 3; + Memoizer memoizer = new Memoizer(computable); + InterruptedException interruptedException = new InterruptedException(); + expect(computable.compute(input)).andThrow(interruptedException); + replay(computable); + + try { + memoizer.compute(input); + fail(); + } + catch (Throwable ex) { + //Should always be thrown the first time + } + + memoizer.compute(input); + } + + @Test(expected = IllegalStateException.class) + public void testDoesNotRecalculateWhenSetToFalse() throws Exception { + Integer input = 1; + Integer answer = 3; --- End diff -- answer is unused > Add a Memoizer class > -------------------- > > Key: LANG-740 > URL: https://issues.apache.org/jira/browse/LANG-740 > Project: Commons Lang > Issue Type: New Feature > Components: lang.concurrent.* > Reporter: Gary Gregory > Assignee: Gary Gregory > Fix For: Review Patch, 3.5 > > Attachments: LANG-740.patch > > > I am currently using a class like the Memoizer class [1] from "Java > Concurrency in Practice" [2], a great book. > It would fit perfectly in org.apache.commons.lang3.concurrent. > [1] http://jcip.net/listings/Memoizer.java > [2] http://jcip.net/ > There is no licensing issue because the code is in the public domain: > {noformat} > ---------- Forwarded message ---------- > From: Brian Goetz > Date: Tue, Aug 9, 2011 at 5:40 PM > Subject: Re: Apache Commons Lang and Memoizer > To: Gary Gregory , Tim Peierls > No license issues -- the code is in the public domain: > Written by Brian Goetz and Tim Peierls with assistance from members of > JCP JSR-166 Expert Group and released to the public domain, as explained at > http://creativecommons.org/licenses/publicdomain > Code for the samples can be downloaded from http://www.jcip.net/listings.html. > Cheers, > -Brian > On 8/9/2011 5:38 PM, Gary Gregory wrote: > > > > Hi Brian, > > > > I would like to include a Memoizer in the next release of Apache > > Commons Lang [1]. > > > > Can we use the Memoizer pattern from "Java Concurrency in Practice"? I > > think I would reuse the code from the class Memoizer and change names, > > things like that. > > > > We are talking about this on the Lang mailing list and are wondering > > if there are any licensing issues. > > > > [1] https://commons.apache.org/lang/ > > > -- > Thank you, > Gary > http://garygregory.wordpress.com/ > http://garygregory.com/ > http://people.apache.org/~ggregory/ > http://twitter.com/GaryGregory > {noformat} -- This message was sent by Atlassian JIRA (v6.3.4#6332)