Skip to content

Commit ad1f2e4

Browse files
committed
add samples for async testing
1 parent 60b080d commit ad1f2e4

File tree

20 files changed

+706
-0
lines changed

20 files changed

+706
-0
lines changed

CLA.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Contributor’s License Agreement
2+
3+
Thank you for your interest in contributing to the Reactive Design Patterns github Organization.
4+
In order to clarify the intellectual property license
5+
granted with Contributions from any person or entity, the organization owners must have
6+
a Contributor License Agreement ("CLA") on file that has
7+
been signed by each Contributor, indicating agreement to the license
8+
terms below. This license is for your protection as a Contributor as
9+
well as the protection of the Authors; it does not
10+
change your rights to use your own Contributions for any other purpose.
11+
Please read this document carefully before
12+
signing and keep a copy for your records.
13+
14+
*Note:* the conditions detailed below are copied verbatim from the [Individual Contributor’s License Agreement version 2 of the Apache Foundation](http://www.apache.org/licenses/icla.txt) with the addition of the last sentence in paragraph 2.
15+
16+
You accept and agree to the following terms and conditions for Your
17+
present and future Contributions submitted to the Organization. In
18+
return, the Organization shall not use Your Contributions in a way that
19+
is contrary to the public benefit or inconsistent with its nonprofit
20+
status and bylaws in effect at the time of the Contribution. Except
21+
for the license granted herein to the Organization and recipients of
22+
software distributed by the Organization, You reserve all right, title,
23+
and interest in and to Your Contributions.
24+
25+
1. Definitions.
26+
27+
"You" (or "Your") shall mean the copyright owner or legal entity
28+
authorized by the copyright owner that is making this Agreement
29+
with the Organization. For legal entities, the entity making a
30+
Contribution and all other entities that control, are controlled
31+
by, or are under common control with that entity are considered to
32+
be a single Contributor. For the purposes of this definition,
33+
"control" means (i) the power, direct or indirect, to cause the
34+
direction or management of such entity, whether by contract or
35+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
36+
outstanding shares, or (iii) beneficial ownership of such entity.
37+
38+
"Contribution" shall mean any original work of authorship,
39+
including any modifications or additions to an existing work, that
40+
is intentionally submitted by You to the Organization for inclusion
41+
in, or documentation of, any of the products owned or managed by
42+
the Organization (the "Work"). For the purposes of this definition,
43+
"submitted" means any form of electronic, verbal, or written
44+
communication sent to the Organization or its representatives,
45+
including but not limited to communication on electronic mailing
46+
lists, source code control systems, and issue tracking systems that
47+
are managed by, or on behalf of, the Organization for the purpose of
48+
discussing and improving the Work, but excluding communication that
49+
is conspicuously marked or otherwise designated in writing by You
50+
as "Not a Contribution."
51+
52+
2. Grant of Copyright License. Subject to the terms and conditions of
53+
this Agreement, You hereby grant to the Organization and to
54+
recipients of software distributed by the Organization a perpetual,
55+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
56+
copyright license to reproduce, prepare derivative works of,
57+
publicly display, publicly perform, sublicense, and distribute Your
58+
Contributions and such derivative works. This includes in particular
59+
the use of Your Contributions within the book Reactive Design Patterns
60+
and accompanying publications.
61+
62+
3. Grant of Patent License. Subject to the terms and conditions of
63+
this Agreement, You hereby grant to the Organization and to
64+
recipients of software distributed by the Organization a perpetual,
65+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66+
(except as stated in this section) patent license to make, have
67+
made, use, offer to sell, sell, import, and otherwise transfer the
68+
Work, where such license applies only to those patent claims
69+
licensable by You that are necessarily infringed by Your
70+
Contribution(s) alone or by combination of Your Contribution(s)
71+
with the Work to which such Contribution(s) was submitted. If any
72+
entity institutes patent litigation against You or any other entity
73+
(including a cross-claim or counterclaim in a lawsuit) alleging
74+
that your Contribution, or the Work to which you have contributed,
75+
constitutes direct or contributory patent infringement, then any
76+
patent licenses granted to that entity under this Agreement for
77+
that Contribution or Work shall terminate as of the date such
78+
litigation is filed.
79+
80+
4. You represent that you are legally entitled to grant the above
81+
license. If your employer(s) has rights to intellectual property
82+
that you create that includes your Contributions, you represent
83+
that you have received permission to make Contributions on behalf
84+
of that employer, that your employer has waived such rights for
85+
your Contributions to the Organization, or that your employer has
86+
executed a separate Corporate CLA with the Organization.
87+
88+
5. You represent that each of Your Contributions is Your original
89+
creation (see section 7 for submissions on behalf of others). You
90+
represent that Your Contribution submissions include complete
91+
details of any third-party license or other restriction (including,
92+
but not limited to, related patents and trademarks) of which you
93+
are personally aware and which are associated with any part of Your
94+
Contributions.
95+
96+
6. You are not expected to provide support for Your Contributions,
97+
except to the extent You desire to provide support. You may provide
98+
support for free, for a fee, or not at all. Unless required by
99+
applicable law or agreed to in writing, You provide Your
100+
Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
101+
OF ANY KIND, either express or implied, including, without
102+
limitation, any warranties or conditions of TITLE, NON-
103+
INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
104+
105+
7. Should You wish to submit work that is not Your original creation,
106+
You may submit it to the Organization separately from any
107+
Contribution, identifying the complete details of its source and of
108+
any license or other restriction (including, but not limited to,
109+
related patents, trademarks, and license agreements) of which you
110+
are personally aware, and conspicuously marking the work as
111+
"Submitted on behalf of a third-party: [named here]".
112+
113+
8. You agree to notify the Organization of any facts or circumstances of
114+
which you become aware that would make these representations
115+
inaccurate in any respect.

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
To get started, <a href="https://www.clahub.com/agreements/ReactiveDesignPatterns/CodeSamples">sign the Contributor License Agreement</a>.

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
This software is licensed under the Apache 2 license, quoted below.
2+
3+
Copyright 2009-2014 Typesafe Inc. [http://www.typesafe.com]
4+
5+
Licensed under the Apache License, Version 2.0 (the "License"); you may not
6+
use this file except in compliance with the License. You may obtain a copy of
7+
the License at
8+
9+
[http://www.apache.org/licenses/LICENSE-2.0]
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
License for the specific language governing permissions and limitations under
15+
the License.
16+
17+
---------------
18+
19+
Licenses for dependency projects can be found here:
20+
[http://akka.io/docs/akka/snapshot/project/licenses.html]

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Reactive Design Patterns Code Samples
2+
3+
This repository hosts the code samples that are used in [Reactive Design Patterns](http://manning.com/kuhn) for illustration. We aim at full test coverage to make sure that the code that we present actually works. While we tend to start out with writing Scala or Java code, we want this repository to also hold samples in other languages (like JavaScript, Ruby, Python, etc.). Contributions, corrections, wishes and all kind of help is appreciated, please don’t hesitate to use the issue tracker.
4+
5+
## Legal
6+
7+
The code in this repository is offered royalty-free under the Apache License version 2, see the LICENSE file in the root directory.
8+

build.sbt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
organization in ThisBuild := "com.reactivedesignpatterns"
2+
3+
scalaVersion in ThisBuild := "2.11.2"
4+
5+
lazy val common = project in file("common")
6+
7+
lazy val chapter04 = project dependsOn (common)
8+
9+
lazy val chapter07 = project dependsOn (common)
10+

chapter04/build.sbt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
libraryDependencies ++= Seq(
2+
"com.typesafe.akka" %% "akka-testkit" % "2.3.6" % "test",
3+
"junit" % "junit" % "4.11" % "test",
4+
"org.scalatest" %% "scalatest" % "2.2.2" % "test"
5+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.reactivedesignpatterns.chapter4
2+
3+
import akka.actor.Actor
4+
import akka.actor.ActorRef
5+
6+
object EchoService {
7+
case class Request(tag: String, client: ActorRef)
8+
case class Response(tag: String)
9+
}
10+
11+
class EchoService extends Actor {
12+
import EchoService._
13+
14+
def receive = {
15+
case Request(tag, ref) => ref ! Response(tag)
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.reactivedesignpatterns.chapter4
2+
3+
import scala.concurrent.ExecutionContext
4+
import scala.concurrent.Future
5+
6+
class TranslationService {
7+
import ExecutionContext.Implicits.global
8+
9+
def translate(input: String): Future[String] = Future { Thread.sleep(100); "How are you?" }
10+
11+
def translate(input: String, ec: ExecutionContext): Future[String] =
12+
Future { Thread.sleep(100); "How are you?" }(ec)
13+
}

0 commit comments

Comments
 (0)