Slides from Ian Forsey and Ariel Kogan's session at Skill Matter's Scala Exchange 2013.
-------------------------------------------------
In this session we will share our experience at Net-a-porter, creating our first reactive Scala/Akka/Spray service in a company with a long-standing Java codebase and production infrastructure.
We've heard how Twitter and LinkedIn adopted Scala on greenfield initiatives and we're excited to use a more expressive language running on a robust, familiar VM. But is the ecosystem ready to support the demands of a long-established enterprise infrastructure, mission-critical (non-Scala!) middleware and the traditional dev-test-release workflow?
We'll start by exposing what drove our decision to dive into Scala. Next: We'll talk about some of the challenges we faced designing, building, load testing and debugging our service. We will discuss some of the patterns we used moving to a more reactive platform, the availability/maturity of the tooling and some of the framework code we had to write. Finally we'll outline the benefits gained through embarking on this project and any prices we have paid for doing so.
Orchestration tool roundup - OpenStack Israel summit - kubernetes vs. docker...Uri Cohen
It’s no news that containers represent a portable unit of deployment, and OpenStack has proven an ideal environment for running container workloads. However, where it usually becomes more complex is that many times an application is often built out of multiple containers. What’s more, setting up a cluster of container images can be fairly cumbersome because you need to make one container aware of another and expose intimate details that are required for them to communicate which is not trivial especially if they’re not on the same host.
These scenarios have instigated the demand for some kind of orchestrator. The list of container orchestrators is growing fairly fast. This session will compare the different orchestation projects out there - from Heat to Kubernetes to TOSCA - and help you choose the right tool for the job.
A presentation on what's the magic in LinkedIn? LinkedIn's DNA & recipe, tips, tricks and examples.
Presented at Sosa Tel Aviv, on 1/3/16 at the Israeli Marketing Innovation Forum conference - a LinkedIn event, with Tal Shmueli, Linkedin Marketing Solutions Account Manager, Tsur Shraibman, Linkedin Marketing Solutions Account Executive and Efrat Fenigson, Senior Director of Marketing Communications at Viaccess-Orca (Orange group)
Introduction to Scrum development process. Main concepts. The process. Examples. Issues
Slides for course Software engineering seminar @ Afeka College Of Engineering
"The joy of Scala" - Maxim Novak / Wix
Around eight years ago I started my journey as a developer. Since then, I've played around with many languages and thought that C# offers the best developer productivity. After joining Wix two years ago, I was exposed to the amazing world of Scala and Functional Programming and never looked back.
In Scala the code is much more concise, less ceremonious, immutable by default, combines functional with object oriented, seamlessly interoperates with Java, and many software engineering patterns are already baked into the language. Most importantly - Scala is FUN! By the end of the session you too will, hopefully, convert to Scala and never look back.
Recording of the lecture (Hebrew) - https://youtu.be/TcnYTwff2xU
How does Google work? How can a friend user her own computer to enter a Website you developed on your own machine? Where are your Facebook posts saved once you exit the browser?
In this talk we will learn the general ideas behind the Internet, what the main components of a Web application are and what happens from the moment you open the browser, enter an address and until you can see the Website with all the relevant data.
This talk was given at the she codes; Google Campus branch.
The lecture recording is available here: https://youtu.be/qys1rsBRhUs
Lessons we learned while getting Wonderball Heroes on WebGL using Unity 5.
The slides share our challenges, optimizations made and general tips for working with Unity and WebGL.
How fast ist it really? Benchmarking in practiceTobias Pfeiffer
“What’s the fastest way of doing this?” - you might ask yourself during development. Sure, you can guess what’s fastest or how long something will take, but do you know? How long does it take to sort a list of 1 Million elements? Are tail-recursive functions always the fastest?
Benchmarking is here to answer these questions. However, there are many pitfalls around setting up a good benchmark and interpreting the results. This talk will guide you through, introduce best practices and show you some surprising benchmarking results along the way.
Continuous Deployment into the Unknown with Artifactory, Bintray, Docker and ...Gilad Garon
VMware’s Common SaaS Platform (CSP) is a brand new offering designed to enhance the productivity of developers and cloud providers by equipping them with a set of common and configurable capabilities (such as Identity, Telemetry, Account Management, Billing etc.), thus enabling them to focus on their core businesses.
But enough with the product pitch.
CSP is distributed to numerous cloud providers around the globe, used by developers and IT alike to empower their services and better answer the business need of their customers.
Please join us and witness how we take continuous delivery to the next step where sometimes the target environment is not on our control and still seamlessly manage and deliver our unique collection of capabilities, packaged as platform for ease of use, using the best and shiniest tools the frogs can provide.
Optimizing DevOps strategy in a large enterpriseEyal Edri
Large enterprises today are pacing a flood of multiple devops tools to choose from for their infrastructure. The problem intensifies when you have dozens of devops teams across the world, each with his own background of devops tools and knowledge and each with his own agenda of pushing to use his tools. How would you leverage this distributed, disconnected knowledge into a single working devops knowledge source, and common infrastructure to leverage the whole enterprise? Come and hear about Red Hat Global CI initiative to hear on one possible approach for taking on the battle.
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)Christian Catalan
Presented at the STLJS Meetup (St Louis, MO)
We dive into a Vue application used in semiconductor labs for transistor measurements. We discuss how get started with E2E testing with Cypress.io. And give a crash course into Vue applications.
Video: https://www.youtube.com/watch?v=dpB0YgnFyZQ
Slides from Ian Forsey and Ariel Kogan's session at Skill Matter's Scala Exchange 2013.
-------------------------------------------------
In this session we will share our experience at Net-a-porter, creating our first reactive Scala/Akka/Spray service in a company with a long-standing Java codebase and production infrastructure.
We've heard how Twitter and LinkedIn adopted Scala on greenfield initiatives and we're excited to use a more expressive language running on a robust, familiar VM. But is the ecosystem ready to support the demands of a long-established enterprise infrastructure, mission-critical (non-Scala!) middleware and the traditional dev-test-release workflow?
We'll start by exposing what drove our decision to dive into Scala. Next: We'll talk about some of the challenges we faced designing, building, load testing and debugging our service. We will discuss some of the patterns we used moving to a more reactive platform, the availability/maturity of the tooling and some of the framework code we had to write. Finally we'll outline the benefits gained through embarking on this project and any prices we have paid for doing so.
Orchestration tool roundup - OpenStack Israel summit - kubernetes vs. docker...Uri Cohen
It’s no news that containers represent a portable unit of deployment, and OpenStack has proven an ideal environment for running container workloads. However, where it usually becomes more complex is that many times an application is often built out of multiple containers. What’s more, setting up a cluster of container images can be fairly cumbersome because you need to make one container aware of another and expose intimate details that are required for them to communicate which is not trivial especially if they’re not on the same host.
These scenarios have instigated the demand for some kind of orchestrator. The list of container orchestrators is growing fairly fast. This session will compare the different orchestation projects out there - from Heat to Kubernetes to TOSCA - and help you choose the right tool for the job.
A presentation on what's the magic in LinkedIn? LinkedIn's DNA & recipe, tips, tricks and examples.
Presented at Sosa Tel Aviv, on 1/3/16 at the Israeli Marketing Innovation Forum conference - a LinkedIn event, with Tal Shmueli, Linkedin Marketing Solutions Account Manager, Tsur Shraibman, Linkedin Marketing Solutions Account Executive and Efrat Fenigson, Senior Director of Marketing Communications at Viaccess-Orca (Orange group)
Introduction to Scrum development process. Main concepts. The process. Examples. Issues
Slides for course Software engineering seminar @ Afeka College Of Engineering
"The joy of Scala" - Maxim Novak / Wix
Around eight years ago I started my journey as a developer. Since then, I've played around with many languages and thought that C# offers the best developer productivity. After joining Wix two years ago, I was exposed to the amazing world of Scala and Functional Programming and never looked back.
In Scala the code is much more concise, less ceremonious, immutable by default, combines functional with object oriented, seamlessly interoperates with Java, and many software engineering patterns are already baked into the language. Most importantly - Scala is FUN! By the end of the session you too will, hopefully, convert to Scala and never look back.
Recording of the lecture (Hebrew) - https://youtu.be/TcnYTwff2xU
How does Google work? How can a friend user her own computer to enter a Website you developed on your own machine? Where are your Facebook posts saved once you exit the browser?
In this talk we will learn the general ideas behind the Internet, what the main components of a Web application are and what happens from the moment you open the browser, enter an address and until you can see the Website with all the relevant data.
This talk was given at the she codes; Google Campus branch.
The lecture recording is available here: https://youtu.be/qys1rsBRhUs
Lessons we learned while getting Wonderball Heroes on WebGL using Unity 5.
The slides share our challenges, optimizations made and general tips for working with Unity and WebGL.
How fast ist it really? Benchmarking in practiceTobias Pfeiffer
“What’s the fastest way of doing this?” - you might ask yourself during development. Sure, you can guess what’s fastest or how long something will take, but do you know? How long does it take to sort a list of 1 Million elements? Are tail-recursive functions always the fastest?
Benchmarking is here to answer these questions. However, there are many pitfalls around setting up a good benchmark and interpreting the results. This talk will guide you through, introduce best practices and show you some surprising benchmarking results along the way.
Continuous Deployment into the Unknown with Artifactory, Bintray, Docker and ...Gilad Garon
VMware’s Common SaaS Platform (CSP) is a brand new offering designed to enhance the productivity of developers and cloud providers by equipping them with a set of common and configurable capabilities (such as Identity, Telemetry, Account Management, Billing etc.), thus enabling them to focus on their core businesses.
But enough with the product pitch.
CSP is distributed to numerous cloud providers around the globe, used by developers and IT alike to empower their services and better answer the business need of their customers.
Please join us and witness how we take continuous delivery to the next step where sometimes the target environment is not on our control and still seamlessly manage and deliver our unique collection of capabilities, packaged as platform for ease of use, using the best and shiniest tools the frogs can provide.
Optimizing DevOps strategy in a large enterpriseEyal Edri
Large enterprises today are pacing a flood of multiple devops tools to choose from for their infrastructure. The problem intensifies when you have dozens of devops teams across the world, each with his own background of devops tools and knowledge and each with his own agenda of pushing to use his tools. How would you leverage this distributed, disconnected knowledge into a single working devops knowledge source, and common infrastructure to leverage the whole enterprise? Come and hear about Red Hat Global CI initiative to hear on one possible approach for taking on the battle.
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)Christian Catalan
Presented at the STLJS Meetup (St Louis, MO)
We dive into a Vue application used in semiconductor labs for transistor measurements. We discuss how get started with E2E testing with Cypress.io. And give a crash course into Vue applications.
Video: https://www.youtube.com/watch?v=dpB0YgnFyZQ
The Loom project has been under work for many years, and just delivered Virtual Threads as a preview feature in the JDK 19. We now have a very precise idea of what they are and what you can do with them. Our good old Threads, created more than 25 years ago, will see a new kind of lightweight threads. This presentation shows you that creating a thread is easier and much cheaper, allowing the creation of millions of them in a single JVM. These virtual threads can be block at almost no cost. These new virtual threads bring with them new notions that will be covered in this talk. Loom threads are coming, and they will change the landscape of concurrent programming in Java.
Have you ever wondered what the best way would be to test emails? Or how you would go about testing a messaging queue?
Making sure your components are correctly interacting with each other is both a tester and developer’s concern. Join us to get a better understanding of what you should test and how, both manually and automated.
This session is the first ever in which we will have two units working together to give you a nuanced insight on all aspects of integration testing. We’ll start off exploring the world of integration testing, defining the terminology, and creating a general understanding of what phases and kinds of testing exist. Later on we’ll delve into integration test automation, ranging from database integration testing to selenium UI testing and even as far as LDAP integration testing.
We have a wide variety of demos prepared where we will show you how easy it is to test various components of your infrastructure. Some examples:
- Database testing (JPA)
- Arquillian, exploring container testing, EJB testing and more
- Email testing
- SOAP testing using SoapUI
- LDAP testing
- JMS testing
Frameworks are bulky, quirky, and non-compositional, which has led to a rejection of Spring and similar frameworks in the Scala ecosystem. Yet, despite their drawbacks, frameworks have been used to boost team productivity in many large companies. In this presentation, Pavel and Kai will introduce Izumi 1.0, a Scala microframework based on compositional functional programming. Designed to help you and your team achieve new levels of productivity, Izumi now includes full compile-time checks for your configurable applications and completely reworked Tagless Final hierarchy for Bifunctors and Trifunctors.
Maven and Ant have dominated the build landscape in the Java world for more than a decade. Why on earth do we need or want another one? That’s a question many people ask themselves when hearing about Gradle. In this talk, I provide some context to what makes a good build and hence what you should expect from your build tools.
You will then learn how Gradle provides the features you need to solve any build problem, while still being easy to use for standard stuff. Afterwards, you’ll start to understand why Google picked Gradle for the new Android build system.
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...Fwdays
At some point, we reached the limit of the existing build process in the Grammarly Editor monorepo. Build tools required too much time to support, and each new package increased build time and made dependency management harder. To move further, we had to rethink the architecture of the build process. Our solution: We switched to Bazel. In this talk, I will share our findings and how we made the architecture of the build process scalable and predictable.
A presentation for the Vancouver Island Java User's Group showcasing how Groovy and the Griffon application framework can ease the pain of coding Swing applications.
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?Dmitri Shiryaev
. Problem we are facing
. Big Data Stacks
. Why validation
. What is "Success" and the effort to achieve it
. Solutions
. Ops testing
. Platform certification
. Application testing
. Stack on stack
. Test artifacts are First Class Citizen
. Assembling validation stack (vstack)
. Tailoring vstack for target clusters
. D3: Deployment/Dependencies/Determinism
The range of tools available for the Java platform is one of its many strengths, and a surprising number of these tools rely on bytecode instrumentation (BCI) and bytecode generation to do their work. A few of the many examples of where BCI is used are profiling tools, static analysis tools (FindBugs), dynamic languages (Nashorn, JRuby), and code coverage (EMMA). But BCI is a black art to most. This session aims to take away the mystery and show you what BCI is, how it is used, and how you can get started on writing your own BCI-based tooling.
We describe the deployment and use of Globus Compute for remote computation. This content is aimed at researchers who wish to compute on remote resources using a unified programming interface, as well as system administrators who will deploy and operate Globus Compute services on their research computing infrastructure.
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppGoogle
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-fusion-buddy-review
AI Fusion Buddy Review: Key Features
✅Create Stunning AI App Suite Fully Powered By Google's Latest AI technology, Gemini
✅Use Gemini to Build high-converting Converting Sales Video Scripts, ad copies, Trending Articles, blogs, etc.100% unique!
✅Create Ultra-HD graphics with a single keyword or phrase that commands 10x eyeballs!
✅Fully automated AI articles bulk generation!
✅Auto-post or schedule stunning AI content across all your accounts at once—WordPress, Facebook, LinkedIn, Blogger, and more.
✅With one keyword or URL, generate complete websites, landing pages, and more…
✅Automatically create & sell AI content, graphics, websites, landing pages, & all that gets you paid non-stop 24*7.
✅Pre-built High-Converting 100+ website Templates and 2000+ graphic templates logos, banners, and thumbnail images in Trending Niches.
✅Say goodbye to wasting time logging into multiple Chat GPT & AI Apps once & for all!
✅Save over $5000 per year and kick out dependency on third parties completely!
✅Brand New App: Not available anywhere else!
✅ Beginner-friendly!
✅ZERO upfront cost or any extra expenses
✅Risk-Free: 30-Day Money-Back Guarantee!
✅Commercial License included!
See My Other Reviews Article:
(1) AI Genie Review: https://sumonreview.com/ai-genie-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
#AIFusionBuddyReview,
#AIFusionBuddyFeatures,
#AIFusionBuddyPricing,
#AIFusionBuddyProsandCons,
#AIFusionBuddyTutorial,
#AIFusionBuddyUserExperience
#AIFusionBuddyforBeginners,
#AIFusionBuddyBenefits,
#AIFusionBuddyComparison,
#AIFusionBuddyInstallation,
#AIFusionBuddyRefundPolicy,
#AIFusionBuddyDemo,
#AIFusionBuddyMaintenanceFees,
#AIFusionBuddyNewbieFriendly,
#WhatIsAIFusionBuddy?,
#HowDoesAIFusionBuddyWorks
Navigating the Metaverse: A Journey into Virtual Evolution"Donna Lenk
Join us for an exploration of the Metaverse's evolution, where innovation meets imagination. Discover new dimensions of virtual events, engage with thought-provoking discussions, and witness the transformative power of digital realms."
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
May Marketo Masterclass, London MUG May 22 2024.pdfAdele Miller
Can't make Adobe Summit in Vegas? No sweat because the EMEA Marketo Engage Champions are coming to London to share their Summit sessions, insights and more!
This is a MUG with a twist you don't want to miss.
Check out the webinar slides to learn more about how XfilesPro transforms Salesforce document management by leveraging its world-class applications. For more details, please connect with sales@xfilespro.com
If you want to watch the on-demand webinar, please click here: https://www.xfilespro.com/webinars/salesforce-document-management-2-0-smarter-faster-better/
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
Science gateways allow science and engineering communities to access shared data, software, computing services, and instruments. Science gateways have gained a lot of traction in the last twenty years, as evidenced by projects such as the Science Gateways Community Institute (SGCI) and the Center of Excellence on Science Gateways (SGX3) in the US, The Australian Research Data Commons (ARDC) and its platforms in Australia, and the projects around Virtual Research Environments in Europe. A few mature frameworks have evolved with their different strengths and foci and have been taken up by a larger community such as the Globus Data Portal, Hubzero, Tapis, and Galaxy. However, even when gateways are built on successful frameworks, they continue to face the challenges of ongoing maintenance costs and how to meet the ever-expanding needs of the community they serve with enhanced features. It is not uncommon that gateways with compelling use cases are nonetheless unable to get past the prototype phase and become a full production service, or if they do, they don't survive more than a couple of years. While there is no guaranteed pathway to success, it seems likely that for any gateway there is a need for a strong community and/or solid funding streams to create and sustain its success. With over twenty years of examples to draw from, this presentation goes into detail for ten factors common to successful and enduring gateways that effectively serve as best practices for any new or developing gateway.
OpenMetadata Community Meeting - 5th June 2024OpenMetadata
The OpenMetadata Community Meeting was held on June 5th, 2024. In this meeting, we discussed about the data quality capabilities that are integrated with the Incident Manager, providing a complete solution to handle your data observability needs. Watch the end-to-end demo of the data quality features.
* How to run your own data quality framework
* What is the performance impact of running data quality frameworks
* How to run the test cases in your own ETL pipelines
* How the Incident Manager is integrated
* Get notified with alerts when test cases fail
Watch the meeting recording here - https://www.youtube.com/watch?v=UbNOje0kf6E
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
Graspan: A Big Data System for Big Code AnalysisAftab Hussain
We built a disk-based parallel graph system, Graspan, that uses a novel edge-pair centric computation model to compute dynamic transitive closures on very large program graphs.
We implement context-sensitive pointer/alias and dataflow analyses on Graspan. An evaluation of these analyses on large codebases such as Linux shows that their Graspan implementations scale to millions of lines of code and are much simpler than their original implementations.
These analyses were used to augment the existing checkers; these augmented checkers found 132 new NULL pointer bugs and 1308 unnecessary NULL tests in Linux 4.4.0-rc5, PostgreSQL 8.3.9, and Apache httpd 2.2.18.
- Accepted in ASPLOS ‘17, Xi’an, China.
- Featured in the tutorial, Systemized Program Analyses: A Big Data Perspective on Static Analysis Scalability, ASPLOS ‘17.
- Invited for presentation at SoCal PLS ‘16.
- Invited for poster presentation at PLDI SRC ‘16.
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Globus
The U.S. Geological Survey (USGS) has made substantial investments in meeting evolving scientific, technical, and policy driven demands on storing, managing, and delivering data. As these demands continue to grow in complexity and scale, the USGS must continue to explore innovative solutions to improve its management, curation, sharing, delivering, and preservation approaches for large-scale research data. Supporting these needs, the USGS has partnered with the University of Chicago-Globus to research and develop advanced repository components and workflows leveraging its current investment in Globus. The primary outcome of this partnership includes the development of a prototype enterprise repository, driven by USGS Data Release requirements, through exploration and implementation of the entire suite of the Globus platform offerings, including Globus Flow, Globus Auth, Globus Transfer, and Globus Search. This presentation will provide insights into this research partnership, introduce the unique requirements and challenges being addressed and provide relevant project progress.
Quarkus Hidden and Forbidden ExtensionsMax Andersen
Quarkus has a vast extension ecosystem and is known for its subsonic and subatomic feature set. Some of these features are not as well known, and some extensions are less talked about, but that does not make them less interesting - quite the opposite.
Come join this talk to see some tips and tricks for using Quarkus and some of the lesser known features, extensions and development techniques.
Unleash Unlimited Potential with One-Time Purchase
BoxLang is more than just a language; it's a community. By choosing a Visionary License, you're not just investing in your success, you're actively contributing to the ongoing development and support of BoxLang.
GraphSummit Paris - The art of the possible with Graph TechnologyNeo4j
Sudhir Hasbe, Chief Product Officer, Neo4j
Join us as we explore breakthrough innovations enabled by interconnected data and AI. Discover firsthand how organizations use relationships in data to uncover contextual insights and solve our most pressing challenges – from optimizing supply chains, detecting fraud, and improving customer experiences to accelerating drug discoveries.
2. Agenda
• Background
– Testability
– Dependency injection pattern (DI)
– Factory pattern
• Guice basics
• Unit testing with Guice and Mockito
• Best practices
• Useful links
3/4/2014 2Guice - Evgeny Barabanov
3. Testability
class A {
int complexCalculation(){
//Some calculation
}
}
class B {
A a;
B(){
a = new A();
}
int doubleCalculation{
return a.complexCalulation() * 2;
}
}
Why it is difficult to unit test class B?
3/4/2014 3Guice - Evgeny Barabanov
4. Testability
class A {
int complexCalculation(){
//Some calculation
}
}
class B {
A a;
B(){
a = new A();
}
int doubleCalculation{
return a.complexCalulation() * 2;
}
}
Why it is difficult to unit test class B?
What if
a.complexCalculation
computes wrong
result?
3/4/2014 4Guice - Evgeny Barabanov
5. Testability
Why it is difficult to unit test class B?
- B implementation depends directly on actual A implementation,
therefore we cannot test B as standalone class.
class A {
int complexCalculation(){
//Some calculation
}
}
class B {
A a;
B(){
a = new A();
}
int doubleCalculation{
return a.complexCalulation() * 2;
}
}
What if
a.complexCalculation
computes wrong
result?
3/4/2014 5Guice - Evgeny Barabanov
6. The solution – Dependency injection
interface IA {
int complexCalculation();
}
class A implements IA {
int complexCalculation(){
//Some calculation
}
}
class B {
IA a;
B(IA _a){
a = _a;
}
int doubleCalculation{
return a.complexCalculation() * 2;
}
}
Hollywood principle: “Don’t call us, we’ll call you”
3/4/2014 6Guice - Evgeny Barabanov
7. The solution – Dependency injection
interface IA {
int complexCalculation();
}
class A implements IA {
int complexCalculation(){
//Some calculation
}
}
class B {
IA a;
B(IA _a){
a = _a;
}
int doubleCalculation{
return a.complexCalculation() * 2;
}
}
Hollywood principle: “Don’t call us, we’ll call you”
Now A implementation is absolutely decoupled from B implementation…
3/4/2014 7Guice - Evgeny Barabanov
8. …It makes the unit testing of B much easier:
class AStub implements IA {
int complexCalculation(){
return 1;
}
}
class BTest(){
void testCalc(){
B b = new B(new AStub());
assert(b.doubleCalculation() == 2)
}
}
Now a.complexCalculation() may return wrong result and we don’t care,
because we’re only testing the pure functionality of B.
3/4/2014 8Guice - Evgeny Barabanov
9. But…
I’d like to order
a new computer
Sure! We’ll
ship it in few
hours!
3/4/2014 9Guice - Evgeny Barabanov
10. …There is a problem
WTF!!??
3/4/2014 10Guice - Evgeny Barabanov
11. class HardDrive implements IHardDrive {
HardDrive(IDiscCase c, IDiscPlatter p, ISpindle s, IActuator a ...){
//
}
///
}
class GraphicCard implements IGraphicCard {
GraphicCard(IGraphicMemory m, IHeatSink hs, IFun f ...){
//
}
//
}
class Computer implements IComputer {
Computer(IHardDrive hd, IGraphicCard gc, ....){
//
}
//
}
3/4/2014 11Guice - Evgeny Barabanov
12. class Homer {
IComputer homersPC;
Homer(){
IDiscCase c = new DiscCase();
IDiscPlatter p = new DiscPlatter();
ISpindle s = new Spindle();
IActuator a = new Actuator();
...
IHardDrive hd = new HardDrive(c,p,s,a,...);
IGraphicMemory m = new GraphicMemory();
IHeatSink hs = new HeatSink();
IFun f = new Fun();
...
IGraphicCard gc = new GraphicCard(m, hs, f, ...);
...
...
//And finally!!!
homersPC = new Computer(hd, gc, ... );
}
}
The amount of “new” grows exponentially!!!
3/4/2014 12Guice - Evgeny Barabanov
13. The solution - Factory
I’d like to order
a new computer
Sure! We’ll ship it
in few hours! And
we will assemble it
for you!
3/4/2014 13Guice - Evgeny Barabanov
15. class HardDriveFactory {
static IHardDrive GetHardDrive{
IDiscCase c = new DiscCase();
IDiscPlatter p = new DiscPlatter();
ISpindle s = new Spindle();
IActuator a = new Actuator();
...
return new HardDrive(c,p,s,a,...);
}
}
class GraphicCardFactory {
static IGraphicCard GetGraphicCard{
IGraphicMemory m = new GraphicMemory();
IHeatSink hs = new HeatSink();
IFun f = new Fun();
...
return new GraphicCard(m, hs, f, ...);
}
}
class ComputerFactory {
static IComputer GetComputer{
IHardDrive hd = HardDriveFactory.GetHardDrive();
IGraphicCard gc = GraphicCardFactory.GetGraphicCard();
...
return new Computer(hd, gc, ... );
}
}
class Homer {
IComputer homersPC;
Homer(){
homersPC = ComputerFactory.GetComputer();
}
}
3/4/2014 15Guice - Evgeny Barabanov
16. Factory
• Advantages:
– Single responsibility. There is a separate entity which is responsible for instantiation and
configuration of a concrete object.
– Decoupling. A factory class decouples the client and implementing class.
– Avoid code duplication. If, for example, we are changing the signature of A constructor, we don’t
have to go over all the classes which are using A, but just change it in A factory.
– Homer doesn’t have to assemble the computer by himself.
• Disadvantages:
– We still have tight coupling between Factory class and products.
– We still have testability issues with naive factory implementation (can be solved by using more
advanced factory techniques, like factory with reflection)
– We shall maintain additional classes
3/4/2014 16Guice - Evgeny Barabanov
17. The most powerful solution - Guice
Guice is a dependency injection framework, which
alleviates the need for factories and use of new in your
java code.
Your code will be easier to change, unit test and reuse in
other contexts.
Guice aims to make development and debugging easier
and faster, not harder and slower.
3/4/2014 17Guice - Evgeny Barabanov
18. With dependency injection, objects accept dependencies in their
constructors. To construct an object, you first build its
dependencies. But to build each dependency you
need its dependencies, and so on. So when you build an object, you
really need to build an object graph.
Building object graphs by hand (as you have seen) is labour
intensive, error prone, and makes testing difficult. Instead, Guice
can build the object graph for you. But first, Guice needs to be
configured to build the graph exactly as you want it.
Injector is Guice's object-graph builder. First we create the injector,
and then we can use that to build.
The most powerful solution - Guice
3/4/2014 18Guice - Evgeny Barabanov
20. Explicit bindings
A module is a collection of bindings which is
passed to Injector on its creation.
In module we specify all the bindings we want
to be used in current context.
3/4/2014 20Guice - Evgeny Barabanov
21. Explicit bindings
Consider previous example with a computer (for simplicity let’s assume
that HardDrive and GraphicCard receive nothing in their constructors):
class HardDrive implements IHardDrive {
HardDrive(){
//
}
///
}
class GraphicCard implements IGraphicCard {
GraphicCard(){
//
}
//
}
class Computer implements IComputer {
Computer(IHardDrive hd, IGraphicCard gc, ....){
//
}
//
}
3/4/2014 21Guice - Evgeny Barabanov
22. Explicit bindings
Now lets define a module which will bind the
interfaces to their implementations:
public class ComputerModule extends AbstractModule {
@Override
protected void configure() {
/*
* This tells Guice that whenever it sees a dependency on a IHardDrive,
* it should satisfy the dependency using a HardDrive.
*/
bind(IHardDrive.class).to(HardDrive.class);
/*
* Similarly, this binding tells Guice that when IGraphicCard is used in
* a dependency, that should be satisfied with a GraphicCard.
*/
bind(IGraphicCard.class).to(GraphicCard.class);
/*
* Finally, this binding tells Guice that when IComputer is used in
* a dependency, that should be satisfied with a Computer.
*/
bind(IComputer.class).to(Computer.class);
}
3/4/2014 22Guice - Evgeny Barabanov
23. Explicit bindings
Once we defined a module and passed it to the injector,
Guice will be able to create all the dependencies for us.
class Homer {
static Injector injector = Guice.createInjector(new ComputerModule());
IComputer homersPC;
Homer(){
homerPC = injector.getInstance(IComputer.class);
}
}
3/4/2014 23Guice - Evgeny Barabanov
24. Implicit bindings
When the injector needs an instance of a type, it needs
a binding.
The bindings in a modules are called explicit bindings,
and the injector uses them whenever they're available.
If a type is needed but there isn't an explicit binding,
the injector will attempt to create a Just-In-Time
binding. These are also known as JIT bindings or
implicit bindings.
3/4/2014 24Guice - Evgeny Barabanov
25. Impicit bindings
Implicit binding is done by specifying @ImplementedBy
annotation on the interface. Thus, instead of creating a
module we can tell Guice what are default implicit
bindings for our interfaces:
@ImplementedBy(GraphicCard.class)
public interface IGraphicCard {
//
//...
//
}
@ImplementedBy(HardDrive.class)
public interface IHardDrive {
//
//...
//
}
@ImplementedBy(Computer.class)
public interface IComputer {
//
//...
//
}
3/4/2014 25Guice - Evgeny Barabanov
26. Bindings
There are much more bindings, we have only
seen the basic ones.
You can find out more about bindings here.
3/4/2014 26Guice - Evgeny Barabanov
27. Injections
It’s not enough to tell Guice what are the
bindings. We also need to tell him what are
injected objects for each class.
There are several ways to do that, let’s look at
couple of them.
3/4/2014 27Guice - Evgeny Barabanov
28. Constructor injection
Constructor injection combines instantiation with injection. To use it, we
should annotate the constructor with the @Inject annotation. This
constructor should accept class dependencies as parameters. Most
constructors will then assign the parameters to fields (better final fields).
public class Computer implements IComputer{
final IHardDrive m_hd;
IGraphicCard m_gc;
@Inject
public Computer(IHardDrive hd, IGraphicCard gc){
m_hd = hd;
m_gc = gc;
}
}
If your class has no @Inject-annotated constructor, Guice will use a
public, no-arguments constructor if it exists.
Constructor injection works nicely with unit testing. If your class accepts
all of its dependencies in a single constructor, you won't accidentally
forget to set a dependency
3/4/2014 28Guice - Evgeny Barabanov
29. Field injection
Guice injects fields with the @Inject annotation. This is the most concise
injection, but the least testable.
public class Homer {
@Inject
private IComputer m_comp;
}
public class Main {
public static void main(String [] args)
{
Injector injector = Guice.createInjector();
Homer homer = injector.getInstance(Homer.class);
}
}
At the end of “main” method Homer will have an instance of Computer
with all its subcomponents.
3/4/2014 29Guice - Evgeny Barabanov
31. Unit testing with Guice and Mockito
We want to unit test Computer, so we don’t want to be dependent on
GraphicCard and HardDrive implementations. The only thing we want
to test is a Computers functionality.
Guice provides us great ability to change binding.
All we need is just define two stubs (for GraphicCard and HardDrive),
define a new module which will bind interfaces to these stubs and
pass this module to the injector in test module.
But are we really want to maintain stub classes? Absolutely – NO.
Mockito provides us great ability to simulate classes behavior with its
Mocks, but as Mock is not a user defined class, we cannot bind
interface to the Mock.
So how can we combine and use both of these great frameworks?
3/4/2014 31Guice - Evgeny Barabanov
32. Unit testing with Guice and Mockito
The solution is @Provides methods:
@Provides method allows us to create an object when the object requires
additional code to be created, set up or configured . The method must be
defined within a module, and it must have an @Provides annotation. The
method's return type is the bound type. Whenever the injector needs an
instance of that type, it will invoke the method.
Guice does not allow exceptions to be thrown from Providers. Exceptions
thrown by @Provides methods will be wrapped in a ProvisionException. It is
bad practice to allow any kind of exception to be thrown -- runtime or
checked -- from an @Provides method.
3/4/2014 32Guice - Evgeny Barabanov
33. Unit testing with Guice and Mockito
Consider previous example with computer:
public class HardDrive implements IHardDrive {
@Override
public int CalculateSpeed() {
int result = 0;
//Complicated and long computation
return result;
}
}
public class GraphicCard implements IGraphicCard {
@Override
public int GetPerformanceRate() {
int result = 0;
//Complicated and long computation
return result;
}
}
public class Computer implements IComputer{
IHardDrive m_hd;
IGraphicCard m_gc;
@Inject
public Computer(IHardDrive hd, IGraphicCard gc){
m_hd = hd;
m_gc = gc;
}
@Override
public int GetComputerPerformanceRate() {
return m_hd.CalculateSpeed()+m_gc.GetPerformanceRate();
}
}
3/4/2014 33Guice - Evgeny Barabanov
34. Unit testing with Guice and Mockito
We’d like to test GetComputerPerformanceRate method.
So lets do that!
First, we create a module which defines @Provides methods
for GraphicCard and HardDrive stubs:
public class ComputerTestsModule extends AbstractModule {
@Override
protected void configure() {
}
@Provides
IHardDrive provideHardDrive(){
IHardDrive hd = mock(IHardDrive.class);
when(hd.CalculateSpeed()).thenReturn(5);
return hd;
}
@Provides
IGraphicCard provideGraphicCard(){
IGraphicCard gc = mock(IGraphicCard.class);
when(gc.GetPerformanceRate()).thenReturn(10);
return gc;
}
}
3/4/2014 34Guice - Evgeny Barabanov
35. Unit testing with Guice and Mockito
After we tell Guice to use our module instead of default binding
for HardDrive and GraphicCard creation, we can unit test the desired class:
public class ComputerTests extends TestCase {
static Injector injector = Guice.createInjector(new ComputerTestsModule());
IComputer cpForTest = injector.getInstance(IComputer.class);
@Test
public void testComputerPerformance(){
assertEquals(15, cpForTest.GetComputerPerformanceRate());
}
}
3/4/2014 35Guice - Evgeny Barabanov
36. Best practices
• Minimize mutability
• Inject only direct dependencies
• Avoid cyclic dependencies
• Avoid static state
• Use @Nullable
• Create fast and side-effects free modules
• Be careful about I/O in providers
• Avoid conditional logic in modules
• Keep constructors as hidden as possible
3/4/2014 36Guice - Evgeny Barabanov
37. Useful links
• FAQ
• Using Guice with Google AppEngine
3/4/2014 37Guice - Evgeny Barabanov